接口列表

  • hummer.on

Public 回调函数事件名 eventName
voidConnectionStateChanged
voidTokenExpired
  • RtsClient.on

Public 回调函数事件名 eventName
voidMessageFromUser
  • RtsRoom.on

Public 回调函数事件名 eventName
voidRoomMessage
voidMemberJoined
voidMemberLeft
voidMemberCountUpdated
voidMemberAttributesSet
voidMemberAttributesDeleted
voidMemberAttributesCleared
voidMemberAttributesAddedOrUpdated
voidRoomAttributesSet
voidRoomAttributesDeleted
voidRoomAttributesCleared
voidRoomAttributesAddedOrUpdated
voidRoomMemberOffline

回调详细说明

hummer.on

接收连接状态变更的回调通知(hummer.on('ConnectionStateChanged', (data) => {}))

事件描述
ConnectionStateChanged通知 SDK 与 Hummer RTS 系统的连接状态发生了改变。
hummer.on('ConnectionStateChanged', (data) => {});

回调通知:

nametypedescription
eventNamestring取值"ConnectionStateChanged"
handlerfunction接收回调

回调参数:

nametypedescription
stateenum新的连接状态
reasonenum状态改变的原因
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"}

接收Token过期的回调通知(hummer.on('TokenExpired', () => {}))

hummer.on('TokenExpired', () => {});

回调通知:

nametypedescription
eventNamestring取值"TokenExpired"
handlerfunction接收回调

回调参数:

nametypedescription
NA

断链重连时token过期才会回调通知。

RtsClient.on

接收对端消息(client.on('MessageFromUser', (data) => {}))

接收对端的点对点消息

client.on('MessageFromUser', (data) => { console.log(data); });

回调通知:

nametypedescription
eventNamestring取值"MessageFromUser"
handlerfunction接收回调

回调参数:

nametypedescription
messageMessage消息对象。
fromUidstring发送者的uid

Message定义:

nametypedescription
typenumber消息内容类型
dataUint8Array消息内容
appExtras{[k: string]: string}可选参数。 用户自定义的数据。 键和值为string的json-object。
interface Message {
    message: {
        type: string;
        data: Uint8Array;
        appExtras?: ({ [k: string]: string }|null);
    },
    fromUid: string;
}

RtsRoom.on

room接收组播消息(room.on('RoomMessage', (data) => {}))

接收指定房间的消息

room.on('RoomMessage', (data) => { console.log(data); })

回调通知:

nametypedescription
eventNamestring取值"RoomMessage"
handlerfunction接收回调

handler回调参数:

nametypedescription
messageMessage房间消息对象
fromUidstring发送者的uid

Message定义:

nametypedescription
typenumber消息内容类型
dataUint8Array消息内容
appExtras{ [k: string]: string }可选参数。 用户自定义的数据。 键和值为string的json-object。
interface RoomMessage {
    message: {
        type: string;
        data: Uint8Array;
        appExtras?: ({ [k: string]: string }|null);
    },
    fromUid: string;
}
room接收到加入房间Notify回调(room.on('MemberJoined', (data) => {}))

接收加入房间的用户列表通知。

room.on('MemberJoined', (data) => { console.log(data); })

回调通知:

nametypedescription
eventNamestring取值"MemberJoined"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义见data定义

data定义:

nametypedescription
uidsstring[]UID数组
{"uid":["555"]}
room接收到退出房间Notify回调(room.on('MemberLeft', (data) => {}))

接收退出房间的用户列表通知。

room.on('MemberLeft', (data) => { console.log(data); })

回调通知:

nametypedescription
eventNamestring取值"MemberLeft"
handlerfunction接收回调

handler回调参数:

nametypedescription
uidsstring[]UID数组

参考示例:

{"uid":["135666911222"]}
room接收当前用户断线超时离开房间回调(room.on('RoomMemberOffline', () => {}))

接收退出房间的用户列表通知。

room.on('RoomMemberOffline', () => {})

回调通知:

nametypedescription
eventNamestring取值"RoomMemberOffline"
handlerfunction接收回调

handler回调参数:

nametypedescription
NA
room接收设置用户属性Notify的回调(room.on('MemberAttributesSet', (data) => {}))

接收到该房间设置用户某些属性Notify回调通知。

room.on('MemberAttributesSet', (data) => { console.log(data); })

回调通知:

nametypedescription
eventNamestring取值"MemberAttributesSet"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义见data定义

data定义:

nametypedescription
uidstringUID
attributesobject用户属性

参考示例:

