A message communication method, system and electronic device

By designing a layered architecture consisting of a data source layer, a state management layer, a core processing layer, and a user interface interaction layer, the existing SDK addresses the challenges of simultaneously achieving business decoupling, multi-source disaster recovery, state consistency, and type expansion. This enables reliable message transmission, global state consistency, and flexible expansion.

CN123123410APending Publication Date: 2026-11-17BEIJING LONGJU YIXING TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611264011.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-19
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing chat SDKs struggle to balance business decoupling, multi-source disaster recovery, state consistency, and type expansion. They suffer from poor reusability, a single data source, easy message loss or high latency, and difficulty in synchronizing components due to fragmented state management.

Method used

It adopts a layered architecture, including a data source layer, a state management layer, a core processing layer, and a user interface interaction layer. It solves the data source problem through multi-protocol adaptive switching, a single state data source manages the global state, and message types are processed in a plug-in manner. The user interface interaction layer decouples the user interaction logic by dispatching actions.

Benefits of technology

It achieves reliable message transmission with multi-channel disaster recovery, ensures global state consistency, supports flexible expansion of message types without modifying the core code, and realizes a clear unidirectional data flow and loosely coupled interaction architecture.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123123410A_ABST
    Figure CN123123410A_ABST
Patent Text Reader

Abstract

This application relates to the field of application development technology and discloses a message communication method, system, and electronic device. The message communication method is implemented based on a layered architecture, including: a data source layer establishing a communication link through a multi-protocol interface and automatically switching to a backup link to push message data when the link latency exceeds a threshold; a state management layer centrally managing the global state through a single data source and a reducer, driving interface updates; a core processing layer formatting message types through a plugin mechanism; and a user interface interaction layer driving interface rendering by dispatching actions and receiving global states. The technical solution of this application solves the problem in related technologies where chat SDKs struggle to simultaneously address business decoupling, multi-source disaster recovery, state consistency, and type expansion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of application development technology, specifically to a message communication method, system, and electronic device. Background Technology

[0002] In mobile application development, developers typically integrate third-party chat software development kits (SDKs) to implement instant messaging functionality. Most existing chat SDKs employ a single-layer or shallow architecture, coupling message sending and receiving, user interface (UI) rendering, and local state management into the same layer. However, this architecture has the following drawbacks: First, the core logic of the SDK is deeply coupled with specific business logic, resulting in poor reusability; Second, the data source is singular, and messages are easily lost or experience high latency in weak network environments; Third, state management is scattered across various components, making synchronization between components difficult; Fourth, the message types are fixed, and extensions require modifications to the core code.

[0003] In other words, the relevant technologies have technical problems that the SDK cannot simultaneously address business decoupling, multi-source disaster recovery, state consistency, and type expansion. Summary of the Invention

[0004] In view of this, embodiments of this application provide a message communication method, system, and electronic device to solve the technical problem in the related art that SDKs are difficult to balance in terms of business decoupling, multi-source disaster recovery, state consistency, and type expansion.

[0005] In a first aspect, embodiments of this application provide a message communication method. This method is implemented based on a layered architecture, which includes a data source layer, a state management layer, a core processing layer, and a user interface interaction layer. The data source layer is used to manage multiple communication protocols. The method is executed by the data source layer and includes: establishing a first communication link based on a first network transmission protocol through a data source interface encapsulating multiple network transmission protocols; obtaining the response delay of the first communication link through a heartbeat detection mechanism; and when the response delay exceeds a preset delay threshold, establishing a second communication link based on a second network transmission protocol through the data source interface, and pushing message data using the second communication link.

[0006] In one alternative implementation, the first communication link is a WebSocket-based communication link, and the second communication link is an HTTP polling or long polling protocol-based communication link.

[0007] Secondly, embodiments of this application provide a message communication method based on the aforementioned layered architecture. The state management layer is set independently of other layers and is used for centralized management of the global state. This method is executed by the state management layer and includes: establishing a single state data source for centralized storage of global state information; receiving actions dispatched by the user interface layer or the core processing layer, and extracting state change data from the actions, wherein the actions are dispatched by the user interface layer in response to user operations, or by the core processing layer after receiving message data; calculating updated global state information based on the actions and the current global state information in the single state data source using a reducer, and replacing the original state information in the single state data source with the updated global state information, wherein the reducer outputs a new state based on the input actions and the current state; and driving the user interface layer to perform rendering updates based on the updated global state information.

[0008] In one alternative implementation, after receiving an action dispatched by the interface interaction layer or the core processing layer, the method further includes: invoking the application programming interface provided by the core processing layer to enable the core processing layer to perform a message processing operation corresponding to the action.

[0009] Thirdly, this application provides a message communication method based on the above-mentioned layered architecture. The core processing layer is used to perform plug-in processing on message types. The method is executed by the core processing layer and includes: responding to user input information, matching the corresponding message type processor based on the user input information, having the message type processor call the registered message type plugin to format the user input information to obtain message data; and sending the message data to the network server by calling the currently configured data source through the unified data source interface provided by the data source layer.

