Event Handler
Channelize JavaScript SDK provides a simple way to notify client applications for real-time events happening across the Application. Achieve this by registering event callback for the events. Whenever an event occurs, the respective callback is executed. You can also add multiple callbacks for an event.
Register a callback for an event like this:
channelize.chsocket.on(eventName, function (res) {
});
- connected
- reconnected
- disconnected
- online
- offline
- friendAdded
- friendRemoved
- userBlocked
- userUnblocked
- userUpdate
- conversationUpdated
- conversationDeleted
- conversationCleared
- userMuteStatusUpdated
- userJoined
- userLeft
- conversationAdminAdded
- typingStatusUpdated
- messageReceived
- messagesDeletedForMe
- messagesDeletedForEveryone
- readMessageToSelf
- readMessageToOwner
Connected
Invoke when the JavaScript SDK establishes a successful connection with the Channelize.io server.
channelize.chsocket.on('connected', function () {
});
Reconnected
Invoke when the JavaScript SDK successfully reconnects to the Channelize.io server.
channelize.chsocket.on('reconnected', function () {
});
Disconnected
Invoke when the JavaScript SDK disconnects from the Channelize.io server.
channelize.chsocket.on('disconnected', function (err) {
});
Callback Params
res
Indicates the error object. This error object can have details about the connection lost.
Online
Invoke when a user appears online.
channelize.chsocket.on('online', function (user) {
});
Callback Params
user
Indicates the user's object.
Offline
Invoke when a user goes offline.
channelize.chsocket.on('offline', function (user) {
});
Callback Params
user
Indicates the user's object.
Friend Added
Invoke when two users become friends. This event will update both the users.
channelize.chsocket.on('friendAdded', function (user) {
});
Callback Params
user
Indicates the user's object.
Friend Removed
Invoke when a user removes someone from its friend or the following list. This event will update both the users.
channelize.chsocket.on('friendRemoved', function (userId) {
});
Callback Params
userId
The unique ID of the user.
User Blocked
Invoke when a user blocks another user. This event will update both the users.
channelize.chsocket.on('userBlocked', function (self, userId) {
});
Callback Params
self
Specifies if the user is blocked by someone or vice-versa. If set to true, the user is blocked by someone. If set to false, the user has blocked someone.userId
The unique ID of the user.
User Unblocked
Invoke when a user unblocks another user. This event will update both the users.
channelize.chsocket.on('userUnblocked', function (self, user) {
});
Callback Params
self
Specifies if the user is unblocked by someone or vice-versa. If set to true, the user is unblocked by someone. If set to false, the user has unblocked someone.user
The unique ID of the user.
User Updated
Invoke when a user's information is updated. This event needs userId as a parameter and you have to register this event callback for every user you want to get the real-time update.
channelize.chsocket.on('userUpdated', userId, function (user) {
});
Function Params
userId
The unique ID of the user.
Callback Params
user
Indicates the user's object.
Conversation Update
Invoke when there is an update in a conversation i.e Title, Profile Image or Members list.
channelize.chsocket.on('conversationUpdated', function (conversation) {
});
Callback Params
conversation
Indicates the conversation's object.
Conversation Deleted
Invoke when a conversation is deleted. This event will update the user who has deleted the conversation.
channelize.chsocket.on('conversationDeleted', function (conversation) {
});
Callback Params
conversation
Indicates the conversation's object.
Conversation Cleared
Invoke when a conversation is cleared. This event will update the user who has cleared the conversation.
channelize.chsocket.on('conversationCleared', function (conversation) {
});
Callback Params
conversation
Indicates the conversation's object.
User Mute Status Updated
Invoke when a user mutes or unmutes a conversation. This event will update the user who has performed this action.
channelize.chsocket.on('userMuteStatusUpdated', function (conversation) {
});
Callback Params
res will be the response object having following keys:
chatId
Specifies the unique conversation ID which has been muted or unmuted.mute
Indicates whether the conversation is currently mute or unmute.userId
The unique ID of the user.
User Joined
Invoke when a user is added to a conversation.
channelize.chsocket.on('userJoined', function (conversation) {
});
Callback Parameters
conversation
Indicates the conversation's object.
User Left
Invoke when a user is removed from a conversation or left a conversation.
channelize.chsocket.on('userLeft', function (conversation) {
});
Callback Params
conversation
Indicates the conversation's object.
Conversation Admin Added
Invoke when a user's status is changed to admin in one of your conversations.
channelize.chsocket.on('conversationAdminAdded', function (res) {
});
Callback Params
res will be the response object having following keys:
chatId
The unique ID of conversation in which action is performed.isAdmin
Determines if the admin status has been added or removed.userId
The unique ID of the user whose status is updated.
Typing Status Updated
Invoke when a user starts or stops typing in a conversation.
channelize.chsocket.on('typingStatusUpdated', function (res) {
});
Callback Params
res will be the response object having following keys:
isTyping
Determines if the user is typing or not.chatId
The unique ID of conversation in which action is performed.userId
Indicates the unique ID of the user who is performing the action.
Message Received
Invoke when you receive a new message.
channelize.chsocket.on('messageReceived', function (message) {
// This method get invoked when a user send or receive a new message.
// So please check that if that message exist into your list then update that message on that particular position
// otherwise add the message into your list.
});
Callback Parameters
message
Indicates the message's object.
Messages Deleted For Me
Invoke when a user deletes his own copy of the message.
channelize.chsocket.on('messagesDeletedForMe', function (message) {
});
Callback Params
message
Indicates the message's object.
Messages Deleted For Everyone
Invoke when a user recalls a sent message. This event will update all the recipients of the message.
channelize.chsocket.on('messagesDeletedForEveryone', function (res) {
});
Callback Params
res will be the response object having following keys:
messageIds
The unique ID of the deleted message.chatId
The unique ID of conversation in which action is performed.
Read Message To Self
Invoke when a user reads the message sent by another user. This event will update the message recipient who read the message.
channelize.chsocket.on('readMessageToSelf', function (res) {
});
Callback Params
res will be the response object having following keys:
chatId
The unique ID of conversation in which action is performed.messageStatus
Specifies the status of the message. It can have values 1, 2 and 3 for sent, delivered and read respectively.userId
The unique ID of the user who marked the message as read.
Read Message To Owner
Invoke when a user reads a message sent by a user. This event will update the message owner.
channelize.chsocket.on('readMessageToOwner', function (res) {
});
Callback Params
res will be the response object having following keys:
chatId
The unique ID of conversation in which action is performed.messageStatus
Specifies the status of the message. It can have values 1, 2 and 3 for sent, delivered and read respectively.userId
The unique ID of the user who marked the message as read.