Search

CN-122001867-A - Cross-component communication method, device, equipment, medium and product

CN122001867ACN 122001867 ACN122001867 ACN 122001867ACN-122001867-A

Abstract

The invention discloses a method, a device, equipment, a medium and a product for cross-component communication. The method comprises the steps of receiving starting parameters from a main application, obtaining a main application service address which is pre-established and provided by the main application according to the starting parameters, establishing sub-application communication service, determining the sub-application service address, sending the sub-application service address to the main application, enabling the main application and the sub-application to establish two-way communication based on the main application service address and the sub-application service address, loading an embedded Web container, carrying out two-way communication with the embedded Web container through a communication interface which is pre-arranged in the embedded Web container, providing the main application service address to the embedded Web container, enabling the embedded Web container to communicate with the main application according to the main application service address, receiving communication data which is sent by the main application and aims at the embedded Web container, and forwarding the communication data to the embedded Web container. The embodiment of the invention can solve the communication difficulty of deep integration of heterogeneous applications and Web contents in a complex desktop system.

Inventors

  • LIANG XIANCHAO
  • JIA QIANGQIANG
  • Zeng Pengxuan
  • WANG YUHANG

Assignees

  • 北京思明启创科技有限公司

Dates

Publication Date
20260508
Application Date
20260122

Claims (10)

  1. 1. A method of cross-component communication performed by a sub-application that is started by a main application, the method comprising: Receiving a starting parameter from a main application, and acquiring a main application service address which is pre-established and provided by the main application according to the starting parameter; Establishing a sub-application communication service, determining a sub-application service address, and transmitting the sub-application service address to the main application through the main application service address, so that the main application and the sub-application establish two-way communication based on the main application service address and the sub-application service address; Loading an embedded Web container, and carrying out bidirectional communication with the embedded Web container through a communication interface pre-arranged in the embedded Web container; providing the main application service address to the embedded Web container, so that the embedded Web container communicates with the main application according to the main application service address; and receiving communication data which are sent by the main application and aim at the embedded Web container, and forwarding the communication data to the embedded Web container.
  2. 2. The method of claim 1, wherein the initiation parameters include a path of a profile set by the host application, the profile including the host application service address, wherein establishing the sub-application communication service, determining the sub-application service address, comprises: attempting to start HTTP service monitoring from the initial port number; if the starting fails, the port number is increased according to a preset step size and then try again until the starting is successful or the maximum try times are reached; and taking the network address for successfully starting HTTP service monitoring as the sub-application service address.
  3. 3. The method of claim 1, wherein the bi-directional communication with the embedded Web container via a communication interface pre-disposed in the embedded Web container comprises: transmitting instructions or data to the embedded Web container by invoking a first method of the communication interface, the instructions or data comprising a unique identifier and an event type; Receiving a request initiated by the embedded Web container through a second method for calling the communication interface; And receiving an asynchronous processing result which is returned by the embedded Web container through a third method for calling the communication interface and corresponds to the unique identifier.
  4. 4. The method of claim 1, wherein communication data in a uniform format is interacted between the main application and the sub application, between the sub application and the embedded Web container, and between the embedded Web container and the main application; The communication data comprises a type field and an event name field, wherein the type field is used for indicating the type of a target communication endpoint and realizing the routing distribution of the data, the type of the communication endpoint comprises a main application, a sub-application and an embedded Web container, and the event name field is used for uniquely identifying and triggering a predefined business operation or state notification in the target communication endpoint designated by the type field.
  5. 5. The method of claim 4, wherein receiving communication data sent by the host application and targeted to the embedded Web container and forwarding the communication data to the embedded Web container comprises: receiving communication data which is sent by a main application and takes an embedded Web container as a target communication endpoint; and forwarding the communication data to the embedded Web container through a communication interface preset in the embedded Web container.
  6. 6. The method of claim 1, wherein the lifecycle status of the sub-application is monitored by the main application, the main application being triggered to cease business functions associated with the sub-application when the sub-application exits.
  7. 7. A cross-component communication device configured for a sub-application that is started by a main application, the device comprising: the system comprises a main application address acquisition module, a main application service address acquisition module and a control module, wherein the main application address acquisition module is used for receiving starting parameters from a main application and acquiring a main application service address which is pre-established and provided by the main application according to the starting parameters; the first bidirectional communication module establishes a sub-application communication service, determines a sub-application service address, and sends the sub-application service address to the main application through the main application service address, so that the main application and the sub-application establish bidirectional communication based on the main application service address and the sub-application service address; The second bidirectional communication module is used for loading an embedded Web container and carrying out bidirectional communication with the embedded Web container through a communication interface which is pre-arranged in the embedded Web container; The main application address forwarding module is used for providing the main application service address for the embedded Web container so that the embedded Web container communicates with the main application according to the main application service address; and the communication data forwarding module is used for receiving communication data which is sent by the main application and aims at the embedded Web container, and forwarding the communication data to the embedded Web container.
  8. 8. An electronic device, the electronic device comprising: at least one processor; and a memory communicatively coupled to the at least one processor; Wherein the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the inter-component communication method of any of claims 1-6.
  9. 9. A computer readable storage medium storing computer instructions for causing a processor to implement the cross-component communication method of any one of claims 1-6 when executed.
  10. 10. A computer program product comprising a computer program which, when executed by a processor, implements the inter-component communication method according to any of claims 1-6.

