Receiving Messages
Setting Up a Message Listener
- Set up a message listener. All received messages will be returned in this callback method.
- It is recommended to register the message listener within the application lifecycle.
- Multiple listeners are not supported. To avoid memory leaks, set the listener to null when it is no longer needed.
Method
setOnMessageReceivedListener(listener?: (message: RCIMIWMessage, left: number, offline: boolean, hasPackage: boolean) => void): void;
Parameter Description
Parameter | Type | Description |
---|---|---|
message | RCIMIWMessage | The received message object |
left | number | When the client successfully connects, the server will send all compensation messages to the client in the form of a message package, with a maximum of 200 messages per package. After receiving the message package, the client will parse it one by one and notify the application. left indicates the number of remaining messages in the current message package (Package) |
offline | boolean | Whether the message is an offline message |
hasPackage | boolean | Whether there are still undelivered message packages on the server |
Code Example
engine?.setOnMessageReceivedListener((message: RCIMIWMessage, left: number, offline: boolean, hasPackage: boolean) => {
//...
});
Notes
-
Notes on receiving messages:
-
When receiving offline messages, the server will bundle 200 messages into a package and send it to the client, which will then parse this package.
-
hasPackage
indicates whether there are remaining message packages, andleft
indicates how many messages are left after the package is parsed and sent to the App layer one by one.
-
-
How to determine if offline messages have been fully received:
-
hasPackage
is false andleft
is 0. -
hasPackage
being false indicates that the last package (200 messages) is being received, andleft
being 0 indicates that the last message in the last package has also been received.
-