events.connect()

After a successful sign in, the events.connect() method will connect the client to the server's event stream.

Event stream contains entries about new messages, presence changes, read/deliverered recipts, group membership changes etc. The SDK takes care of all these events and applies the changes automatically to the internal data store, as long as the event stream is opened.

The event stream is divided into three phases: offline messages (including history), replaying group membership changes, and new messages.

In order to show the most up-to-date UI with all conversations and messages, a very small amount of offline messages may be received first. This begins with the event messages:offline:start. The stopping point of the offline messages is marked with the event messages:offline:stop.

In order to show an accurate unread message count, you should wait for the conversations:loading:stop event, since the server may still be replaying group membership changes until then.

After that point, message events will come on new messages.

See also a list of Events that the SDK supports.

Definition

client.events.connect():void

Returns

An error will be thrown if the network is offline or user is not logged in. In the case where the network is offline, the connection will be established later when the network is online.

Otherwise, the connection will be established, with a retry period if it does not succeed. The connection will be kept open indefinitely until the user logs out.

Examples

client.events.connect()
console.log('listening to new events');
client.on('messages:offline:stop', function() {
console.log('all offline messages are downloaded!');
});
client.on('conversations:loading:stop', function() {
console.log('all group membership notifications have been received!');
});