[0010] In one optional implementation, invoking a registered message type plugin includes: obtaining registered message type plugins, each message type plugin corresponding to a custom message type and containing structure definition information in JavaScript Object Notation (JSON) Schema format; when a registered custom message type is identified based on user input information, invoking the corresponding message type plugin to convert the user input information into message data that conforms to the structure definition information.

[0011] Fourthly, embodiments of this application provide a message communication method. This method is implemented based on the aforementioned layered architecture, wherein the interface interaction layer is used to acquire user input and render and display message data. The method is executed by the interface interaction layer and includes: responding to user operation by dispatching an action to the state management layer, so that the state management layer calls the core processing layer to perform message processing operation; receiving updated global state information broadcast by the state management layer, wherein the updated global state information is calculated by the state management layer based on the action; and rendering and updating the interface according to the updated global state information.

[0012] Fifthly, embodiments of this application provide a message communication system, including: a communication interface; a processor communicatively connected to the communication interface; and a memory communicatively connected to the processor, storing a computer program. When the processor executes the computer program, it is configured to implement: a data source unit, configured to establish a first communication link through the communication interface based on a first network transmission protocol via a data source interface encapsulating multiple network transmission protocols, obtain the response delay of the first communication link through a heartbeat detection mechanism, and establish a second communication link through the communication interface based on a second network transmission protocol when the response delay exceeds a preset delay threshold, and push message data using the second communication link; and, after receiving message data pushed by a network server through the communication interface, to call back and notify a core processing unit; and a state management unit, configured to maintain in the memory... A single-state data source receives actions dispatched by the interface interaction unit or the core processing unit. It calculates updated global state information based on the actions and current global state information using a reducer, replaces the original state information with the updated global state information, and drives the interface interaction unit to render and update based on the updated global state information. The core processing unit is configured to respond to calls from the state management unit, match user input information with corresponding message type processors, and have the message type processors call registered message type plugins for formatting to obtain message data. The message data is then sent to the network server through the unified data source interface provided by the data source unit. The interface interaction unit is configured to respond to user operations by dispatching actions to the state management unit and receiving updated global state information broadcast by the state management unit to render and update the interface.

[0013] Sixthly, embodiments of this application provide an electronic device, including: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the computer instructions to perform the message communication method of any one of the first to fourth aspects described above.

[0014] In a seventh aspect, embodiments of this application provide a computer-readable storage medium storing computer instructions for causing a computer to execute the message communication method of any one of the first to fourth aspects described above.

[0015] The technical solutions provided by the embodiments of this application have the following advantages over the prior art: Firstly, by encapsulating multiple network transmission protocols at the data source layer and combining them with a heartbeat detection mechanism to monitor link quality in real time, the system automatically switches to a backup link to push message data when the quality of the primary link deteriorates. This avoids the problem of message loss or high latency caused by a single data source disconnecting in a weak network environment, which is common in related technologies, and achieves reliable message transmission with multi-channel disaster recovery.

[0016] Secondly, by maintaining a single state data source through the state management layer and centrally processing global state changes with the help of a reducer, the scheme in related technologies where each component separately maintains its own state is replaced. This avoids problems such as asynchronous read states and duplicate message display caused by cross-component state conflicts, and achieves consistency and traceability of the global state.

[0017] Third, by registering and managing message types through plugins in the core processing layer, it is possible to add new custom message types without modifying the core code. Simply register the corresponding message type plugin and define its structure information. This solves the problem of fixed message types and the need to modify the core code for expansion in related technologies, which leads to the coupling between the SDK and business logic. It enables business-independent message types to be extensible.

[0018] Fourth, by triggering the message processing flow through the interface interaction layer by dispatching actions and driving the interface update by receiving global state, the user interaction and message processing logic are decoupled, achieving a clear unidirectional data flow and a loosely coupled interaction architecture. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in the specific embodiments of this application or the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0020] Figure 1 This is a flowchart of a message communication method executed at the data source layer according to an embodiment of this application; Figure 2 This is a flowchart of a message communication method executed at the state management layer according to an embodiment of this application; Figure 3This is a flowchart of a message communication method executed in the core processing layer according to an embodiment of this application; Figure 4 This is a flowchart of a message communication method executed in the interface interaction layer according to an embodiment of this application; Figure 5 This is a schematic diagram illustrating message communication between different layers according to an embodiment of this application; Figure 6 This is a schematic diagram of the hardware structure of an electronic device according to an embodiment of this application. Detailed Implementation

[0021] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0022] It is understood that before using the technical solutions disclosed in the various embodiments of this application, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this application in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.

[0023] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this application, "multiple" means two or more, unless otherwise explicitly specified.

[0024] In related technologies, chat SDKs struggle to simultaneously address business decoupling, multi-source disaster recovery, state consistency, and type expansion. This application provides a message communication method that decouples data source management, state management, message processing, and user interface interaction through a layered architecture to solve the aforementioned technical problems. Specifically, the data source layer addresses message loss in weak network conditions through multi-protocol adaptive switching; the state management layer resolves state conflicts between components through a single data source and a reducer; the core processing layer addresses the need to modify core code for message type expansion through a plugin mechanism; and the user interface interaction layer decouples interaction from logic through an action-receive-state dispatching approach.

[0025] According to an embodiment of this application, a message communication method embodiment is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0026] This embodiment provides a message communication method based on a layered architecture. The layered architecture includes a data source layer, a state management layer, a core processing layer, and a user interface layer. The data source layer manages various communication protocols, and the method is executed by the data source layer. This method can be used on terminal devices such as mobile phones, tablets, and in-vehicle systems. Figure 1 This is a flowchart of a message communication method executed at the data source layer according to an embodiment of this application, such as... Figure 1 As shown, the process includes the following steps: Step S101: Based on the first network transmission protocol, a first communication link is established through a data source interface encapsulated with multiple network transmission protocols.

[0027] Specifically, a layered architecture refers to a software architecture design that divides a message communication system into multiple independent layers according to their responsibilities, with each layer communicating with the others through pre-defined interfaces. In this embodiment, it includes a data source layer, a state management layer, a core processing layer, and a user interface layer. The data source layer is the message transmission layer responsible for managing various network transmission protocols, shielding the upper layers from the implementation details of different protocols through the data source interface. The state management layer is a global state management layer independent of other layers, centrally managing all state information during message communication through a single data source and reducer. The core processing layer is the message logic layer responsible for the pluggable processing of message types, providing corresponding formatting capabilities for different types of messages. The user interface layer is the user interface layer responsible for acquiring user input and rendering and displaying message data, collaborating with other layers by dispatching actions and receiving states.

[0028] The data source interface refers to the unified abstract interface exposed by the data source layer. Internally, it encapsulates connection establishment, disconnection, and message sending / receiving operations for various network transmission protocols such as WebSocket, Hypertext Transfer Protocol (HTTP) polling, and long polling, providing upper-layer modules with a message sending channel independent of specific protocols. The primary network transmission protocol refers to the currently preferred communication protocol, such as WebSocket. The primary communication link refers to the communication connection established between the data source layer and the network server based on the primary network transmission protocol, used for bidirectional transmission of message data.

[0029] In this step, the data source layer initializes the first communication link through the data source interface when the system starts. Subsequent message pushing and receiving will be carried out on this link, and the upper-layer modules do not need to be aware of the underlying protocol details.

[0030] In one possible implementation, during SDK initialization, the data source layer calls the `connect` method of the WebSocket protocol through the data source interface to initiate a WebSocket handshake request and establish a persistent connection with the server. After a successful connection, the server and client can exchange messages at any time through this full-duplex link.

[0031] Step S102: Obtain the response delay of the first communication link through the heartbeat detection mechanism.

[0032] Specifically, the heartbeat detection mechanism refers to a link health monitoring mechanism in which the data source layer sends probe data packets to the server at preset time intervals and waits for a response. Response latency refers to the time from sending the probe data packet to receiving the corresponding response from the server, used to measure the current link's latency level and connectivity.

[0033] In this step, the data source layer continuously monitors the response latency of the first communication link. When the latency is within the normal range, the current link remains unchanged; when the latency continues to exceed the threshold, the link switching process is triggered.

[0034] In one possible implementation, the data source layer sends a Ping heartbeat packet to the server every 10 seconds, and the server immediately replies with a Pong response upon receiving it. The client records the round-trip time of each heartbeat as the response latency. If no response is received after three consecutive heartbeats, the first communication link is considered to have been interrupted.

[0035] Step S103: When the response delay exceeds the preset delay threshold, a second communication link is established through the data source interface based on the second network transmission protocol, and message data is pushed using the second communication link.

[0036] Specifically, the preset delay threshold refers to a pre-set upper limit for response delay, used as a basis for judging whether the current link meets communication quality requirements, such as 500 milliseconds. The second network transmission protocol refers to a backup communication protocol, such as HTTP polling or long polling. The second communication link refers to a backup communication connection established based on the second network transmission protocol.

[0037] In this step, when the quality of the primary link deteriorates, the data source layer automatically establishes a second communication link using the backup protocol encapsulated in the data source interface, switching message sending to the backup link to ensure uninterrupted message transmission.

[0038] In one possible implementation, when the response latency of the WebSocket connection exceeds 500 milliseconds continuously or the heartbeat times out, the data source layer automatically creates an HTTP long polling connection through the data source interface as a second communication link. Messages to be sent in the message sending queue are pushed to the server one by one through this HTTP long polling connection. Simultaneously, the data source layer continuously attempts to rebuild the WebSocket connection in the background using an exponential backoff strategy. Once the WebSocket heartbeat resumes, it immediately switches back to the first communication link to restore real-time communication capabilities.

[0039] The message communication method provided in this embodiment establishes a first communication link based on a data source interface encapsulated with multiple network transmission protocols. It acquires the response latency of the first communication link through a heartbeat detection mechanism, and automatically switches to a second communication link to push message data when the main link response latency exceeds a preset threshold. This avoids the problem of message loss or high latency caused by a single data source disconnecting in a weak network environment, as seen in related technologies, and achieves reliable message transmission with adaptive switching across multiple data sources.