{"uid":"123","attributes":{"Name":"阿武","Description":"js_sdk测试","Bulletin":"bull","Extention":"ex"}}
room接收到删除用户某些属性Notify回调(room.on('MemberAttributesDeleted', (data) => {}))

接收到该房间删除用户某些属性Notify回调通知

room.on('MemberAttributesDeleted', (data) => { console.log(data); });

回调通知:

nametypedescription
eventNamestring取值"MemberAttributesDeleted"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义后面描述

Message定义:

nametypedescription
uidstringUID
attributes{[k:string]: string}用户属性

Typescript定义参考:

{"uid":"999888","attributes":{"room_role_name":"student"}}
room接收到清除用户某些属性Notify回调(room.on('MemberAttributesCleared', (data) => {}))

接收到该房间清除用户某些属性Notify回调通知

room.on('MemberAttributesCleared', (data) => { console.log(data); });

回调通知:

nametypedescription
eventNamestring取值"MemberAttributesCleared"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义后面描述

Message定义:

nametypedescription
uidstringUID
attributes{[k:string]: string}用户属性

Typescript定义参考:

{"uid":"999888","attributes":{"room_role_name":"student"}}
room接收到添加或更新用户某些属性Notify回调(room.on('MemberAttributesAddedOrUpdated', (data) => {}))

接收到添加或更新用户某些属性Notify回调通知

room.on('MemberAttributesAddedOrUpdated', (data) => { console.log(data); });

回调通知:

nametypedescription
eventNamestring取值"MemberAttributesAddedOrUpdated"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义将data定义描述

data定义:

nametypedescription
uidstringUID
attributes{[k:string]: string}用户属性

参考示例:

{"uid":"999888","attributes":{"Name":"awu","room_role_name":"student"}}
room接收设置房间属性Notify的回调(room.on('RoomAttributesSet', (data) => {}))

接收设置房间属性Notify的回调通知。

room.on('RoomAttributesSet', (data) => { console.log(data); })

回调通知:

nametypedescription
eventNamestring取值"RoomAttributesSet"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义将data定义描述

data定义:

nametypedescription
lastUpdateUidstring最近一次变更房间属性的用户UID
attributes{[k:string]: string}房间属性

参考示例:

{"lastUpdateUid":"999888","attributes":{"Name":"awu","Bulletin":"bull","Extention":"ex","room_name":"nginx大讲堂"}}
room接收到删除房间某些属性Notify回调(room.on('RoomAttributesDeleted', (data) => {}))

接收到该房间删除用户某些属性Notify回调通知

room.on('RoomAttributesDeleted', (data) => { console.log(data); });

回调通知:

nametypedescription
eventNamestring取值"RoomAttributesDeleted"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义将data定义描述

data定义:

nametypedescription
lastUpdateUidstring最近一次变更房间属性的用户UID
attributes{[k:string]: string}房间属性
room接收到清除房间某些属性Notify回调(room.on('RoomAttributesCleared', (data) => {}))

接收到该房间清除用户某些属性Notify回调通知

room.on('RoomAttributesCleared', (data) => { console.log(data); });

回调通知:

nametypedescription
eventNamestring取值"RoomAttributesCleared"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义将data定义描述

data定义:

nametypedescription
lastUpdateUidstring最近一次变更房间属性的用户UID
attributes{[k:string]: string}房间属性

参考示例:

{"lastUpdateUid":"999888","attributes":{"room_name":"nginx大讲堂"}}
room接收到添加或更新房间某些属性Notify回调(room.on('RoomAttributesAddedOrUpdated', (data) => {}))

接收到添加或更新房间某些属性Notify回调通知

room.on('RoomAttributesAddedOrUpdated', (data) => { console.log(data); });

回调通知:

nametypedescription
eventNamestring取值"RoomAttributesAddedOrUpdated"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义将data定义描述

data定义:

nametypedescription
lastUpdateUidstring最近一次变更房间属性的用户UID
attributes{[k:string]: string}房间属性

参考示例:

{"lastUpdateUid":"999888","attributes":{"room_name":"nginx大讲堂","owner":"awu"}}
room接收到房间用户数变更Notify回调(room.on('MemberCountUpdated', (data) => {}))

接收到添加或更新房间某些属性Notify回调通知

room.on('MemberCountUpdated', (data) => { console.log(data); });

回调通知:

nametypedescription
eventNamestring取值"MemberCountUpdated"
handlerfunction接收回调

handler回调参数:

nametypedescription
object详细定义将data定义描述

data定义:

nametypedescription
countnumber房间内用户数

参考示例:

{"count":1}

文档是否有解决您的问题?

有帮助 没帮助
提交成功,非常感谢您的反馈!

反馈

TOP
<