Receive Messages
Set Up Message Listener
- Set up a message receiver listener. All received messages will be called back in this interface 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
Function(RCIMIWMessage? message, int? left, bool? offline, bool? hasPackage)? onMessageReceived;
Parameter Description
Parameter Name | Parameter Type | Description |
---|---|---|
message | RCIMIWMessage | The received message object |
left | int | When 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. |
offline | bool | Whether the message is an offline message |
hasPackage | bool | Whether there are still undelivered message packages on the server |
Code Example
engine?.onMessageReceived = (RCIMIWMessage? message, int? left, bool? offline, bool? hasPackage) {
//...
};
Notes
-
Receiving Messages:
-
For offline messages, the server packages 200 messages into a single package and sends it to the client. The client then parses this package.
-
hasPackage
indicates whether there are remaining message packages, andleft
indicates how many messages are left after parsing and delivering them to the app layer.
-
-
How to Determine When Offline Messages Are 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 final package has been received.
-