[0040] In some alternative implementations, the first communication link is a WebSocket-based communication link, and the second communication link is an HTTP polling or long polling protocol-based communication link.

[0041] Specifically, the WebSocket protocol is a full-duplex communication protocol based on TCP. After the client and server establish a connection, both parties can actively send data to each other at any time, making it suitable for message push scenarios with high real-time requirements. HTTP polling refers to a communication method where the client sends HTTP requests to the server at fixed time intervals to check for new messages. Long polling refers to a communication method where, after the client sends an HTTP request, the server does not immediately return a response but maintains the connection until there is a new message or a timeout occurs, thus reducing the number of invalid requests compared to HTTP polling.

[0042] By using the WebSocket protocol as the first communication link and HTTP polling or long polling as the second communication link, the full-duplex feature of the WebSocket link is used to maintain real-time message push when the WebSocket link is normal, and the transmission is downgraded to HTTP polling or long polling as a fallback when the WebSocket link is unavailable, thus balancing real-time performance and reliability.

[0043] In one possible implementation, the data source interface registers both WebSocket and HTTP long polling transport protocols during initialization. During normal operation, WebSocket is used to push messages, allowing the server to send real-time updates on order status and dispatch instructions to the client. When a user enters a weak signal area such as an underground parking garage, causing a WebSocket heartbeat timeout, the data source layer automatically switches the message sending mode to HTTP long polling: the client sends a long polling request to the server every 30 seconds. If the server receives a new message within 30 seconds, it returns immediately; otherwise, it returns an empty response. Upon receiving an empty response, the client immediately initiates the next long polling request, thus maintaining continuous message delivery. Once the user leaves the parking garage and the WebSocket heartbeat resumes, the data source layer automatically switches back to the WebSocket connection.

[0044] This embodiment also provides a message communication method based on a layered architecture. The layered architecture includes a data source layer, a state management layer, a core processing layer, and a user interface layer. The state management layer is set up independently of the other layers and is used to centrally manage the global state. The method is executed by the state management layer and can be used in the aforementioned terminals, such as mobile phones, tablets, and in-vehicle systems. Figure 2 This is a flowchart of a message communication method executed at the state management layer according to an embodiment of this application, such as... Figure 2 As shown, the process includes the following steps: Step S201: Establish a single state data source. The single state data source is used to centrally store global state information.

[0045] Specifically, a single state data source refers to a unique global state storage object maintained in memory by the state management layer, where all state information related to message communication is centrally stored. Global state information includes at least a session list, message read flags, user online status, and message sending status.

[0046] In this step, the state management layer creates a state storage instance during initialization as a globally unique state container. All subsequent reading and modification of state information by all modules are done through this instance, avoiding conflicts caused by each component maintaining its own local state.

[0047] In one possible implementation, the single-state data source is created as a JavaScript object during SDK initialization. The initial state includes an empty list of sessions, a default online status, and an empty message queue. When the application starts, the state management layer loads the previous session data and message read flags from the local cache and populates the single-state data source, achieving persistent state recovery.

[0048] Step S202: Receive an action dispatched by the interface interaction layer or the core processing layer, and extract state change data from the action. The action is dispatched by the interface interaction layer in response to the user operation, or by the core processing layer after receiving message data.

[0049] Specifically, an action refers to a state change request sent by the user interface layer or core processing layer to the state management layer. It is a structured object containing action type and payload data. For example, when a user clicks the send button, the user interface layer dispatches an action of type "SEND_MESSAGE" to the state management layer, with the payload being the message text and session ID; when the core processing layer receives a new message from the server, it dispatches an action of type "RECEIVE_MESSAGE" to the state management layer, with the payload being the new message content.

[0050] In this step, the state management layer serves as the sole entry point for state modification. It receives actions from the upper-level modules, parses the state fields that need to be changed and the new data values ​​from the actions, and prepares for subsequent reducer processing.

[0051] In one possible implementation, the user interface layer dispatches actions by calling the dispatch method provided by the state management layer. The transmitted content includes the action type (e.g., "MARK_READ" indicating that the action has been read) and the payload (e.g., {"conversationId": "123", "messageId": "456"}). After receiving the action, the state management layer passes the action type and payload to the reducer for processing.

[0052] Step S203: The reducer calculates the updated global state information based on the action and the current global state information in the single state data source, and replaces the original state information in the single state data source with the updated global state information. The reducer is used to output a new state based on the input action and the current state.

[0053] Specifically, a reducer is a pure function that takes the current state object and action object as input parameters, updates the corresponding fields in the state object according to the action type, and returns a completely new state object without directly modifying the original state object. The reducer ensures the traceability and predictability of state changes; each state update can uniquely determine the new state through the input action and the old state.

[0054] In this step, the state management layer passes the global state information from the current single state data source and the received actions to the reducer. The reducer matches the corresponding state update logic according to the action type, generates a new global state object, and replaces the original state with it.

[0055] In one possible implementation, when the reducer receives an action of type "MARK_READ" with a payload of {"conversationId": "conv_001"}, the reducer iterates through the session list in the current global state, finds the session object with session ID "conv_001", sets its unread message count to zero, and returns a new global state object containing the updated session list. The state management layer assigns the new state object returned by the reducer to the single state data source, completing the state replacement.

