Real Time Updates

How to establish socket connection to get real time updates

Pre-built customizable chat UI

If you're using our pre-built UI you may skip this section.

Build your UI from scratch

Initialize socket connection

In the login script, we're calling ALSocket.init method to initialize the socket connection.

window.Applozic.ALSocket.init(APP_ID, data, events);
APP_ID : This is your applozic App ID. You can find it using
data : object in which you're passing token, device key and websocketurl
                var data = {};
            data.token : token you get in response of login call success
            data.deviceKey = deviceKey you get in response of login call success
            data.websocketUrl = websocketUrl you get in response of login call success
events : Applozic events which you declare before making a login call 
                 (refer installation section for description) 

Typing indicator

Subscribe for typing channel

You need to subscribe to typing channel in order to get real time update about typing status of other user when you're chatting with them personally or on a group.


// subscribeId: userId of logged in user.

Send typing status

Once you have subscribed to typing channel then you need to send typing status on keypress which will show typing status on other end.

window.Applozic.ALSocket.sendTypingStatus(status, previousTypingState, userId, otherUserId);

status: 1 (when user is typing) or 0 (when user has stopped writing)
previousTypingState: 1 or 0 (previous typing state)
userId: userId of user
otherUserId: userId of other user (or groupId)

Disconnect and remove typing indicator

This will remove typing status from you chat once you have unsubscribed to typing channel


Stop notification on desktop site


Send online/offline status of user

// status = 0 OFFLINE 
// status = 1 ONLINE

Reconnect socket

By default we're providing reconnect feature in our chat SDK but in case you want to reconnect socket for some use case then you can call below mentioned method.


What’s Next
Did this page help you?