Public 回调函数 | 事件名 eventName |
---|---|
void | ConnectionStateChanged |
void | TokenExpired |
Public 回调函数 | 事件名 eventName |
---|---|
void | MessageFromUser |
Public 回调函数 | 事件名 eventName |
---|---|
void | RoomMessage |
void | MemberJoined |
void | MemberLeft |
void | MemberCountUpdated |
void | MemberAttributesSet |
void | MemberAttributesDeleted |
void | MemberAttributesCleared |
void | MemberAttributesAddedOrUpdated |
void | RoomAttributesSet |
void | RoomAttributesDeleted |
void | RoomAttributesCleared |
void | RoomAttributesAddedOrUpdated |
void | RoomMemberOffline |
事件 | 描述 |
---|---|
ConnectionStateChanged | 通知 SDK 与 Hummer RTS 系统的连接状态发生了改变。 |
hummer.on('ConnectionStateChanged', (data) => {});
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"ConnectionStateChanged" |
handler | function | 接收回调 |
回调参数:
name | type | description |
---|---|---|
state | enum | 新的连接状态 |
reason | enum | 状态改变的原因 |
enum ConnectionState {
DISCONNECTED = "DISCONNECTED",
CONNECTING = "CONNECTING",
CONNECTED = "CONNECTED",
RECONNECTING = "RECONNECTING",
};
enum ConnectionChangeReason {
INIT = 'INIT',
LOGIN = "LOGIN",
LOGIN_SUCCESS = "LOGIN_SUCCESS",
LOGIN_FAILURE = "LOGIN_FAILURE",
LOGIN_TIMEOUT ="LOGIN_TIMEOUT",
INTERRUPTED ="INTERRUPTED",
LOGOUT = "LOGOUT",
REMOTE_LOGIN = "REMOTE_LOGIN"
};
链接初始状态:{"state":"DISCONNECTED","reason":"INIT"}
(1)登录过程中: 回调通知{"state":"CONNECTING","reason":"LOGIN"};
(2)登录完成: 回调通知{"state":"CONNECTED","reason":"LOGIN_SUCCESS"}
(3)登录失败: 回调通知{"state":"DISCONNECTED","reason":"LOGIN_FAILURE"}
(4)登录超时失败: 回调通知{"state":"DISCONNECTED","reason":"LOGIN_TIMEOUT"}
(5)重连/重登: 回调通知{"state":"RECONNECTING","reason":"INTERRUPTED"};
(6)登录被踢:(账户互踢功能:后端暂不支持web互踢) 回调通知{"state":"DISCONNECTED","reason":"REMOTE_LOGIN"}
hummer.on('TokenExpired', () => {});
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"TokenExpired" |
handler | function | 接收回调 |
回调参数:
name | type | description | |
---|---|---|---|
NA |
断链重连时token过期才会回调通知。
接收对端的点对点消息
client.on('MessageFromUser', (data) => { console.log(data); });
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"MessageFromUser" |
handler | function | 接收回调 |
回调参数:
name | type | description |
---|---|---|
message | Message | 消息对象。 |
fromUid | string | 发送者的uid |
Message定义:
name | type | description |
---|---|---|
type | number | 消息内容类型 |
data | Uint8Array | 消息内容 |
appExtras | {[k: string]: string} | 可选参数。 用户自定义的数据。 键和值为string的json-object。 |
interface Message {
message: {
type: string;
data: Uint8Array;
appExtras?: ({ [k: string]: string }|null);
},
fromUid: string;
}
接收指定房间的消息
room.on('RoomMessage', (data) => { console.log(data); })
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"RoomMessage" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
message | Message | 房间消息对象 |
fromUid | string | 发送者的uid |
Message定义:
name | type | description |
---|---|---|
type | number | 消息内容类型 |
data | Uint8Array | 消息内容 |
appExtras | { [k: string]: string } | 可选参数。 用户自定义的数据。 键和值为string的json-object。 |
interface RoomMessage {
message: {
type: string;
data: Uint8Array;
appExtras?: ({ [k: string]: string }|null);
},
fromUid: string;
}
接收加入房间的用户列表通知。
room.on('MemberJoined', (data) => { console.log(data); })
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"MemberJoined" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义见data定义 |
data定义:
name | type | description |
---|---|---|
uids | string[] | UID数组 |
{"uid":["555"]}
接收退出房间的用户列表通知。
room.on('MemberLeft', (data) => { console.log(data); })
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"MemberLeft" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
uids | string[] | UID数组 |
参考示例:
{"uid":["135666911222"]}
接收退出房间的用户列表通知。
room.on('RoomMemberOffline', () => {})
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"RoomMemberOffline" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
NA |
接收到该房间设置用户某些属性Notify回调通知。
room.on('MemberAttributesSet', (data) => { console.log(data); })
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"MemberAttributesSet" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义见data定义 |
data定义:
name | type | description |
---|---|---|
uid | string | UID |
attributes | object | 用户属性 |
参考示例:
{"uid":"123","attributes":{"Name":"阿武","Description":"js_sdk测试","Bulletin":"bull","Extention":"ex"}}
接收到该房间删除用户某些属性Notify回调通知
room.on('MemberAttributesDeleted', (data) => { console.log(data); });
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"MemberAttributesDeleted" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义后面描述 |
Message定义:
name | type | description |
---|---|---|
uid | string | UID |
attributes | {[k:string]: string} | 用户属性 |
Typescript定义参考:
{"uid":"999888","attributes":{"room_role_name":"student"}}
接收到该房间清除用户某些属性Notify回调通知
room.on('MemberAttributesCleared', (data) => { console.log(data); });
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"MemberAttributesCleared" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义后面描述 |
Message定义:
name | type | description |
---|---|---|
uid | string | UID |
attributes | {[k:string]: string} | 用户属性 |
Typescript定义参考:
{"uid":"999888","attributes":{"room_role_name":"student"}}
接收到添加或更新用户某些属性Notify回调通知
room.on('MemberAttributesAddedOrUpdated', (data) => { console.log(data); });
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"MemberAttributesAddedOrUpdated" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义将data定义描述 |
data定义:
name | type | description |
---|---|---|
uid | string | UID |
attributes | {[k:string]: string} | 用户属性 |
参考示例:
{"uid":"999888","attributes":{"Name":"awu","room_role_name":"student"}}
接收设置房间属性Notify的回调通知。
room.on('RoomAttributesSet', (data) => { console.log(data); })
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"RoomAttributesSet" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义将data定义描述 |
data定义:
name | type | description |
---|---|---|
lastUpdateUid | string | 最近一次变更房间属性的用户UID |
attributes | {[k:string]: string} | 房间属性 |
参考示例:
{"lastUpdateUid":"999888","attributes":{"Name":"awu","Bulletin":"bull","Extention":"ex","room_name":"nginx大讲堂"}}
接收到该房间删除用户某些属性Notify回调通知
room.on('RoomAttributesDeleted', (data) => { console.log(data); });
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"RoomAttributesDeleted" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义将data定义描述 |
data定义:
name | type | description |
---|---|---|
lastUpdateUid | string | 最近一次变更房间属性的用户UID |
attributes | {[k:string]: string} | 房间属性 |
接收到该房间清除用户某些属性Notify回调通知
room.on('RoomAttributesCleared', (data) => { console.log(data); });
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"RoomAttributesCleared" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义将data定义描述 |
data定义:
name | type | description |
---|---|---|
lastUpdateUid | string | 最近一次变更房间属性的用户UID |
attributes | {[k:string]: string} | 房间属性 |
参考示例:
{"lastUpdateUid":"999888","attributes":{"room_name":"nginx大讲堂"}}
接收到添加或更新房间某些属性Notify回调通知
room.on('RoomAttributesAddedOrUpdated', (data) => { console.log(data); });
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"RoomAttributesAddedOrUpdated" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义将data定义描述 |
data定义:
name | type | description |
---|---|---|
lastUpdateUid | string | 最近一次变更房间属性的用户UID |
attributes | {[k:string]: string} | 房间属性 |
参考示例:
{"lastUpdateUid":"999888","attributes":{"room_name":"nginx大讲堂","owner":"awu"}}
接收到添加或更新房间某些属性Notify回调通知
room.on('MemberCountUpdated', (data) => { console.log(data); });
回调通知:
name | type | description |
---|---|---|
eventName | string | 取值"MemberCountUpdated" |
handler | function | 接收回调 |
handler回调参数:
name | type | description |
---|---|---|
object | 详细定义将data定义描述 |
data定义:
name | type | description |
---|---|---|
count | number | 房间内用户数 |
参考示例:
{"count":1}