[0056] Step S204: The driver interface interaction layer performs rendering updates based on the updated global state information.

[0057] Specifically, after replacing the global state information, the state management layer broadcasts the state update notification to the UI / UX components that have subscribed to the state change via an event bus or the observer pattern. Upon receiving the notification, the UI / UX components re-render the corresponding interface based on the new global state information.

[0058] In this step, the state management layer does not directly manipulate the UI components, but drives UI updates through a publish-subscribe pattern, thus maintaining the decoupling between state management and UI rendering.

[0059] In one possible implementation, after the state management layer completes the state update by performing the "MARK_READ" action, it publishes a "STATE_CHANGED" event via the event bus, carrying the updated global state information. The session list component subscribes to this event, and upon receiving the notification, retrieves the updated session data, re-renders the list, and updates the unread marker for the corresponding session from a red dot to a gray read status.

[0060] In some optional implementations, after receiving the action dispatched by the interface interaction layer or the core processing layer in step S202, the following steps are also included: Step a1: Call the application programming interface provided by the core processing layer so that the core processing layer can perform message processing operations corresponding to the action.

[0061] Specifically, the application programming interface (API) refers to the call entry point exposed by the core processing layer, used to receive message processing instructions from the state management layer, such as the message sending interface, the marked read interface, and the retrieve historical message interface. Message processing operations refer to the message business logic executed by the core processing layer according to the action type, including formatting the message to be sent and submitting it to the data source layer, synchronizing the read status with the server, and retrieving the session history from the server.

[0062] In this embodiment, after the state management layer completes the state update, for actions that require network communication (such as sending a message), it synchronously calls the message processing interface opened by the core processing layer, and hands over the message processing task to the core processing layer for execution, thus realizing the separation of state management and message processing logic.

[0063] In one possible implementation, when the state management layer receives an action of type "SEND_MESSAGE" and completes the state update through the reducer, it calls the sendMessage interface provided by the core processing layer, passing in parameters such as message content, session ID, and message type. The core processing layer matches the corresponding message type plugin according to the message type to format the message content, and then sends the formatted message data to the network server through the unified data source interface provided by the data source layer, completing the end-to-end message transmission.

[0064] This embodiment also provides a message communication method based on a layered architecture, which includes a data source layer, a state management layer, a core processing layer, and a user interface interaction layer. The core processing layer is used for pluggable processing of message types, and the method is executed by the core processing layer. This method can be used with the aforementioned terminals, such as mobile phones, tablets, and in-vehicle systems. Figure 3 This is a flowchart of a message communication method executed in the core processing layer according to an embodiment of this application, such as... Figure 3 As shown, the process includes the following steps: Step S301: In response to user input information, the corresponding message type processor is matched based on the user input information. The message type processor calls the registered message type plugin to format the user input information and obtain message data.

[0065] Specifically, a message type processor refers to a software processing unit in the core processing layer used to process specific categories of messages, corresponding one-to-one with the message type, such as a text message processor, image message processor, location message processor, and custom message processor. A message type plugin refers to a software module registered in the core processing layer as a plugin, used to define and format specific message types. Each plugin contains the structural definition information and serialization logic for that message type. Formatting processing refers to the process of converting raw information input by the user into message data conforming to the network transmission format according to the structural definition of the corresponding message type. Message data refers to structured data obtained after formatting processing, which can be sent to the network server via the data source layer.

[0066] In this step, the core processing layer automatically matches the corresponding message type processor based on the type of user input information. The processor then calls the corresponding registered plugin to complete the formatting, thus achieving dynamic expansion of message types and decoupling from business logic.

[0067] In one possible implementation, the user enters text in the chat interface and clicks send. The interface interaction layer dispatches the user input to the core processing layer. The core processing layer identifies the user input as text and matches it with a text message processor. This processor calls a registered text message plugin to encapsulate the raw text into message data in the format {"type":"text","content":"user-input text","timestamp":"2026-07-24T10:30:00Z"}, thus completing the formatting.

[0068] Step S302: Through the unified data source interface provided by the data source layer, the message data is sent to the network server by calling the currently configured data source.

[0069] Specifically, the unified data source interface refers to the message sending interface exposed by the data source layer to the core processing layer, which is independent of the underlying protocol. When the core processing layer sends messages through this interface, it does not need to know whether WebSocket or HTTP polling protocol is currently being used. The currently configured data source refers to the communication protocol instance that the data source layer automatically selects and activates based on the current network status, such as a WebSocket connection or an HTTP long polling connection.

[0070] In this step, the core processing layer submits the formatted message data to the data source layer through a unified data source interface. The data source layer then selects the appropriate communication protocol based on the current link status to complete the message transmission. The core processing layer does not need to be aware of the underlying link switching process.

[0071] In one possible implementation, after receiving the formatted message data, the core processing layer calls the `send(msgData)` interface provided by the data source layer to pass the message data. Internally, the data source layer determines whether a WebSocket connection is currently active; if so, it pushes the message data to the server in real time via the WebSocket connection. If it has switched to an HTTP long polling connection, it sends the message via an HTTP POST request. Regardless of the underlying protocol used, the core processing layer maintains a consistent calling method.

