Bidirectional communication method and device, computer equipment and storage medium
By establishing a two-way communication bridge between Unity applications and the Web platform, the problems of inefficient communication and cross-end communication barriers in the existing technology are solved, seamless integration and real-time interaction are achieved, and user experience and development efficiency are improved.
Patent Information
- Application Number
- CN202411996978.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-02
AI Technical Summary
The existing communication solutions have problems of inefficient communication, cross-end communication barriers and cross-domain access restrictions between Unity applications and the Web platform, limiting the deep integration and interactive experience between the two.
The application operation platform is conditionally compiled through the engine-side project, and the first communication bridge is determined, and the front-end project is called and communicated based on the bridge; at the same time, the front-end project performs platform detection and processing on the application operation platform, determines the second communication bridge, and calls and communicates the engine-side project based on the bridge, thereby realizing two-way communication.
It realizes seamless integration and real-time interaction between Unity applications and web applications, improves user experience, improves development efficiency, and broadens the application usage scenarios and scope.
Smart Images

Figure CN119922173A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computer software development and information technology, and specifically to a two-way communication method, apparatus, computer equipment and storage medium. Background Art
[0002] Unity, as a widely used cross-platform game development engine (engine-side engineering), supports high-quality graphics rendering from 2D to 3D, has rich physical simulation and sound processing functions, and is widely used in games, virtual reality (VR), augmented reality (AR), simulation training, architectural design visualization and other fields. Web technology (front-end engineering), especially technologies based on modern Web standards such as HTML5, CSS3, and Vue development framework, enables Web applications to quickly and easily implement complex interactive logic and exquisite UI interface display, becoming an important bridge connecting users and servers.
[0003] With the rapid development of Internet technology and the growing demand of users for seamless cross-platform experience, it is particularly important to achieve efficient, stable and real-time two-way communication between Unity clients (such as games and visual 3D application clients) and Web clients (such as web pages and Web applications).
[0004] However, existing communication solutions often have problems such as low communication efficiency, cross-end communication barriers, and cross-domain access restrictions, which limit the deep integration and interactive experience between Unity applications and Web platforms. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a two-way communication method to address the defects and shortcomings of the prior art, which has the advantage of promoting seamless integration and real-time interaction between Unity applications and Web applications.
[0006] In order to solve the above technical problems, the embodiment of the present application provides a two-way communication method, which is applied to front-end engineering and engine-end engineering, and adopts the following technical solutions:
[0007] Get the application running platform;
[0008] Conditionally compile the application running platform through the engine-side project, determine a first communication bridge, and call the front-end project for communication based on the first communication bridge;
[0009] The front-end project performs platform detection processing on the application running platform, determines the second communication bridge, and calls the engine-side project for communication based on the second communication bridge.
[0010] Furthermore, the first communication bridge includes a first webpage communication channel and a first desktop communication channel, and before the step of conditionally compiling the application running platform through the engine-side project and determining the first communication bridge, the step further includes:
[0011] Constructing a communication script file in the engine-side project, and calling the communication script file through the engine-side project to obtain the first webpage communication channel;
[0012] A browser control is constructed in the engine-side project, and the browser control is called by the engine-side project to obtain the first desktop communication channel.
[0013] Furthermore, the second communication bridge includes a second webpage communication channel and a second desktop communication channel, and before the step of performing platform detection processing on the application running platform through the front-end engineering and determining the second communication bridge, specifically includes:
[0014] Calling a webpage communication method through the front-end engineering to establish a second webpage communication channel;
[0015] The second desktop communication channel is obtained by calling the browser control through the front-end project. Further, the step of conditionally compiling the application running platform through the engine-side project, determining the first communication bridge, and calling the front-end project for communication based on the first communication bridge specifically includes:
[0016] Obtain a two-way bridging script, and import the two-way bridging script into the engine-side project;
[0017] The application running platform is compiled and judged based on the bidirectional bridging script to obtain the first communication bridge, and the front-end project is called for communication based on the first communication bridge.
[0018] Furthermore, the application running platform includes a web page running platform and a desktop running platform, and the steps of compiling and judging the application running platform based on the two-way bridge script, obtaining the first communication bridge, and calling and communicating with the front-end project based on the first communication bridge specifically include:
[0019] When the application running platform is the web page running platform, determining that the first communication bridge is a first web page communication channel;
[0020] The engine-side project imports the communication information into the communication script file according to a preset coding format, and calls the front-end project for communication;
[0021] When the application running platform is the desktop running platform, determining that the first communication bridge is a first desktop communication channel;
[0022] The engine-side project calls the first desktop calling method in the browser control to perform calling communication with the front-end project.
[0023] Furthermore, the step of performing platform detection processing on the application running platform through the front-end project, determining the second communication bridge, and calling the engine-side project for communication based on the second communication bridge specifically includes:
[0024] Obtaining the platform configuration field of the application running platform;
[0025] The application running platform is classified based on the platform configuration field, a second communication bridge is determined, and the engine-side project is called for communication based on the second communication bridge.
[0026] Furthermore, the step of classifying the application running platform based on the platform configuration field, determining the second communication bridge, and calling the engine-side project for communication based on the second communication bridge specifically includes:
[0027] When the application running platform is the web page running platform, determining that the second communication bridge is a second web page communication channel;
[0028] Obtain the engine object and communication method of the engine-side project, instantiate the engine object through the front-end project and call the communication method to call and communicate with the engine-side project;
[0029] When the application running platform is the desktop running platform, determining that the second communication bridge is a second desktop communication channel;
[0030] The front-end project calls the second desktop calling method in the browser control to call and communicate with the engine-side project.
[0031] In order to solve the above technical problems, the embodiment of the present application also provides a two-way communication device, which is applied to front-end engineering and engine-end engineering, and adopts the following technical solutions:
[0032] An acquisition module is used to obtain the application running platform;
[0033] A first communication module, used to perform conditional compilation processing on the application running platform through the engine-side project, determine a first communication bridge, and call and communicate with the front-end project based on the first communication bridge;
[0034] The second communication module is used to perform platform detection processing on the application running platform through the front-end project, determine the second communication bridge, and call the engine-side project for communication based on the second communication bridge.
[0035] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0036] A computer device comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the two-way communication method when executing the computer-readable instructions.
[0037] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0038] A computer-readable storage medium, characterized in that computer-readable instructions are stored on the computer-readable storage medium, and when the computer-readable instructions are executed by a processor, the steps of the two-way communication method are implemented.
[0039] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0040] In the embodiment of the present application, the engine-side project performs conditional compilation processing on the application running platform, determines the first communication bridge, and calls the front-end project for communication based on the first communication bridge. The front-end project performs platform detection processing on the application running platform, determines the second communication bridge, and calls the engine-side project for communication based on the second communication bridge, thereby achieving seamless integration and real-time interaction between the front-end project and the engine-side project, improving user experience, improving the development efficiency of engine-side project applications and front-end project applications, and broadening the use scenarios and scope of front-end project applications and engine-side project applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0042] Figure 1 is a system architecture diagram of the present application to which the present application may be applied;
[0043] Figure 2 A flowchart of an embodiment of a two-way communication method according to the present application;
[0044] Figure 3 is a flow chart of another embodiment of the two-way communication method according to the present application;
[0045] Figure 4is a flow chart of another embodiment of the two-way communication method according to the present application;
[0046] Figure 5 is a flow chart of another embodiment of the two-way communication method according to the present application;
[0047] Figure 6 is a flow chart of another embodiment of the two-way communication method according to the present application;
[0048] Figure 7 is a schematic structural diagram of an embodiment of a two-way communication device according to the present application;
[0049] Figure 8 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0051] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0052] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0053] like Figure 1As shown, the system architecture of the two-way communication method may include a Web application 101, a Unity WebGLLibrary module 102, a Unity engine end 103, an environment detection device 104 and a desktop application 105, wherein the Web application 101 includes a first JavaScript code module 1011, the JavaScript code module 1011 includes a JSBridgeSDK module 10111, the Unity engine end 103 includes a JSBridgeObject module 1031, the JSBridgeObject module 1031 includes a JSBridgeBehaviour module 10311 and a second JavaScript code module 10312, the JSBridgeBehaviour module 10311 includes [DllImport("__Internal")] 103111 and a C# code module 103112, and the desktop application 105 includes a NativeBrowserSDK module 1051.
[0054] The above-mentioned Web application 101 performs two-way data transmission or two-way data communication with the NativeBrowserSDK module 1051, the above-mentioned first JavaScript code module 1011 performs two-way data transmission or two-way data communication with the Unity WebGL Library module 102, the above-mentioned JSBridgeBehaviour module 10311 can perform one-way data transmission or one-way data communication with the Unity WebGL Library module 102, the above-mentioned environment detection device 104 can perform one-way data transmission or one-way data communication to the Web application 101, the desktop application 105 and the Unityiy engine end 103, the above-mentioned Unityiy engine end 103 can perform two-way data transmission or two-way data communication with the desktop application 105, and the above-mentioned JSBridgeBehaviour module 10311 can perform one-way data transmission or one-way data communication to the second JavaScript code module 10312.
[0055] Specifically, the JSBridgeSDK module 10111 encapsulates the ability to execute a specified JavaScript by allowing the script of the JSBridgeObject object. The specified first JavaScript code module 1011 can directly use the C# code module 103112 in the Unity engine end 103, manipulate the objects of the Unity engine end 103, and implement the functions of the objects in the Unity engine end 103;
[0056] The JSBridgeObject module 1031 may be an object used to bridge the second JavaScript code module 10312 and the C# code module 103112 in the Unity engine end 103. The object will be bound to a JSBridgeObject script component for defining behavior.
[0057] The JSBridgeBehaviour module 10311 may be the JSBridgeObject script component, which may implement some commonly used Unity operation methods internally, so that the code in the second JavaScript code module 10312 may be directly called to achieve the purpose of Javascript communicating with Unity.
[0058] The above-mentioned [DllImport("__Internal")] module 103111 may be an important feature in the C# language, which provides a mechanism that enables managed code in the .NET environment to interact with unmanaged code. Therefore, this feature can be used to implement C# code calling Javascript code, thereby achieving the purpose of Unity communicating with Javascript.
[0059] The Unity WebGL Library module 102 may be a JavaScript library embedded into a build package after a Unity application is published as Unity WebGL.
[0060] The NativeBrowserSDK module 1051 may refer to a Unity native browser control (eg, ZFBrowser) used in Unity to process and display web pages. Since its function is to integrate a browser in the client to display web pages, it can only be applied to the desktop and does not support application to the Web.
[0061] Continue to refer Figure 2 , shows a flow chart of an embodiment of a two-way communication method according to the present application. The two-way communication method comprises the following steps:
[0062] Step 201, obtaining an application running platform;
[0063] In this embodiment, the application running platform includes a web running platform and a desktop running platform. Specifically, the web running platform refers to a web application running in a browser environment, which usually relies on WebGL technology for 3D rendering and interaction. Typical environments include mainstream browsers such as Chrome, Firefox, and Edge, while the desktop running platform refers to an application running independently on a desktop operating system (such as Windows, macOS, and Linux).
[0064] Step 202, conditionally compile the application running platform through the engine-side project, determine the first communication bridge, and call the front-end project for communication based on the first communication bridge;
[0065] Step 203: Perform platform detection processing on the application running platform through the front-end project, determine the second communication bridge, and call the engine-side project for communication based on the second communication bridge.
[0066] In this embodiment, the engine-side project can be an application developed based on the Unity engine, usually developed using the C# language, and is mainly responsible for complex 3D rendering, physical simulation, animation control, and business logic processing. The front-end project can be an application interface and logic layer built based on Web technology (such as HTML5, CSS3, JavaScript, Vue framework, etc.), which is mainly responsible for interacting with users and displaying information. The front-end project can include a web page operation platform and / or a desktop operation platform.
[0067] In this embodiment, the above platform detection processing and conditional compilation processing are both for selecting a suitable communication bridge according to the application running platform to ensure smooth two-way communication between the front-end project and the engine-end project. Specifically, the platform detection processing focuses on dynamically judging the platform characteristics at runtime, while the conditional compilation processing focuses on static judgment at the compilation stage. The two complement each other and jointly ensure the compatibility and efficiency of cross-platform applications in different environments.
[0068] In this embodiment, the first communication bridge and the second communication bridge are message channels for realizing two-way communication between the front-end project and the engine-side project. Specifically, the first communication bridge is determined by the engine-side project through conditional compilation processing, and calls the front-end project for communication based on the bridge. The second communication bridge is determined by the front-end project through platform detection processing, and calls the engine-side project for communication based on the bridge. These two communication bridges jointly ensure two-way data transmission and function calls between the front-end and the engine-side on different platforms, thereby supporting stable and efficient cross-platform interaction.
[0069] In a possible embodiment, the above two-way communication method can be deployed in Figure 1In the system architecture shown, Figure 1 The Web application 101 and the desktop application 105 can be combined as a front-end project. Specifically, the Web application 101 can be used as the web page running platform, the desktop application 105 can be used as the desktop running platform, the Unity engine side can be used as an engine side project, and the environment detection device 104 can be used to perform platform detection processing and conditional compilation processing.
[0070] In an embodiment of the present application, the engine-side project is conditionally compiled on the application running platform to determine a first communication bridge, and based on the first communication bridge, the front-end project is called for communication. The front-end project is platform detected on the application running platform to determine a second communication bridge, and based on the second communication bridge, the engine-side project is called for communication, thereby achieving seamless integration and real-time interaction between the front-end project and the engine-side project, improving user experience, improving the development efficiency of engine-side project applications and front-end project applications, and broadening the use scenarios and scope of front-end project applications and engine-side project applications.
[0071] In some optional implementations, before step 202, the following steps are included:
[0072] Building a communication script file in the engine-side project, and calling the communication script file through the engine-side project to obtain a first webpage communication channel;
[0073] A browser control is constructed in the engine-side project, and the browser control is called through the engine-side project to obtain a first desktop communication channel.
[0074] In some optional implementations, before step 203, the following steps are included:
[0075] Calling the webpage communication method through the front-end engineering to establish a second webpage communication channel;
[0076] The second desktop communication channel is obtained by calling the browser control through the front-end project.
[0077] In this embodiment, the first communication bridge includes a first webpage communication channel and a first desktop communication channel, and the second communication bridge includes a second webpage communication channel and a second desktop communication channel.
[0078] This embodiment combines Figure 3 and Figure 4 To explain, specifically:
[0079] exist Figure 3 In the engine-side project 32, create a file ending with .jslib (that is, the communication script file mentioned above), such as Figure 3The webgl.jslib file shown in the figure, the engine-side project 32 defines the Javascript method that the engine-side project 32 needs to call in the webgl.jslib file according to the encoding format required by UnityWebGL. When the engine-side project 32 compiles the webgl.jslib file into a WebGL application, the Javascript method will eventually be added to the .UnityLib object property of the Javascript window object. At this time, under the web page running platform, the Unity script also has the ability to call the Javascript function, that is, the engine-side project 32 communicates with the front-end project 31 in the way of communicating with the webgl.jslib file, and establishes the first web page communication channel;
[0080] exist Figure 3 In the front-end project 31, when the project is initialized, the message channel (i.e., the above-mentioned second web page communication channel) can be defined by calling the myUnityInstance.SendMessage('MyGameObject', 'MyFunction') method (i.e., the above-mentioned web page communication method), wherein 'MyGameObject' is the game object in the Unity project (i.e., the above-mentioned engine-side project 32), and 'MyFunction' is the name of a function in the game object 'MyGameObject' in Unity. At this time, under the web page running platform, the Javascript function also has the ability to call the Unity script function, that is, the front-end project 31 establishes the above-mentioned second web page communication channel with the engine-side project 32 by calling the myUnityInstance.SendMessage method for communication;
[0081] exist Figure 4 The browser control supported by Unity is introduced into the engine-side project 42. The above browser control can embed web pages into the Unity project and realize the function of displaying web browser pages in the Unity application. Figure 4Take the ZFBrowser browser control in as an example. The ZFBrowser browser control provides a browser instance browser and a corresponding communication method. Browser.RegisterFunction("MyFunction", args=>{ / *business code logic* / }) is used to implement the Unity script function (C# function) called by the front-end Javascript. When the project is compiled as a desktop running platform, "MyFunction" will eventually be added to the window object of the front-end project 41. The engine-side project 42 can use browser.CallFunction("MyFunction2", param).Done() to implement Unity calling the Javascript function (that is, communicating with the front-end project 41), that is, calling the browser control through the engine-side project to obtain the first desktop communication channel.
[0082] exist Figure 4 In the front-end project 41, because the function to be called has been added under the window object of the front-end project 41 during the process of the engine-side project 42 calling the browser control, the front-end project 41 can directly communicate with the engine-side project 42 by calling window.MyFunction(), and the engine-side project 42 will receive the corresponding signal, that is, the second desktop communication channel is obtained by calling the browser control through the front-end project.
[0083] In this embodiment, by constructing a web communication channel and a desktop communication channel in the engine-side project and the front-end project respectively, the ability to call Javascript functions through Unity on the web running platform (i.e., the engine-side project communicates with the front-end project) and the ability to call C# functions in Unity through Javascript (i.e., the front-end project communicates with the engine-side project) are realized. The ability to call Javascript functions through Unity on the desktop running platform (i.e., the engine-side project communicates with the front-end project) and the ability to call Unity script functions through Javascript (i.e., the front-end project communicates with the engine-side project) are also realized. Regardless of whether the application runs on a web running platform or a desktop running platform, this method can perform stable and efficient data transmission and function calls based on appropriate communication channels, thereby improving cross-platform compatibility, reducing platform differences, and improving development and operation efficiency.
[0084] In some optional implementations, step 202 includes the following steps:
[0085] Get the two-way bridge script and import it into the engine-side project;
[0086] The application running platform is compiled and judged based on the two-way bridging script to obtain a first communication bridge, and the front-end project is called for communication based on the first communication bridge.
[0087] Among them, the step of "compiling and judging the application running platform based on the two-way bridge script, obtaining the first communication bridge, and calling and communicating with the front-end project based on the first communication bridge." includes:
[0088] When the application running platform is a web running platform, determining the first communication bridge to be a first web communication channel;
[0089] The engine-side project imports the communication information into the communication script file according to the preset coding format, and calls the front-end project for communication;
[0090] When the application running platform is a desktop running platform, determining the first communication bridge to be a first desktop communication channel;
[0091] The engine-side project calls the first desktop calling method in the browser control to call and communicate with the front-end project.
[0092] This embodiment combines Figure 5 To explain, specifically:
[0093] like Figure 5 As shown, create a VueBridge script (i.e., a two-way bridge script) and import it into the engine-side project. In the VueBridge script, you can use C# conditional compilation statements to determine the compiled platform to execute the code for the corresponding platform environment. The above code is as follows:
[0094] #if UNITY_STANDALONE_WIN
[0095] / / Desktop mode
[0096] browser.CallFunction(functionName,param).Done();
[0097] #elif UNITY_WEBGL
[0098] / / Web page method
[0099] CallJSFunction(functionName,param);
[0100] For example, when the engine-side project is compiled and released, the developer selects the application running platform for packaging and compilation, and uses the conditional compilation mechanism in the VueBridge script to determine which communication bridge to use (i.e. Figure 5If the result is a web page running platform, the WebGLBridge channel is used to execute CallJSFunction(functionName,param), and the JavaScript method name and parameters to be executed are imported into the webgl.jslib file (communication script), and the coding format required by UnityWebGL is used in the webgl.jslib file to realize the call communication with the front-end project.
[0101] If the judgment result is a desktop running platform, the NativeBrowserBridge channel is used to execute browser.CallFunction(functionName,param).Done() processing (that is, the first desktop calling method mentioned above) to call the front-end project for communication, select different communication bridges according to the platform, and realize communication methods compatible with different platforms.
[0102] In some optional implementations, step 203 includes the following steps:
[0103] Get the platform configuration fields of the platform where the application runs;
[0104] The application running platform is classified based on the platform configuration field, a second communication bridge is determined, and the engine-side project is called for communication based on the second communication bridge.
[0105] Among them, the step of "classifying the application running platform based on the platform configuration field, determining the second communication bridge, and calling the engine-side project for communication based on the second communication bridge" includes:
[0106] When the application running platform is a web page running platform, determining the second communication bridge to be a second web page communication channel;
[0107] Get the engine object and communication method of the engine-side project, instantiate the engine object through the front-end project and call the communication method to call the engine-side project;
[0108] When the application running platform is a desktop running platform, determining the second communication bridge to be a second desktop communication channel;
[0109] The front-end project calls the second desktop calling method in the browser control to call and communicate with the engine-side project.
[0110] This embodiment combines Figure 6 To explain, specifically:
[0111] When the front-end project is initialized, the platform on which the application is currently running is obtained based on the browser's navigator.userAgent field information (platform configuration field) and stored in the global state. Then, different calling methods are determined based on the running platform within VueSDK (i.e., the application running platform is classified based on the platform configuration field). If the platform on which the application is currently running is a web page running platform, the WebGLBridge channel is used to obtain the engine object and communication method of the engine-side project, and the myUnityInstance.SendMessage('engine object', 'communication method') method is executed to implement calling and communicating with the engine-side project.
[0112] If the application is currently running on a desktop platform, the NativeBrowserBridge channel is used. The ZFBrowser browser control can be used to provide the browser instance browser and the corresponding communication method. Browser.RegisterFunction("MyFunction", args=>{ / *business code logic* / }) is used to implement the Unity script function called by the front-end Javascript (that is, to implement the call communication to the engine-side project). Alternatively, the application can directly communicate with the engine-side project by calling window.MyFunction(), thereby selecting different communication bridges according to the platform and implementing communication methods compatible with different platforms.
[0113] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0114] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0115] like Figure 7 As shown, the two-way communication device 700 described in this embodiment includes: an acquisition module 701, a first communication module 702 and a second communication module 703. Among them:
[0116] The acquisition module 701 is used to perform conditional compilation processing on the application running platform through the engine-side project, determine the first communication bridge, and call the front-end project for communication based on the first communication bridge;
[0117] The first communication module 702 is used to perform conditional compilation processing on the application running platform through the engine-side project, determine the first communication bridge, and call the front-end project for communication based on the first communication bridge;
[0118] The second communication module 703 is used to perform platform detection processing on the application running platform through the front-end project, determine the second communication bridge, and call the engine-side project for communication based on the second communication bridge.
[0119] Before the first communication module 702, the method further includes:
[0120] A first construction module is used to construct a communication script file in the engine-side project, and to obtain the first webpage communication channel by calling the communication script file through the engine-side project;
[0121] The second construction module is used to construct a browser control in the engine-side project, and to call the browser control through the engine-side project to obtain the first desktop communication channel.
[0122] Before the second communication module 703, the method further includes:
[0123] A first calling module, used to call the webpage communication method through the front-end project to establish a second webpage communication channel;
[0124] The second calling module is used to call the browser control through the front-end project to obtain the second desktop communication channel.
[0125] Wherein, the first communication module 702 includes:
[0126] A first acquisition submodule is used to acquire a bidirectional bridge script and import the bidirectional bridge script into the engine-side project;
[0127] The compilation judgment submodule is used to compile and judge the application running platform based on the two-way bridge script, obtain the first communication bridge, and call the front-end project for communication based on the first communication bridge.
[0128] Wherein, the compilation judgment submodule includes:
[0129] A first determining unit, configured to determine, when the application running platform is the web running platform, that the first communication bridge is a first web communication channel;
[0130] An import unit, used to import the communication information into the communication script file according to a preset coding format through the engine-side project, and call the front-end project for communication;
[0131] A second determining unit, configured to determine, when the application running platform is the desktop running platform, that the first communication bridge is a first desktop communication channel;
[0132] The first calling unit is used to call the first desktop calling method in the browser control through the engine-side project to call and communicate with the front-end project.
[0133] Wherein, the second communication module 702 includes:
[0134] A second acquisition submodule is used to acquire the platform configuration field of the application running platform;
[0135] The platform classification submodule is used to classify the application running platform based on the platform configuration field, determine the second communication bridge, and call the engine-side project for communication based on the second communication bridge.
[0136] Wherein, the platform classification submodule includes:
[0137] a third determining unit, configured to determine, when the application running platform is the web page running platform, that the second communication bridge is a second web page communication channel;
[0138] An instantiation unit, used for acquiring the engine object and the communication method of the engine-side project, instantiating the engine object and calling the communication method through the front-end project, and calling and communicating with the engine-side project;
[0139] a fourth determining unit, configured to determine, when the application running platform is the desktop running platform, that the second communication bridge is a second desktop communication channel;
[0140] The second calling unit is used to call the second desktop calling method in the browser control through the front-end project to call and communicate with the engine-side project.
[0141] In this embodiment, the application running platform is conditionally compiled through the engine-side project to determine the first communication bridge, and the front-end project is called for communication based on the first communication bridge. The application running platform is platform detected through the front-end project to determine the second communication bridge, and the engine-side project is called for communication based on the second communication bridge, thereby achieving seamless integration and real-time interaction between the front-end project and the engine-side project, improving user experience, improving the development efficiency of engine-side project applications and front-end project applications, and broadening the use scenarios and scope of front-end project applications and engine-side project applications.
[0142] In this embodiment, the operations performed by the above units or modules correspond one-to-one to the steps of the two-way communication method in the above implementation mode, and are not described in detail here.
[0143] To solve the above technical problems, the present application also provides a computer device. Figure 8 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0144] The computer device 8 includes a memory 81, a processor 82, and a network interface 83 that are interconnected through a system bus. It should be noted that the figure only shows a computer device 8 with components 81-83, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.
[0145] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0146] The memory 81 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 81 can be an internal storage unit of the computer device 8, such as a hard disk or memory of the computer device 8. In other embodiments, the memory 81 can also be an external storage device of the computer device 8, such as a plug-in hard disk equipped on the computer device 8, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Of course, the memory 81 can also include both the internal storage unit of the computer device 8 and its external storage device. In this embodiment, the memory 81 is generally used to store the operating system and various application software installed on the computer device 8, such as computer-readable instructions of a two-way communication method, etc. In addition, the memory 81 can also be used to temporarily store various types of data that have been output or are to be output.
[0147] The processor 82 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 82 is generally used to control the overall operation of the computer device 8. In this embodiment, the processor 82 is used to run computer-readable instructions stored in the memory 81 or process data, such as computer-readable instructions for running the two-way communication method.
[0148] The network interface 83 may include a wireless network interface or a wired network interface. The network interface 83 is generally used to establish a communication connection between the computer device 8 and other electronic devices.
[0149] This embodiment provides a computer device, which performs conditional compilation processing on the application running platform through the engine-side project, determines a first communication bridge, and calls the front-end project for communication based on the first communication bridge, performs platform detection processing on the application running platform through the front-end project, determines a second communication bridge, and calls the engine-side project for communication based on the second communication bridge, thereby achieving seamless integration and real-time interaction between the front-end project and the engine-side project, improving user experience, improving the development efficiency of engine-side project applications and front-end project applications, and broadening the use scenarios and scope of front-end project applications and engine-side project applications.
[0150] The present application also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the two-way communication method as described above.
[0151] This embodiment provides a computer-readable storage medium, which conditionally compiles the application running platform through the engine-side project, determines a first communication bridge, and calls the front-end project for communication based on the first communication bridge, performs platform detection processing on the application running platform through the front-end project, determines a second communication bridge, and calls the engine-side project for communication based on the second communication bridge, thereby achieving seamless integration and real-time interaction between the front-end project and the engine-side project, improving user experience, improving the development efficiency of engine-side project applications and front-end project applications, and broadening the use scenarios and scope of front-end project applications and engine-side project applications.
[0152] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0153] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.
Claims
1. A two-way communication method, applied to front-end engineering and engine-end engineering, comprising: Get the application running platform; Conditionally compile the application running platform through the engine-side project, determine a first communication bridge, and call the front-end project for communication based on the first communication bridge; The front-end project performs platform detection processing on the application running platform, determines the second communication bridge, and calls the engine-side project for communication based on the second communication bridge.
2. The two-way communication method according to claim 1, characterized in that: The first communication bridge includes a first webpage communication channel and a first desktop communication channel. Before the step of conditionally compiling the application running platform through the engine-side project and determining the first communication bridge, the step further includes: Constructing a communication script file in the engine-side project, and calling the communication script file through the engine-side project to obtain the first webpage communication channel; A browser control is constructed in the engine-side project, and the browser control is called by the engine-side project to obtain the first desktop communication channel.
3. The two-way communication method according to claim 2, characterized in that: The second communication bridge includes a second webpage communication channel and a second desktop communication channel. Before the step of performing platform detection processing on the application running platform through the front-end engineering to determine the second communication bridge, the method specifically includes: Calling a webpage communication method through the front-end engineering to establish a second webpage communication channel; The second desktop communication channel is obtained by calling the browser control through the front-end project.
4. The two-way communication method according to claim 3, characterized in that: The step of conditionally compiling the application running platform through the engine-side project, determining the first communication bridge, and calling the front-end project for communication based on the first communication bridge specifically includes: Obtain a two-way bridging script, and import the two-way bridging script into the engine-side project; The application running platform is compiled and judged based on the bidirectional bridging script to obtain the first communication bridge, and the front-end project is called for communication based on the first communication bridge.
5. The two-way communication method according to claim 4, characterized in that: The application running platform includes a web page running platform and a desktop running platform. The steps of compiling and judging the application running platform based on the two-way bridge script, obtaining the first communication bridge, and calling and communicating with the front-end project based on the first communication bridge specifically include: When the application running platform is the web page running platform, determining that the first communication bridge is a first web page communication channel; The engine-side project imports the communication information into the communication script file according to a preset coding format, and calls the front-end project for communication; When the application running platform is the desktop running platform, determining that the first communication bridge is a first desktop communication channel; The engine-side project calls the first desktop calling method in the browser control to perform calling communication with the front-end project.
6. The two-way communication method according to claim 3, characterized in that: The step of performing platform detection processing on the application running platform through the front-end project, determining the second communication bridge, and calling and communicating with the engine-side project based on the second communication bridge specifically includes: Obtaining the platform configuration field of the application running platform; The application running platform is classified based on the platform configuration field, a second communication bridge is determined, and the engine-side project is called for communication based on the second communication bridge.
7. The two-way communication method according to any one of claims 5 or 6, characterized in that: The step of classifying the application running platform based on the platform configuration field, determining the second communication bridge, and calling and communicating with the engine-side project based on the second communication bridge specifically includes: When the application running platform is the web page running platform, determining that the second communication bridge is a second web page communication channel; Obtain the engine object and communication method of the engine-side project, instantiate the engine object through the front-end project and call the communication method to call and communicate with the engine-side project; When the application running platform is the desktop running platform, determining that the second communication bridge is a second desktop communication channel; The front-end project calls the second desktop calling method in the browser control to call and communicate with the engine-side project.
8. A two-way communication device, applied to front-end engineering and engine-end engineering, characterized in that: include: An acquisition module is used to obtain the application running platform; A first communication module, used to perform conditional compilation processing on the application running platform through the engine-side project, determine a first communication bridge, and call and communicate with the front-end project based on the first communication bridge; The second communication module is used to perform platform detection processing on the application running platform through the front-end project, determine the second communication bridge, and call the engine-side project for communication based on the second communication bridge.
9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the two-way communication method according to any one of claims 1 to 7 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the two-way communication method according to any one of claims 1 to 7 are implemented.