函数 | 函数名 |
---|---|
Object | createHummer |
Promise<> | login |
Promise<> | logout |
Promise<> | refreshToken |
string | VERSION |
void | setLogLevel |
函数 | 函数名 |
---|---|
Object | creatRTSInstance |
Promise<> | sendMessageToUser |
void | MessageFromUser |
Promise<> | queryUsersOnlineStatus |
函数 | 函数名 |
---|---|
Object | createRoom |
Promise<> | join |
Promise<> | leave |
Promise<> | sendMessage |
Promise<> | setUserAttributes |
Promise<> | deleteUserAttributesByKeys |
Promise<> | addOrUpdateUserAttributes |
Promise<> | clearUserAttributes |
Promise<> | getMembers |
Promise<> | getUserAttributesByKeys |
Promise<> | getUserAttributes |
Promise<> | setRoomAttributes |
Promise<> | deleteRoomAttributesByKeys |
Promise<> | addOrUpdateRoomAttributes |
Promise<> | clearRoomAttributes |
Promise<> | getRoomAttributes |
Promise<> | getRoomAttributesByKeys |
Promise<> | getRoomMemberCount |
函数 | 函数名 |
---|---|
Object | getInstanceInfo |
Utf8Array | encodeStringToUtf8Bytes |
string | decodeUtf8BytesToString |
获取Hummer SDK版本号
const version = Hummer.VERSION;
Hummer初始化:创建hummer实例
hummer = Hummer.createHummer({ appid });
入参:
Name | Type | Description |
---|---|---|
appid | number | 项目的appid |
传入项目的appid,32bit number 类型。
设置打印日志级别
hummer.setLogLevel(level);
请求参数:
Name | Type | Description |
---|---|---|
level | enum | 日志等级 |
响应数据:
Name | Type | Description |
---|---|---|
NA | void |
枚举值 | 含义 |
---|---|
DEBUG(-1) | debug |
LOG(0) | log |
INFO(1) | info |
WARN(2) | warn |
ERROR(3) | error |
enum LOGLEVEL {
DEBUG = -1,
LOG = 0,
INFO = 1,
WARN = 2,
ERROR = 3
}
获取SDK当前状态
hummer.getState();
请求参数:
Name | Type | Description |
---|---|---|
NA |
响应数据:
Name | Type | Description |
---|---|---|
enum |
枚举值 | 含义 |
---|---|
DISCONNECTED | 未连接 |
CONNECTING | 连接中 |
RECONNECTING | 重连中 |
CONNECTED | 已连接 |
hummer.login({ region, uid, token });
请求参数:
Name | Type | Description |
---|---|---|
region? | string | 用户归属地region |
uid | string | 用户UID |
token? | string | 可选的动态密钥 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
token支持3种模式:appid模式、token模式、临时token模式
hummer.logout();
请求参数:
Name | Type | Description | |
---|---|---|---|
NA |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
hummer.refreshToken({ token });
请求参数:
Name | Type | Description |
---|---|---|
token | string | 动态密钥 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
初始化: 创建RtsService实例
client = hummer.createRTSInstance();
响应数据:
Name | Type | Description |
---|---|---|
Object | 返回RtsService实例 |
发送点对点的消息
client.sendMessageToUser({});
请求参数:
Name | Type | Description |
---|---|---|
type | string | content的类型。用户自己约定。 |
content | Uint8Array | 消息的内容。 |
receiver | string | 接收者uid |
appExtras | { [k: string]: string } | 可选参数。 用户自定义的数据。 键和值为string的json-object。 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
示例:
let params = { type, content, receiver }
client.sendMessageToUser(params).then(res => {
console.log("res: " + JSON.stringify(res));
}).catch(err => {
console.log(err)
})
响应:
{"rescode":0,"msg":"ok"}
批量查询用户在线列表
client.queryUsersOnlineStatus({ uids: uids })
请求参数:
Name | Type | Description |
---|---|---|
uids | string[] | 要查询的uid列表 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
onlineStatus | {[uid: string]: boolean} | 用户/在线状态键值对 |
示例:
client.queryUsersOnlineStatus({uids: uids}).then(res => {
console.log("res: " + JSON.stringify(res));
}).catch(err => {
console.log(err);
})
响应:
{"rescode":0,"msg":"ok","onlineStatus":{"999000":true}}
创建单个房间实例
room = client.createRoom({ region, roomId })
请求参数:
Name | Type | Description |
---|---|---|
region | string | 业务归属地("cn"/"ap_southeast"/"ap_south" / "us" / "me_east" / "sa_east") |
roomId | string | 房间ID |
响应数据:
Name | Type | Description |
---|---|---|
Object | 返回room实例 |
【注】可以创建多个房间实例,并且可以在不同的业务归属region
room.join();
请求参数:
Name | Type | Description |
---|---|---|
extra | {[k: string]: string} | 可扩展字段(选填字段) |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
let params = {extra};
room.join(params).then(res => {
console.log("join res:", res);
}).catch(err => {
});
请求参数:
Name | Type | Description |
---|---|---|
extra | {[k: string]: string} | 可扩展字段(选填字段) |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
let params = {extra};
room.leave(params).then(res => {
console.log("leave res:", res);
}).catch(err => {
});
room.sendMessage({})
请求参数:
Name | Type | Description |
---|---|---|
type | string | content的类型。用户自己约定。 |
content | Uint8Array | 消息的内容。 |
appExtras | { [k: string]: string } | 可选参数。 用户自定义的数据。 键和值为string的Object。 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
示例:
let params = { type, content }
room.sendMessage(params).then(res => {
console.log("res: " + JSON.stringify(res));
}).catch(err => {
console.log(err);
})
响应:
{"rescode":0,"msg":"ok"}
room.setUserAttributes({})
请求参数:
Name | Type | Description |
---|---|---|
attributes | {[k: string]: string} | 用户属性 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
let params = { attributes };
room.setUserAttributes(params).then(res => {
console.log("setUserAttributes Res: ", res);
}).catch(err => {
console.log(err)
})
room.deleteUserAttributesByKeys({})
请求参数:
Name | Type | Description |
---|---|---|
attributes | {[k: string]: string} | 用户属性 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
room.deleteUserAttributesByKeys({ keys }).then(res => {
console.log("deleteUserAttributesByKeys res: ", res);
}).catch(err => {
console.log(err)
})
room.addOrUpdateUserAttributes({attributes})
请求参数:
Name | Type | Description |
---|---|---|
attributes | string[] | 用户属性key数组 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
let params = { attributes };
room.addOrUpdateUserAttributes(params).then(res => {
console.log("addOrUpdateUserAttributes res:", res);
}).catch(err => {
console.log(err)
})
room.clearUserAttributes()
请求参数:
Name | Type | Description | |
---|---|---|---|
NA |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
room.clearUserAttributes().then(res => {
console.log("clearUserAttributes res: ", res);
}).catch(err => {
console.log(err)
})
room.getMembers()
请求参数:
Name | Type | Description | |
---|---|---|---|
NA | NA |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
uids | string[] | 用户列表 |
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
示例:
room.getMembers().then(res => {
console.log("getMembers res:", res);
}).catch(err => {
});
响应:
{"appid":1350626568,"roomId":"test_room","uids":["123","555","233333","1356662","3300235422","3300235423","3300235499","3300235888","135666911222"],"rescode":0}
room.getUserAttributesByKeys({})
请求参数:
Name | Type | Description |
---|---|---|
uid | string | 用户UID |
keys | string[] | 用户属性名keys |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
appid | number | |
roomId | string | |
attributes | {[k: string]: string} | 用户属性object |
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
示例:
room.getUserAttributesByKeys({ uid, keys }).then(res => {
console.log("getUserAttributesByKeys res:", res);
}).catch(err => {
});
room.getUserAttributes({})
请求参数:
Name | Type | Description |
---|---|---|
uid | string | 用户UID |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
appid | number | |
roomId | string | |
attributes | {[k: string]: string} | 用户属性object |
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
示例:
room.getUserAttributes({ uid, keys }).then(res => {
console.log("getUserAttributes res:", res);
}).catch(err => {
});
room.setRoomAttributes({})
请求参数:
Name | Type | Description |
---|---|---|
attributes | {[k: string]: string} | 房间属性key-value键值对 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
let params = { attributes };
room.setRoomAttributes(params).then(res => {
console.log("setRoomAttributes res:", res);
}).catch(err => {
console.log(err)
})
全量设置某指定房间的属性。
Note
支持进房间和不进房间全量设置房间属性 房间持续大约10分钟无人的时候,清空房间属性
room.deleteRoomAttributesByKeys({})
请求参数:
Name | Type | Description |
---|---|---|
keys | string[] | 房间属性key数组 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
room.deleteroomAttributesByKeys({ keys }).then(res => {
console.log("deleteroomAttributesByKeys Res: ", res);
}).catch(err => {
console.log(err)
})
room.addOrUpdateRoomAttributes({})
请求参数:
Name | Type | Description |
---|---|---|
attributes | {[k: string]: string} | 房间属性key-value键值对 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
let params = { attributes };
room.addOrUpdateRoomAttributes(params).then(res => {
console.log("addOrUpdateRoomAttributes res: ", res);
}).catch(err => {
console.log(err)
})
room.clearRoomAttributes()
请求参数:
Name | Type | Description | |
---|---|---|---|
NA |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
示例:
room.clearRoomAttributes().then(res => {
console.log("clearRoomAttributes res: ", res);
}).catch(err => {
console.log(err)
})
room.getRoomAttributes()
请求参数:
Name | Type | Description | |
---|---|---|---|
NA |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
attributes | {[k: string]: string} | 房间属性key-value键值对 |
示例:
room.getRoomAttributes().then(res => {
console.log("getRoomAttributes res: ", res);
}).catch(err => {
console.log(err)
})
room.getRoomAttributesByKeys()
请求参数:
Name | Type | Description |
---|---|---|
keys | string[] | 房间属性key数组 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0:成功 |
msg | string | 返回描述 |
attributes | {[k: string]: string} | 房间属性key-value键值对 |
示例:
room.getRoomAttributesByKeys({ keys }).then(res => {
console.log("getRoomAttributesByKeys res: ", res);
}).catch(err => {
console.log(err)
})
在预先设定的区域,查询单个或多个房间用户数
client.getRoomMemberCount({})
请求参数:
Name | Type | Description |
---|---|---|
region? | string | 业务归属地("cn"/"ap_southeast"/"ap_south" / "us" / "me_east" / "sa_east") |
roomIds | string[] | 同一区域的房间列表 |
响应数据:Promise<>
Name | Type | Description |
---|---|---|
userCount | {[roomId: string]: number} | |
rescode | number | 0:表示成功 |
msg | string | 返回描述 |
示例:
client.getRoomMemberCount({ region, roomIds }).then(res => {
console.log("res:", res);
}).catch(err => {
});
响应示例:
{"appid":1350626568,"userCount":{"test123":0,"test999":3},"rescode":0,"msg":""}
获取实例信息的API接口,用来辅助排查实例的在线状态信息,方便用于调试。
请求参数:
Name | Type |
---|---|
NA |
响应数据:
Name | Type | Description |
---|---|---|
appid | number | |
uid | string | UID |
instanceId | number | 实例ID |
示例:
hummer.getInstanceInfo().then(res => {
console.log("res: " + JSON.stringify(res));
}).catch(err => {
console.log(err);
});
响应:
{ "uid": "123", "instanceId": 3114848827, "isAnonymous": false, "appid": 1350626568 }
请求参数:
Name | Type | Description |
---|---|---|
string |
响应数据:
Name | Type | Description |
---|---|---|
Utf8Bytes |
示例:
Hummer.Utify.encodeStringToUtf8Bytes(content);
请求参数:
Name | Type | Description | |
---|---|---|---|
Utf8Bytes |
响应数据:
Name | Type | Description | |
---|---|---|---|
string |
示例:
Hummer.Utify.decodeUtf8BytesToString(content);