[0072] In one possible implementation, the invocation of the registered message type plugin in step S301 includes the following steps: Step b1: Obtain the registered message type plugins. Each message type plugin corresponds to a custom message type and contains structure definition information in JSON Schema format.

[0073] Specifically, message type plugins refer to software modules registered in the core processing layer as plugins, used to define and format specific message types. Each plugin corresponds to one message type. Custom message types refer to special message types defined by business users according to their own needs, distinct from basic types such as text and images, such as ride-hailing order cards, location sharing cards, and dispatch notification cards. JSON Schema refers to a descriptive specification for defining JSON data structures. The plugin's structure definition information describes the field names, field types, and required fields included in the message type according to the JSON Schema format.

[0074] In this step, the core processing layer loads all registered message type plugins during system initialization, forming a plugin set to provide a basis for subsequent matching and formatting.

[0075] In one possible implementation, when integrating the SDK, the chauffeur service registers three custom message type plugins via the registerPlugin interface: an order card plugin (fields include order number, status, origin, and destination), a location sharing plugin (fields include latitude and longitude, and address name), and a dispatch notification plugin (fields include driver name, license plate number, and estimated arrival time). The core processing layer stores these plugins in the message type registry for runtime matching and invocation.

[0076] Step b2: When a registered custom message type is identified based on user input information, the corresponding message type plugin is invoked to convert the user input information into message data that conforms to the structure definition.

[0077] In this step, the core processing layer analyzes the message type to which the user input belongs. If a registered custom message type is matched, the corresponding plugin is called to perform formatting and conversion according to the structure definition, generating standardized message data.

[0078] In one possible implementation, the user fills in information such as the origin, destination, and desired vehicle type in the designated driver app and then clicks to place an order. The interface interaction layer packages the user input information and dispatches it to the core processing layer. The core processing layer recognizes that the input corresponds to the registered "order_card" custom message type, calls the order card plugin, and converts the user input into message data in the format {"orderId":"OD20260724001","status":"pending","origin":"Chaoyang Joy City","destination":"Haidian Huangzhuang"} according to its JSON Schema structure definition. This data is then sent to the server by the data source layer.

[0079] In this implementation, through the plugin registration mechanism and JSON Schema structure definition, when adding a new message type, the business side only needs to register the corresponding plugin and define its structure information, without modifying the code of the core processing layer, thus realizing flexible expansion of message types and decoupling of business logic.

[0080] This embodiment also provides a message communication method based on a layered architecture. The layered architecture includes a data source layer, a state management layer, a core processing layer, and a user interface layer. The user interface layer is used to acquire user input and render and display message data. The method is executed by the user interface layer and can be used on the aforementioned terminals, such as mobile phones, tablets, and in-vehicle systems. Figure 4 This is a flowchart of a message communication method executed in the interface interaction layer according to an embodiment of this application, such as... Figure 4 As shown, the process includes the following steps: Step S401: In response to the user operation, an action is dispatched to the state management layer so that the state management layer calls the core processing layer to perform message processing operations.

[0081] Specifically, user actions refer to the interactive behaviors performed by users on the chat interface, such as clicking the send button, swiping to view historical messages, clicking the message bubble to mark it as read, and entering text content. Action dispatch refers to the behavior of the interface interaction layer encapsulating user actions into action objects of a specified format and submitting them to the state management layer. Each action object contains an action type identifier and payload data related to that action.

[0082] In this step, the interface interaction layer serves as the sole entry point for user interaction, transforming all user operations into standardized action objects and dispatching them to the state management layer. It does not directly call the core processing layer or data source layer, thus maintaining the clarity of unidirectional data flow and decoupling between layers.

[0083] In one possible implementation, the user types "I'm on my way" in the chat interface and clicks the send button. The interface interaction layer encapsulates this operation as an action object {"type":"SEND_MESSAGE","payload":{"conversationId":"conv_001","text":"I'm on my way"}}, and dispatches the action through the dispatch interface provided by the state management layer. After receiving the action, the state management layer completes the state update and calls the core processing layer to perform message formatting and sending operations.

[0084] Step S402: Receive the updated global state information broadcast by the state management layer. The updated global state information is calculated by the state management layer based on the action.

[0085] Specifically, broadcasting refers to the behavior of the state management layer notifying all UI components that have subscribed to the state change of the updated state after completing a global state update, via an event bus or callback mechanism. The updated global state information refers to the new global state object generated by the state management layer after processing by the reducer, such as complete state data containing information such as the latest session list, read flags, and message sending status.

[0086] In this step, the UI interaction layer, as a subscriber to state changes, extracts the local data required for rendering this component after receiving the updated global state information broadcast by the state management layer, thus preparing the data source for UI refresh.

[0087] In one possible implementation, after processing the "SEND_MESSAGE" action, the state management layer broadcasts the updated global state information via the event bus. Upon receiving this broadcast, the chat component in the user interface layer extracts the message list of the current session (conv_001) from the global state information and finds a newly added message record with a status of "Sent," containing the message "I'm on my way," and a timestamp of the current time.

