Function | Function Name |
---|---|
Object | createHummer |
Promise<> | login |
Promise<> | logout |
Promise<> | refreshToken |
string | VERSION |
void | setLogLevel |
Function | Function Name |
---|---|
Object | creatRTSInstance |
Promise<> | sendMessageToUser |
void | MessageFromUser |
Promise<> | queryUsersOnlineStatus |
Function | Function Name |
---|---|
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 |
Function | Function Name |
---|---|
Object | getInstanceInfo |
Utf8Array | encodeStringToUtf8Bytes |
string | decodeUtf8BytesToString |
Get the SDK version of Hummer.
const version = Hummer.VERSION;
Create the Hummer instance.
hummer = Hummer.createHummer({ appid });
Input Parameter
Name | Type | Description |
---|---|---|
appid | number | Project AppID |
appid of the uploaded project. The value is a 32-bit number.
Set a log level.
hummer.setLogLevel(level);
Request parameter
Name | Type | Description |
---|---|---|
level | enum | Log level |
Enumeration Value | Meaning |
---|---|
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
}
Get the SDK current status.
hummer.getState();
Enumeration Value | Meaning |
---|---|
DISCONNECTED | Disconnected |
CONNECTING | Connecting |
RECONNECTING | Reconnecting |
CONNECTED | Connected |
Log in
hummer.login({ region, uid, token });
Request parameter
Name | Type | Description |
---|---|---|
region? | string | User region |
uid | string | User ID Support a 64-bit uid; as the javascript number type does not support 64-bit integer, the SDK use a string to store the uid. |
token? | string | Optional dynamic key |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Three token modes are supported: appid, token, and temporary token.
Log Out
hummer.logout();
Request parameter
Name | Type | Description | |
---|---|---|---|
NA |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Update the current token
hummer.refreshToken({ token });
Request parameter
Name | Type | Description |
---|---|---|
token | string | Dynamic key |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Create an RtsService instance.
client = hummer.createRTSInstance();
Send P2P messages.
client.sendMessageToUser({});
Request parameter
Name | Type | Description |
---|---|---|
type | string | Content type specified by the user |
context | Uint8Array | Message content |
receiver | string | Receiver user ID |
appExtras | { [k: string]: string } | Optional parameter. Custom data. json-object with string based key and value. |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let params = { type, content, receiver }
client.sendMessageToUser(params).then(res => {
console.log("res: " + JSON.stringify(res));
}).catch(err => {
console.log(err)
})
Sample Response
{"rescode":0,"msg":"ok"}
Batch search list of online users.
client.queryUsersOnlineStatus({ uids: uids })
Request parameter
Name | Type | Description |
---|---|---|
uids | string[] | List of user IDs to be searched |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
onlineStatus | {[uid: string]: boolean} | key-value pair of user/online status |
Sample Request
client.queryUsersOnlineStatus({uids: uids}).then(res => {
console.log("res: " + JSON.stringify(res));
}).catch(err => {
console.log(err);
})
Sample Response
{"rescode":0,"msg":"ok","onlineStatus":{"999000":true}}
Create a single room instance.
Note:
Multiple room instances can be created and they can belong to different service registration regions.
room = client.createRoom({ region, roomId })
Request parameter
Name | Type | Description |
---|---|---|
region | string | Service registration region ("cn"/"ap_southeast"/"ap_south" / "us" / "me_east" / "sa_east") |
roomId | string | Room ID |
Join a room
room.join();
Request parameter
Name | Type | Description |
---|---|---|
extra | {[k: string]: string} | Extendable fields (optional) |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let params = {extra};
room.join(params).then(res => {
console.log("join res:", res);
}).catch(err => {
});
Exit a room.
room.leave();
Request parameter
Name | Type | Description |
---|---|---|
extra | {[k: string]: string} | Extendable fields (optional) |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let params = {extra};
room.leave(params).then(res => {
console.log("leave res:", res);
}).catch(err => {
});
Send multicast messages in a room.
room.sendMessage({})
Request parameter
Name | Type | Description |
---|---|---|
type | string | Content type pecified by the user |
context | Uint8Array | Message content |
appExtras | { [k: string]: string } | Optional parameter. Custom data. Object with string based key and value. |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: Success |
msg | string | Response description |
Sample Request
let params = { type, content }
room.sendMessage(params).then(res => {
console.log("res: " + JSON.stringify(res));
}).catch(err => {
console.log(err);
})
Response:
{"rescode":0,"msg":"ok"}
Set local user attributes in a room
room.setUserAttributes({})
Request parameter
Name | Type | Description |
---|---|---|
attributes | {[k: string]: string} | User attributes |
options | Object | Options, see details in options |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let params = { attributes, options };
room.setUserAttributes(params).then(res => {
console.log("setUserAttributes Res: ", res);
}).catch(err => {
console.log(err)
})
Delete specific attributes of a local user
room.deleteUserAttributesByKeys({})
Request parameter
Name | Type | Description |
---|---|---|
attributes | {[k: string]: string} | User profiles |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
room.deleteUserAttributesByKeys({ keys }).then(res => {
console.log("deleteUserAttributesByKeys res: ", res);
}).catch(err => {
console.log(err)
})
Add or update local user attributes in a room
room.addOrUpdateUserAttributes({attributes})
Request parameter
Name | Type | Description |
---|---|---|
attributes | string[] | User profile key array |
options | Object | Options, see details in options |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let req = { attributes, options: { enableNotification: true } }
room.addOrUpdateUserAttributes(req).then(res => {
console.log("addOrUpdateUserAttributes res:", res);
}).catch(err => {
console.log(err)
})
Clear local user attributes in a room
room.clearUserAttributes({})
Request parameter
Name | Type | Description |
---|---|---|
options | Object | Options, see details in options |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let req = {options: { enableNotification: true } }
room.clearUserAttributes(req).then(res => {
console.log("clearUserAttributes res: ", res);
}).catch(err => {
console.log(err)
})
Get a list of room members
room.getMembers()
Response data: Promise<>
Name | Type | Description |
---|---|---|
uids | string[] | User List |
rescode | number | 0: success |
msg | string | Response description |
Sample Request
room.getMembers().then(res => {
console.log("getMembers res:", res);
}).catch(err => {
});
Sample Response
{"appid":1350626568,"roomId":"test_room","uids":["123","555","233333","1356662","3300235422","3300235423","3300235499","3300235888","135666911222"],"rescode":0}
Get attributes of specific profile names of a specific user in a room
room.getUserAttributesByKeys({})
Request parameter
Name | Type | Description |
---|---|---|
uid | string | User ID |
keys | string[] | User profile name keys |
Response data: Promise<>
Name | Type | Description |
---|---|---|
appid | number | |
roomId | string | |
attributes | {[k: string]: string} | User profile objects |
rescode | number | 0: success |
msg | string | Response description |
Sample Request
room.getUserAttributesByKeys({ uid, keys }).then(res => {
console.log("getUserAttributesByKeys res:", res);
}).catch(err => {
});
Get all attributes of a specific user in a room
room.getUserAttributes({})
Request parameter
Name | Type | Description |
---|---|---|
uid | string | User ID |
Response data: Promise<>
Name | Type | Description |
---|---|---|
appid | number | |
roomId | string | |
attributes | {[k: string]: string} | User profile objects |
rescode | number | 0: success |
msg | string | Response description |
Sample Request
room.getUserAttributes({ uid, keys }).then(res => {
console.log("getUserAttributes res:", res);
}).catch(err => {
});
Fully set attributes of a specific room
Note
- You can set profiles for a room without joining it.
- If a room is empty (no member) for several minutes, the profiles of this room will be cleared.
room.setRoomAttributes(req)
Request parameter
Name | Type | Description |
---|---|---|
attributes | {[k: string]: string} | key-value pair of room profiles |
options | Object | Options, see details in options |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let req = { attributes, options: { enableNotification: true } }
room.setRoomAttributes(req).then(res => {
console.log("setRoomAttributes res:", res);
}).catch(err => {
console.log(err)
})
Delete specific profiles of a specific room
room.deleteRoomAttributesByKeys({})
Request parameter
Name | Type | Description |
---|---|---|
keys | string[] | Room profile key array |
options | Object | Options, see details in options |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let req = { keys, options: { enableNotification: enableNotification } };
room.deleteroomAttributesByKeys(req).then(res => {
console.log("deleteroomAttributesByKeys Res: ", res);
}).catch(err => {
console.log(err)
})
Update room attributes
room.addOrUpdateRoomAttributes({})
Request parameter
Name | Type | Description |
---|---|---|
attributes | {[k: string]: string} | key-value pair of room profiles |
options | Object | Options, see details in options |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let params = { attributes , options : {}};
room.addOrUpdateRoomAttributes(params).then(res => {
console.log("addOrUpdateRoomAttributes res: ", res);
}).catch(err => {
console.log(err)
})
Clear attributes of a specific room.
room.clearRoomAttributes({})
Request parameter
Name | Type | Description |
---|---|---|
options | Object | Options, see details in options |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
Sample Request
let req = { options: { enableNotification: true } };
room.clearRoomAttributes(req).then(res => {
console.log("clearRoomAttributes res: ", res);
}).catch(err => {
console.log(err)
})
Get all profiles of a specific room
room.getRoomAttributes()
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
attributes | {[k: string]: string} | key-value pair of room profiles |
Sample Request
room.getRoomAttributes().then(res => {
console.log("getRoomAttributes res: ", res);
}).catch(err => {
console.log(err)
})
Get attributes of specific profile names of a room
room.getRoomAttributesByKeys()
Request parameter
Name | Type | Description |
---|---|---|
keys | string[] | Room profile key array |
Response data: Promise<>
Name | Type | Description |
---|---|---|
rescode | number | 0: success |
msg | string | Response description |
attributes | {[k: string]: string} | key-value pair of room profiles |
Sample Request
room.getRoomAttributesByKeys({ keys }).then(res => {
console.log("getRoomAttributesByKeys res: ", res);
}).catch(err => {
console.log(err)
})
Search the number of users in one or multiple rooms in a pre-configured region.
client.getRoomMemberCount({})
Request parameter
Name | Type | Description |
---|---|---|
region? | string | Service registration region ("cn"/"ap_southeast"/"ap_south" / "us" / "me_east" / "sa_east") |
roomIds | string[] | List of rooms in the same region |
Response data: Promise<>
Name | Type | Description |
---|---|---|
userCount | {[roomId: string]: number} | |
rescode | number | 0: success |
msg | string | Response description |
Sample Request
client.getRoomMemberCount({ region, roomIds }).then(res => {
console.log("res:", res);
}).catch(err => {
});
Response sample:
{"appid":1350626568,"userCount":{"test123":0,"test999":3},"rescode":0,"msg":""}
Get an API of an instance to help search the online status of the instance, which facilitates debugging.
Request parameter
Name | Type |
---|---|
NA |
Response data:
Name | Type | Description |
---|---|---|
appid | number | |
uid | string | User ID |
instanceId | number | Instance ID |
Sample Request
hummer.getInstanceInfo().then(res => {
console.log("res: " + JSON.stringify(res));
}).catch(err => {
console.log(err);
});
Response:
{ "uid": "123", "instanceId": 3114848827, "isAnonymous": false, "appid": 1350626568 }
Encode a string to Utf8 Binary
Sample Request
Hummer.Utify.encodeStringToUtf8Bytes(content);
Dcode a string to Utf8 Binary
Sample Request
Hummer.Utify.decodeUtf8BytesToString(content);
Option object
Name | Type | Description |
---|---|---|
options | Object | Parameter object |
Parameters
Name | Type | Description |
---|---|---|
enableNotification | Boolean | Whether to inform |
Sample
{
enableNotification: true //Whether to inform
}