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:
channelizeCall.chsocket.on(eventName, function (res) {
});
Event Names:
- connected
- disconnected
- reconnected
- user.friends_added
- user.friends_removed
- user.blocked
- user.unblocked
- user.call_invite_received
- user.call_joined
- user.call_rejected
- user.call_deleted
- member.invited
- member.invite_received
- member.joined
- member.rejected
- member.removed
- ended
Invoke when the JavaScript SDK establishes a successful connection with the Channelize.io server.
channelizeCall.chsocket.on('connected', function () {
});
Disconnected
Invoke when the JavaScript SDK disconnects from the Channelize.io server.
channelizeCall.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.
channelizeCall.chsocket.on('reconnected', function () {
});
Friend Added
Invoke when two users become friends. This event will update both the users.
channelizeCall.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.
channelizeCall.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.
User Blocked
Invoke when a user blocks another user. This event will update both the users.
channelizeCall.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.
channelizeCall.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.
Call Invite Received
Invoke when a user invites you to a call.
channelizeCall.chsocket.on('user.call_invite_received', function (res) {
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.user
The user who has invited you.timestamp
Specifies the timestamp of the action.
User Joined a Call
Invoke when you joins a call.
channelizeCall.chsocket.on('user.call_joined', function (res) {
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.timestamp
Specifies the timestamp of the action.
User Rejected a Call
Invoke when you rejects a call.
channelizeCall.chsocket.on('user.call_rejected', function (res) {
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.timestamp
Specifies the timestamp of the action.
Deleted Call
Invoke when you delete a call.
channelizeCall.chsocket.on('user.call_deleted', function (res) {
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.timestamp
Specifies the timestamp of the action.
Member Invited
Invoke when a new member is invited to the call.
channelizeCall.Call.getCall(callId, function (err, call) {
if (err) return console.error(err);
call.on('member.invited', (res) => {
});
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.members
The array which includes the newly invited members.user
The user who has invited these members.timestamp
Specifies the timestamp of the action.
Member Invite Received
Invoke when a invite has been received on a user's end you invited to the call.
channelizeCall.Call.getCall(callId, function (err, call) {
if (err) return console.error(err);
call.on('member.invite_received', (res) => {
});
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.user
The user who has received the invite.busy
Indicates if user is busy.timestamp
Specifies the timestamp of the action.
Member Joined
Invoke when a new member is added to the call.
channelizeCall.Call.getCall(callId, function (err, call) {
if (err) return console.error(err);
call.on('member.joined', (res) => {
});
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.members
The array which includes the newly added members.timestamp
Specifies the timestamp of the action.
Member Rejected
Invoke when an invited member rejects the call.
channelizeCall.Call.getCall(callId, function (err, call) {
if (err) return console.error(err);
call.on('member.rejected', (res) => {
});
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.members
The array which includes the members who rejected the call.timestamp
Specifies the timestamp of the action.
Member Removed
Invoke when a member is removed from the call.
channelizeCall.Call.getCall(callId, function (err, call) {
if (err) return console.error(err);
call.on('member.removed', (res) => {
});
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.members
The array which includes the removed members.user
The user who has removed the members.timestamp
Specifies the timestamp of the action.
Call Ended
Invoke when a call is ended.
channelizeCall.Call.getCall(callId, function (err, call) {
if (err) return console.error(err);
call.on('ended', (res) => {
});
});
Callback Params
res will be the response object having following keys:
call
The call object in which action is performed.user
The user who has ended the call.timestamp
Specifies the timestamp of the action.
Unsubscribe Events
You can unsubscribe events with the below code.
channelizeCall.Call.getCall(callId, function (err, call) {
if (err) return console.error(err);
call.off(event);
});
event
is the event name you want to unsubscribe and it can have values - member.invited
, member.invite_received
, member.joined
, member.rejected
, member.removed
, ended
. If you do not pass event, It will unsubscribe all these events.
Channelize.io Calls SDK use these events to update call model's data in real time. If you unsubscribe an event, It may affect the real time updation of model's data.