[0088] Step S403: Render the updated interface based on the updated global state information.

[0089] Specifically, rendering and updating the interface refers to the process by which the interface interaction layer redraws or partially refreshes the currently displayed interface elements based on the received updated global state information. This includes operations such as adding a message bubble to the bottom of the message list, updating the preview of the last message in the conversation list, updating the message read status icon, and adjusting the message sending status indicator.

[0090] In this step, the interface interaction layer updates the interface in a data-driven manner. All interface changes are triggered by changes in the global state, and there is no direct communication between interface components, thus avoiding display errors caused by inconsistent states.

[0091] In one possible implementation, after the chat interface component receives global status information containing new messages, it dynamically inserts a new message bubble at the bottom of the message list, displaying the message "I'm on my way," with a blue checkmark indicating that the message has been sent. Simultaneously, after the conversation list component receives the same global status information broadcast, it updates the preview of the last message in conversation conv_001 to "I'm on my way" and places that conversation at the top of the list.

[0092] The message communication method provided in this embodiment dispatches actions to the state management layer in response to user operations, receives updated global state information broadcast by the state management layer, and renders and updates the interface based on the updated global state information. This decouples user interaction from message processing logic, eliminating the need for direct communication between interface components. The interface update is driven solely by a single global state, avoiding issues such as duplicate message display and inconsistent read status caused by asynchronous state between components in related technologies. This achieves a clear unidirectional data flow and a loosely coupled interaction architecture.

[0093] Figure 5 This is a schematic diagram illustrating message communication between different layers according to an embodiment of this application. For example... Figure 5 As shown, the message communication between layers in the layered architecture of this application embodiment includes a message sending process and a message receiving process.

[0094] In the message sending process, the UI interaction layer responds to user actions (such as entering text and clicking send), encapsulates the user action as an action object, and dispatches it to the state management layer. After receiving the action, the state management layer calculates the updated global state information based on the current global state information through the reducer, and calls the core processing layer to execute message processing operations. The core processing layer matches the corresponding message type processing unit according to the action content, and the processing unit calls the registered message type plugin to format the user input information and generate message data. The core processing layer submits the message data to the data source layer through the unified data source interface provided by the data source layer. The data source layer pushes the message data to the network server according to the currently configured communication link (such as WebSocket link or HTTP polling link).

[0095] In the message receiving process, after the data source layer receives the message data pushed by the network server through the current communication link, it notifies the core processing layer via callback. The core processing layer dispatches the corresponding receiving action to the state management layer. The state management layer calculates the updated global state information through the reducer, replaces the original state information, and broadcasts the updated global state information through the event bus. After receiving the broadcast, the interface interaction layer renders the updated interface according to the updated global state information, such as adding message bubbles to the message list, updating the session preview, and updating the message read status.

[0096] thus, Figure 5 The layered architecture shown achieves unidirectional data flow and hierarchical decoupling between layers through the division of responsibilities: the interface interaction layer dispatches actions, the state management layer centrally manages the global state, the core processing layer handles message logic, and the data source layer manages communication protocols.

[0097] This embodiment also provides a message communication system, which includes: Communication interface; The processor is connected to the communication interface. Memory, which is connected in communication with the processor, stores computer programs; When a processor executes a computer program, it is configured to implement: The data source unit is configured to establish a first communication link through a communication interface based on a first network transmission protocol and through a data source interface encapsulating multiple network transmission protocols; obtain the response delay of the first communication link through a heartbeat detection mechanism; and establish a second communication link through the communication interface based on a second network transmission protocol when the response delay exceeds a preset delay threshold, and push message data using the second communication link; and after receiving message data pushed by the network server through the communication interface, call back to notify the core processing unit. The state management unit is configured to maintain a single state data source in memory, receive actions dispatched by the interface interaction unit or the core processing unit, calculate updated global state information based on the actions and the current global state information through the reducer, replace the original state information with the updated global state information, and drive the interface interaction unit to perform rendering updates based on the updated global state information. The core processing unit is configured to respond to the call of the state management unit, match the user input information with the corresponding message type processor, and the message type processor calls the registered message type plugin to perform formatting processing to obtain message data, and then sends the message data to the network server through the unified data source interface provided by the data source unit. The interface interaction unit is configured to dispatch actions to the state management unit in response to user operations, and to receive updated global state information broadcast by the state management unit to render the updated interface.

[0098] The message communication system provided in this application can execute the message communication method provided in any embodiment of this application, and has the corresponding functional modules and beneficial effects of the method execution. Further functional descriptions of the above-described units are the same as in the corresponding embodiments described above, and will not be repeated here.

[0099] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0100] The following is a detailed reference. Figure 6This diagram illustrates a suitable structural schematic for implementing the electronic device described in the embodiments of this application. The electronic device may include a processor (e.g., a central processing unit, graphics processor, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from memory 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for the operation of the electronic device. The processor 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0101] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; memory devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.

