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) {
});
Event Names:
- connected
- disconnected
- reconnected
- conversation.updated
- conversation.members_added
- conversation.members_removed
- conversation.admin_added
- conversation.admin_removed
- conversation.typing
- conversation.mark_as_read
- user.friends_added
- user.friends_removed
- user.blocked
- user.unblocked
- user.conversation_deleted
- user.conversation_cleared
- user.mute_updated
- user.joined
- user.removed
- user.status_updated
- user.updated
- user.message_created
- user.message_deleted
- user.total_unread_message_count_updated
- message.deleted_for_everyone
- watcher.message.created
- watcher.conversation.start_watching
- watcher.conversation.stop_watching
- watcher.message.deleted_for_everyone
- reaction.added
- reaction.removed
Connected
Invoke when the JavaScript SDK establishes a successful connection with the Channelize.io server.
channelize.chsocket.on('connected', function () {
});
Disconnected
Invoke when the JavaScript SDK disconnects from the Channelize.io server.
channelize.chsocket.on('disconnected', function (err) {
});
Callback Params
err
Indicates the error object. This error object can have details about the connection lost.
Reconnected
Invoke when the JavaScript SDK successfully reconnects to the Channelize.io server.
channelize.chsocket.on('reconnected', function () {
});
Conversation Update
Invoke when there is an update in a conversation i.e Title, Profile Image or Members list.
channelize.chsocket.on('conversation.updated', function (conversation) {
});
Callback Params
conversation
Indicates the conversation's object.
Members Added
Invoke when members are added to a conversation.
channelize.chsocket.on('conversation.members_added', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
The object of the conversation in which action is performed.members
The array which includes the newly added user.timestamp
Specifies the time when new member is added.
Members Removed
Invoke when members are removed from a conversation.
channelize.chsocket.on('conversation.members_removed', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
The object of the conversation in which action is performed.members
The array which includes the newly added user.timestamp
Specifies the time when member is removed.
Conversation Admin Added
Invoke when a user's status is changed to admin in one of your conversations.
channelize.chsocket.on('conversation.admin_added', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
The object of the conversation in which action is performed.adminUser
The object of user added as an admin.timestamp
Specifies the time when member makes an admin.
Conversation Admin Removed
Invoke when a user's status is changed from admin to normal member in one of your conversations.
channelize.chsocket.on('conversation.admin_removed', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
The object of the conversation in which action is performed.adminUser
The object of user removed from the admin role.timestamp
Specifies the time when member removed from the admin role.
Conversation Typing
Invoke when a user starts or stops typing in a conversation.
channelize.chsocket.on('conversation.typing', function (res) {
});
Callback Params
res will be the response object having following keys:
isTyping
Determines if the user is typing or not.conversation
The object of the conversation in which action is performed.user
Indicates the user who is performing the action.timestamp
Specifies the time when user start or stop typing.
Conversation Mark As Read
Invoke when a user reads a message sent by a user. This event will update the message owner.
channelize.chsocket.on('conversation.mark_as_read', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
The conversation object in which action is performed.user
Indicates the user who is performing the action.timestamp
Specifies the time when user read message.
Friend Added
Invoke when two users become friends. This event will update both the users.
channelize.chsocket.on('user.friends_added', function (res) {
});
Callback Params
res will be the response object having following keys:
user
Indicates the user's object.timestamp
Specifies the time when user added as a friend.
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('user.friends_removed', function (res) {
});
Callback Params
res will be the response object having following keys:
user
Indicates the user's object.timestamp
Specifies the time when user removed from friends.
Callback Params
res will be the response object having following keys:
conversation
The conversation in which action is performed.message
Indicates the message's object.timestamp
Specifies the time when user deleted the message.
User Blocked
Invoke when a user blocks another user. This event will update both the users.
channelize.chsocket.on('user.blocked', function (res) {
});
Callback Params
res will be the response object having following keys:
blocker
The user object who takes the block action.blockee
The user object who gets blocked.timestamp
Specifies the time when user blocked.
User Unblocked
Invoke when a user unblocks another user. This event will update both the users.
channelize.chsocket.on('user.unblocked', function (res) {
});
Callback Params
res will be the response object having following keys:
unblocker
The user object who takes the unblock action.unblockee
The user object who gets unblocked.timestamp
Specifies the time when user unblocked.
Conversation Deleted
Invoke when a conversation is deleted. This event will update the user who has deleted the conversation.
channelize.chsocket.on('user.conversation_deleted', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
Indicates the conversation's object.timestamp
Specifies the time when user delete the conversation.
Conversation Cleared
Invoke when a conversation is cleared. This event will update the user who has cleared the conversation.
channelize.chsocket.on('user.conversation_cleared', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
Indicates the conversation's object.timestamp
Specifies the time when user clear the conversation.
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('user.mute_updated', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
Indicates the conversation's object.muteUpdatedUser
Object of muted user.timestamp
Specifies the time when user mute the conversation.
User Joined
Invoke when a user is added to a conversation.
channelize.chsocket.on('user.joined', function (res) {
});
Callback Parameters
res will be the response object having following keys:
conversation
Indicates the conversation's object.timestamp
Specifies the time when user is added to a conversation.
User Removed
Invoke when a user is removed from a conversation or left a conversation.
channelize.chsocket.on('user.removed', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
Indicates the conversation's object.timestamp
Specifies the time when user removed from a conversation.
User Status Updated
Invoke when any user presence status is updated means when a user come online and goes offline.
channelize.chsocket.on('user.updated', function (res) {
});
Callback Params
res will be the response object having following keys:
user
Indicates the user's object.timestamp
Specifies the time when user come online and goes offline.
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('user.updated', function (res) {
});
Callback Params
res will be the response object having following keys:
user
Indicates the user's object.timestamp
Specifies the time when user's information is updated.
Message Received
Invoke when you receive a new message.
channelize.chsocket.on('user.message_created', function (res) {
// 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
res will be the response object having following keys:
message
Indicates the message's object.timestamp
Specifies the time when user receive the message.
Total Unread Message Count Updated
Invoke when a user mark read to any conversation and unread message count is updated.
channelize.chsocket.on('user.total_unread_message_count_updated', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
The conversation in which action is performed.user
Indicates the user's object.timestamp
Specifies the time when unread message count is updated.
Messages Deleted For Me
Invoke when a user deletes his own copy of the message.
channelize.chsocket.on('user.message_deleted', function (res) {
});
Callback Params
res will be the response object having following keys:
message
Indicates the message's object.timestamp
Specifies the time when user deleted the message.
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('message.deleted_for_everyone', function (res) {
});
Callback Params
res will be the response object having following keys:
conversation
The conversation in which action is performed.message
Indicates the message's object.timestamp
Specifies the time when user deleted the message.
Watcher Message Received
Invoke when you receive a new message. This event will update all the users who are watching the conversations.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
// Subscribe the event
conversation.on('watcher.message.created', (res) => {
});
// UnSubscribe the event
conversation.off('watcher.message.created', (res) => {
});
});
Callback Parameters
res will be the response object having following keys:
message
Indicates the message's object.timestamp
Specifies the time when watcher receive the message.
Start Watching
Invoke when a user start watching the conversation. This event will update all the users who are watching the conversations.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
// Subscribe the event
conversation.on('watcher.conversation.start_watching', (res) => {
});
// UnSubscribe the event
conversation.off('watcher.conversation.start_watching', (res) => {
});
});
Callback Params
res will be the response object having following keys:
conversation
The object of the conversation in which action is performed.watchers
The object which has the newly added watcher.timestamp
Specifies the time when watcher start watching the conversation.
Stop Watching
Invoke when a user stops watching the conversation. This event will update all the users who are watching the conversations.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
// Subscribe the event
conversation.on('watcher.conversation.stop_watching', (res) => {
});
// UnSubscribe the event
conversation.off('watcher.conversation.stop_watching', (res) => {
});
});
Callback Params
res will be the response object having following keys:
conversation
The object of the conversation in which action is performed.watchers
The object which has the newly added watcher.timestamp
Specifies the time when watcher stop watching the conversation.
Watcher Messages Deleted For Everyone
Invoke when a user recalls a sent message. This event will update all the users who are watching the conversations.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
// Subscribe the event
conversation.on('watcher.message.deleted_for_everyone', (res) => {
});
// UnSubscribe the event
conversation.off('watcher.message.deleted_for_everyone', (res) => {
});
});
Callback Params
res will be the response object having following keys:
conversation
The conversation in which action is performed.message
Indicates the message's object.timestamp
Specifies the time when user deleted the message.
Add Reaction
Invoke when a user adds a reaction to the message. This event will update all the users who are subscribed to add reaction events.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
conversation.on('reaction.added', (res) => {
});
});
Callback Params
res will be the response object having following keys:
message
Indicates the message's object.reaction
Indicates the reaction's object.user
Indicates the user's object who add reaction.timestamp
Specifies the time when reaction is added.
Remove Reaction
Invoke when a user removes a reaction from the message. This event will update all the users who are subscribed to remove reaction events.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
conversation.on('reaction.removed', (res) => {
});
});
Callback Params
res will be the response object having following keys:
message
Indicates the message's object.reaction
Indicates the reaction's object.user
Indicates the user's object who remove reaction.timestamp
Specifies the time when reaction is removed.