接入侧需要监听处理的事件列表,详细如下:
Members
(static) NEW_INVITATION_RECEIVED
收到新的邀请
Example
let onNewInvitationReceived = function(event) {
console.log('demo | onNewInvitationReceived', `inviteID:${event.data.inviteID} inviter:${event.data.inviter} inviteeList:${event.data.inviteeList} data:${event.data.data}`);
};
tsignaling.on(TSignaling.EVENT.NEW_INVITATION_RECEIVED, onNewInvitationReceived);
(static) INVITEE_ACCEPTED
被邀请人接受了邀请
Example
let onInviteeAccepted = function(event) {
console.log('demo | onInviteeAccepted', `inviteID:${event.data.inviteID} invitee:${event.data.invitee} data:${event.data.data}`);
};
tsignaling.on(TSignaling.EVENT.INVITEE_ACCEPTED, onInviteeAccepted);
(static) INVITEE_REJECTED
被邀请人拒绝了邀请
Example
let onInviteeRejected = function(event) {
console.log('demo | onInviteeRejected', `inviteID:${event.data.inviteID} invitee:${event.data.invitee} data:${event.data.data}`);
};
tsignaling.on(TSignaling.EVENT.INVITEE_REJECTED, onInviteeRejected);
(static) INVITATION_CANCELLED
邀请被发起者取消
Example
let onInvitationCancelled = function(event) {
console.log('demo | onInvitationCancelled', `inviteID:${event.data.inviteID} inviter:${event.data.invitee} data:${event.data.data}`);
};
tsignaling.on(TSignaling.EVENT.INVITATION_CANCELLED, onInvitationCancelled);
(static) INVITATION_TIMEOUT
邀请超时
Example
let onInvitationTimeout = function(event) {
console.log('demo | onInvitationTimeout', `inviteID:${event.data.inviteID} inviteeList:${event.data.inviteeList}`);
};
tsignaling.on(TSignaling.EVENT.INVITATION_TIMEOUT, onInvitationTimeout);
(static) SDK_READY
SDK 进入 ready 状态时触发,接入侧监听此事件,然后可调用 SDK 发送消息等api,使用 SDK 的各项功能
Example
let onSDKReady = function(event) {
tsignaling.sendTextMessage({
to: 'user1',
groupFlag: false,
priority: TSignaling.TYPES.MSG_PRIORITY_NORMAL,
text: 'hello from tsignaling'
});
}
tsignaling.on(TSignaling.EVENT.SDK_READY, onSDKReady);
(static) SDK_NOT_READY
SDK 进入 not ready 状态时触发,此时接入侧将无法使用 SDK 发送消息等功能。
Example
let onSDKNotReady = function(event) {
// 如果想使用发送消息等功能,接入侧需驱动 SDK 进入 ready 状态,重新调用 login 接口即可,如下所示:
// tsignaling.login({userID: 'your userID', userSig: 'your userSig'});
};
tsignaling.on(TSignaling.EVENT.SDK_NOT_READY, onSDKNotReady);
(static) TEXT_MESSAGE_RECEIVED
收到文本消息
Example
let onTextMessageReceived = function(event) {
event.data.forEach(function(message) {
console.log('demo | ' + (message.from || message.nick) + ' : ', message.payload.text);
});
};
tsignaling.on(TSignaling.EVENT.TEXT_MESSAGE_RECEIVED, onTextMessageReceived);
(static) CUSTOM_MESSAGE_RECEIVED
收到自定义消息
Example
let onCustomMessageReceived = function(event) {
console.log('demo | custom message received', event.data);
};
tsignaling.on(TSignaling.EVENT.CUSTOM_MESSAGE_RECEIVED, onCustomMessageReceived);
(static) REMOTE_USER_JOIN
有远端用户进入群
Example
let onRemoteUserJoin = function(event) {
event.data.forEach(function(message) {
console.log('demo | ' + (message.nick || message.payload.userIDList[0]) + ' 来了');
});
};
tsignaling.on(TSignaling.EVENT.REMOTE_USER_JOIN, onRemoteUserJoin);
(static) REMOTE_USER_LEAVE
有远端用户离开群
Example
let onRemoteUserLeave = function(event) {
event.data.forEach(function(message) {
console.log('demo | ' + (message.nick || message.payload.userIDList[0]) + ' 走了');
});
};
tsignaling.on(TSignaling.EVENT.REMOTE_USER_LEAVE, onRemoteUserLeave);
(static) KICKED_OUT
用户被踢下线
Example
let onKickedOut = function(event) {
console.log(event.data.type);
// TSignaling.TYPES.KICKED_OUT_MULT_ACCOUNT(Web端,同一账号,多页面登录被踢)
// TSignaling.TYPES.KICKED_OUT_MULT_DEVICE(同一账号,多端登录被踢)
// TSignaling.TYPES.KICKED_OUT_USERSIG_EXPIRED(签名过期)
};
tsignaling.on(TSignaling.EVENT.KICKED_OUT, onKickedOut);
(static) NET_STATE_CHANGE
网络状态发生改变
Example
let onNetStateChange = function(event) {
// event.data.state 当前网络状态,枚举值及说明如下:
// TSignaling.TYPES.NET_STATE_CONNECTED - 已接入网络
// TSignaling.TYPES.NET_STATE_CONNECTING - 连接中。很可能遇到网络抖动,SDK 在重试。接入侧可根据此状态提示“当前网络不稳定”或“连接中”
// TSignaling.TYPES.NET_STATE_DISCONNECTED - 未接入网络。接入侧可根据此状态提示“当前网络不可用”。SDK 仍会继续重试,若用户网络恢复,SDK 会自动同步消息
};
tsignaling.on(TSignaling.EVENT.NET_STATE_CHANGE, onNetStateChange);