Description

Cross-component communication method, device, equipment, medium and product Technical Field The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, a medium, and a product for inter-component communication. Background In the current cross-platform desktop application based on an Electron and other frameworks, in order to realize function modularization and multiplexing, a three-layer architecture of 'main application-sub application-embedded Web container' is often adopted. However, inter-application communication under this architecture always faces the serious challenge that existing single communication schemes, such as common memory, startup parameter transfer, file sharing, log listening, or pure network connection, all suffer from inherent drawbacks. The method is characterized in that common memory hardware is sensitive, troublesome in writing and easy to make mistakes, starting parameter transfer can only be carried out, synchronous transmission of a large number of initialization parameters cannot be supported, coding format requirements are strict, some characters are easy to be transcoded and the like to cause unrecognizable, file sharing is occupied and monitoring is complex, file change is judged by time cyclic reading, resource consumption is large, log monitoring can only be used for monitoring log output of sub-applications, a network connection of a pure long connection is used, a client lacks some authority configuration of a server, the maintenance cost of the long connection authority is high, the network connection of the pure short connection needs to know a local communication address and can be initialized after network communication is realized, a transfer server is needed to communicate, cost is high, and some character combinations cannot be used due to transcoding through proxy protocol communication between an embedded Web container and an application. The existing single communication scheme is limited by the problems of character transcoding, resource overhead, firewall configuration, platform diversity and the like, so that a communication link is fragile, limited in function and poor in stability, and complete cross-level bidirectional communication becomes a long-standing technical problem. Disclosure of Invention The invention provides a method, a device, equipment, a medium and a product for cross-component communication, which are used for solving the long-term technical problem of stable and bidirectional communication among a main application, a sub-application and an embedded Web container. According to an aspect of the present invention, there is provided a cross-component communication method performed by a sub-application started by a main application, including: Receiving a starting parameter from a main application, and acquiring a main application service address which is pre-established and provided by the main application according to the starting parameter; Establishing a sub-application communication service, determining a sub-application service address, and transmitting the sub-application service address to the main application through the main application service address, so that the main application and the sub-application establish two-way communication based on the main application service address and the sub-application service address; Loading an embedded Web container, and carrying out bidirectional communication with the embedded Web container through a communication interface pre-arranged in the embedded Web container; providing the main application service address to the embedded Web container, so that the embedded Web container communicates with the main application according to the main application service address; and receiving communication data which are sent by the main application and aim at the embedded Web container, and forwarding the communication data to the embedded Web container. According to another aspect of the present invention, there is provided a cross-component communication apparatus configured to a sub-application started by a main application, the apparatus comprising: the system comprises a main application address acquisition module, a main application service address acquisition module and a control module, wherein the main application address acquisition module is used for receiving starting parameters from a main application and acquiring a main application service address which is pre-established and provided by the main application according to the starting parameters; the first bidirectional communication module establishes a sub-application communication service, determines a sub-application service address, and sends the sub-application service address to the main application through the main application service address, so that the main application and the sub-application establish bidirectional communication based on the main application serv