Skip to main content

Receive Messages

Set Up Message Listener

  1. Set up a message receiver listener. All received messages will be called back in this interface 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

Function(RCIMIWMessage? message, int? left, bool? offline, bool? hasPackage)? onMessageReceived;

Parameter Description

Parameter NameParameter TypeDescription
messageRCIMIWMessageThe received message object
leftintWhen the client successfully connects, the server sends all compensation messages to the client in packages, with a maximum of 200 messages per package. After receiving the package, the client parses it and notifies the app one by one. left indicates the number of remaining messages in the current package.
offlineboolWhether the message is an offline message
hasPackageboolWhether there are still undelivered message packages on the server

Code Example

engine?.onMessageReceived = (RCIMIWMessage? message, int? left, bool? offline, bool? hasPackage) {
//...
};

Notes

  • Receiving Messages:

    1. For offline messages, the server packages 200 messages into a single package and sends it to the client. The client then parses this package.

    2. hasPackage indicates whether there are remaining message packages, and left indicates how many messages are left after parsing and delivering them to the app layer.

  • How to Determine When Offline Messages Are 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 final package has been received.