Events: retransmit
This article will teach you how to retransmit events and why you need it.
Contents
What is event retransmission
Each action in a Voximplant conversation is represented by events. This includes sending, receiving, and editing messages; adding and removing participants, changing user permissions and conversation preferences, and much more.
When a user is logged in to the conversation, the user tracks these events via event listeners. But when a user is logged off, the user cannot track any events.
That is why, when you log a user into a conversation, you need to retransmit events to update previous messages and other conversation changes.
How to retransmit events
In WebSDK, use the retransmitEvents method to retransmit up to 100 previous events.
In the iOS SDK, use the following methods to retransmit events:
In the Android SDK, use the following methods as well:
Please refer to the given API reference links to learn more about these methods.
Here is a code example of how to retransmit events in Web, iOS and Android SDKs:
The retransmitEvents method requires two parameters: to and count.
The to parameter's value equals the conversation's lastSequence property, and the count parameter's value is an integer that represents the number of events.
How to use the local cache
Using the cache functions in SDK allows developers to load the application state at the moment of logging off and does not update the conversations to the actual state.
Before you load the recent activity, such as recent messages and and chat room updates, when you open your application, you may want to show the previous messages from the time when you last closed the application.
To do so, you may use the cache functionality in our Web SDK.
When you log off or close the application, use the toCache method to save the existing messages to the application cache.
When you open the application, you can show the conversation state at the moment of logging off by using the createConversationFromCache method.
Please note, that restoring the conversation from cache does not load the recent messages that were sent when the user was online. You still need to load the recent activity via retransmitting the events to show what happened when the user has been offline.
Download our demos
Here you can download our instant messaging demos for multiple platforms for your instance: