Skip to main content

Receiving Messages

Setting Up a Message Listener

  1. Set up a message listener. All received messages will be returned in this callback method.
  2. It is recommended to register the message listener within the application lifecycle.
  3. 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

ParameterTypeDescription
messageRCIMIWMessageThe received message object
leftnumberWhen 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)
offlinebooleanWhether the message is an offline message
hasPackagebooleanWhether 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:

    1. 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.

    2. hasPackage indicates whether there are remaining message packages, and left 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:

    1. hasPackage is false and left is 0.

    2. hasPackage being false indicates that the last package (200 messages) is being received, and left being 0 indicates that the last message in the last package has also been received.