[0102] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication device 609, or installed from memory 608, or installed from ROM 602. When the computer program is executed by processor 601, it performs the functions defined in the message communication method of embodiments of this application.

[0103] Figure 6 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0104] This application also provides a computer-readable storage medium. The methods described in this application can be implemented in hardware or firmware, or implemented as recordable on a storage medium, or implemented as computer code downloaded over a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the message communication method shown in the above embodiments is implemented.

[0105] A portion of this application can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to this application through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.

[0106] Although embodiments of this application have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of this application, and all such modifications and variations fall within the scope defined by the appended claims.

Claims

1. A message communication method, characterized in that, Implemented using a layered architecture, the layered architecture includes a data source layer, a state management layer, a core processing layer, and a user interface interaction layer. The data source layer manages multiple communication protocols, and the method is executed by the data source layer, including: Based on the first network transmission protocol, a first communication link is established through a data source interface encapsulated with multiple network transmission protocols; The response delay of the first communication link is obtained through a heartbeat detection mechanism; When the response delay exceeds a preset delay threshold, a second communication link is established through the data source interface based on the second network transmission protocol, and message data is pushed using the second communication link.

2. The method according to claim 1, characterized in that, The first communication link is a communication link based on the WebSocket protocol, and the second communication link is a communication link based on the HTTP polling or long polling protocol.

3. A message communication method, characterized in that, Implemented using a layered architecture, the layered architecture includes a data source layer, a state management layer, a core processing layer, and a user interface interaction layer. The state management layer is set up independently of the other layers and is used for centralized management of the global state. The method is executed by the state management layer and includes: Establish a single state data source, which is used to centrally store global state information; Receive actions dispatched by the interface interaction layer or the core processing layer, and extract state change data from the actions, wherein the actions are dispatched by the interface interaction layer in response to user operations, or by the core processing layer after receiving message data. The reducer calculates updated global state information based on the action and the current global state information in the single state data source, and replaces the original state information in the single state data source with the updated global state information. The reducer is used to output a new state based on the input action and the current state. The driver interface interaction layer is rendered and updated based on the updated global state information.

4. The method according to claim 3, characterized in that, After receiving the action dispatched by the interface interaction layer or the core processing layer, the method further includes: The application programming interface provided by the core processing layer is invoked so that the core processing layer performs the message processing operation corresponding to the action.

5. A message communication method, characterized in that, Implemented based on a layered architecture, the layered architecture includes a data source layer, a state management layer, a core processing layer, and a user interface interaction layer. The core processing layer is used for pluggable processing of message types, and the method is executed by the core processing layer, including: In response to user input information, a corresponding message type processor is matched based on the user input information. The message type processor then calls a registered message type plugin to format the user input information and obtain message data. The message data is sent to the network server by calling the currently configured data source through the unified data source interface provided by the data source layer.

6. The method according to claim 5, characterized in that, The invocation of registered message type plugins includes: Retrieve registered message type plugins. Each message type plugin corresponds to a custom message type and contains JSONSchema formatted structure definition information. When a registered custom message type is identified based on the user input information, the corresponding message type plugin is invoked to convert the user input information into message data that conforms to the structure definition information.

7. A message communication method, characterized in that, Implemented using a layered architecture, the layered architecture includes a data source layer, a state management layer, a core processing layer, and a user interface interaction layer. The user interface interaction layer is used to acquire user input and render and display message data. The method is executed by the user interface interaction layer and includes: In response to a user action, an action is dispatched to the state management layer so that the state management layer invokes the core processing layer to perform a message processing operation. Receive updated global state information broadcast by the state management layer, wherein the updated global state information is calculated by the state management layer based on the action; The updated interface is rendered based on the updated global state information.

8. A message communication system, characterized in that, include: Communication interface; The processor is communicatively connected to the communication interface; A memory, communicatively connected to the processor, stores a computer program. When the processor executes the computer program, it is configured to implement: The data source unit is configured to establish a first communication link through the communication interface based on a first network transmission protocol and through a data source interface encapsulating multiple network transmission protocols, obtain the response delay of the first communication link through a heartbeat detection mechanism, and establish a second communication link through the communication interface based on a second network transmission protocol when the response delay exceeds a preset delay threshold, and push message data using the second communication link; And, after receiving message data pushed by the network server through the communication interface, a callback notification is sent to the core processing unit; The state management unit is configured to maintain a single state data source in the memory, receive actions dispatched by the interface interaction unit or the core processing unit, calculate updated global state information through a reducer based on the actions and the current global state information, replace the original state information with the updated global state information, and drive the interface interaction unit to perform rendering updates based on the updated global state information. The core processing unit is configured to respond to the call of the state management unit, match the user input information with the corresponding message type processor, have the message type processor call the registered message type plugin to perform formatting processing to obtain message data, and send the message data to the network server through the unified data source interface provided by the data source unit. The interface interaction unit is configured to dispatch an action to the state management unit in response to a user operation, and to receive updated global state information broadcast by the state management unit to render an updated interface.

9. An electronic device, characterized in that, include: A memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, the processor executing the computer instructions to perform the method of any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing the computer to perform the method of any one of claims 1 to 7.