Functional APIs

API List

  • Hummer

FunctionFunction Name
ObjectcreateHummer
Promise<>login
Promise<>logout
Promise<>refreshToken
stringVERSION
voidsetLogLevel
  • RtsClient

FunctionFunction Name
ObjectcreatRTSInstance
Promise<>sendMessageToUser
voidMessageFromUser
Promise<>queryUsersOnlineStatus
  • RtsRoom

FunctionFunction Name
ObjectcreateRoom
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
  • Auxiliary Tools

FunctionFunction Name
ObjectgetInstanceInfo
Utf8ArrayencodeStringToUtf8Bytes
stringdecodeUtf8BytesToString

Details

Create a Hummer Instance

VERSION

Get the SDK version of Hummer.

    const version = Hummer.VERSION;

createHummer

Create the Hummer instance.

    hummer = Hummer.createHummer({ appid });

Input Parameter

NameTypeDescription
appidnumberProject AppID

appid of the uploaded project. The value is a 32-bit number.

setLogLevel

Set a log level.

hummer.setLogLevel(level);

Request parameter

NameTypeDescription
levelenumLog level
Enumeration ValueMeaning
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
}

getState

Get the SDK current status.

hummer.getState();
Enumeration ValueMeaning
DISCONNECTEDDisconnected
CONNECTINGConnecting
RECONNECTINGReconnecting
CONNECTEDConnected

login

Log in

hummer.login({ region, uid, token });

Request parameter

NameTypeDescription
region?stringUser region
uidstringUser 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?stringOptional dynamic key

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Three token modes are supported: appid, token, and temporary token.

logout

Log Out

hummer.logout();

Request parameter

NameTypeDescription
NA

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

refreshToken

Update the current token

hummer.refreshToken({ token });

Request parameter

NameTypeDescription
tokenstringDynamic key

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

createRTSInstance

Create an RtsService instance.

client = hummer.createRTSInstance();

Process P2P Messages

sendMessageToUser

Send P2P messages.

client.sendMessageToUser({});

Request parameter

NameTypeDescription
typestringContent type specified by the user
contextUint8ArrayMessage content
receiverstringReceiver user ID
appExtras{ [k: string]: string }Optional parameter. Custom data. json-object with string based key and value.

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse 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"}
queryUsersOnlineStatus

Batch search list of online users.

client.queryUsersOnlineStatus({ uids: uids })

Request parameter

NameTypeDescription
uidsstring[]List of user IDs to be searched

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse 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}}

Process Room Messages

createRoom

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

NameTypeDescription
regionstringService registration region ("cn"/"ap_southeast"/"ap_south" / "us" / "me_east" / "sa_east")
roomIdstringRoom ID
join

Join a room

room.join();

Request parameter

NameTypeDescription
extra{[k: string]: string}Extendable fields (optional)

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

        let params = {extra};
        room.join(params).then(res => {
          console.log("join res:", res);
        }).catch(err => {
        });
leave

Exit a room.

room.leave();

Request parameter

NameTypeDescription
extra{[k: string]: string}Extendable fields (optional)

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

        let params = {extra};
        room.leave(params).then(res => {
          console.log("leave res:", res);
        }).catch(err => {
        });
sendMessage

Send multicast messages in a room.

room.sendMessage({})

Request parameter

NameTypeDescription
typestringContent type pecified by the user
contextUint8ArrayMessage content
appExtras{ [k: string]: string }Optional parameter. Custom data. Object with string based key and value.

Response data: Promise<>

NameTypeDescription
rescodenumber0: Success
msgstringResponse 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"}
setUserAttributes

Set local user attributes in a room

room.setUserAttributes({})

Request parameter

NameTypeDescription
attributes{[k: string]: string}User attributes
optionsObjectOptions, see details in options

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

    let params = { attributes, options };
    room.setUserAttributes(params).then(res => {
      console.log("setUserAttributes Res: ", res);
    }).catch(err => {
      console.log(err)
    })
deleteUserAttributesByKeys

Delete specific attributes of a local user

room.deleteUserAttributesByKeys({})

Request parameter

NameTypeDescription
attributes{[k: string]: string}User profiles

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

    room.deleteUserAttributesByKeys({ keys }).then(res => {
      console.log("deleteUserAttributesByKeys res: ", res);
    }).catch(err => {
      console.log(err)
    })
addOrUpdateUserAttributes

Add or update local user attributes in a room

room.addOrUpdateUserAttributes({attributes})

Request parameter

NameTypeDescription
attributesstring[]User profile key array
optionsObjectOptions, see details in options

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

    let req = { attributes, options: { enableNotification: true } }
    room.addOrUpdateUserAttributes(req).then(res => {
      console.log("addOrUpdateUserAttributes res:", res);
    }).catch(err => {
      console.log(err)
    })
clearUserAttributes

Clear local user attributes in a room

room.clearUserAttributes({})

Request parameter

NameTypeDescription
optionsObjectOptions, see details in options

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

    let req = {options: { enableNotification: true } }
    room.clearUserAttributes(req).then(res => {
      console.log("clearUserAttributes res: ", res);
    }).catch(err => {
      console.log(err)
    })
getMembers

Get a list of room members

room.getMembers()

Response data: Promise<>

NameTypeDescription
uidsstring[]User List
rescodenumber0: success
msgstringResponse 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}
getUserAttributesByKeys

Get attributes of specific profile names of a specific user in a room

room.getUserAttributesByKeys({})

Request parameter

NameTypeDescription
uidstringUser ID
keysstring[]User profile name keys

Response data: Promise<>

NameTypeDescription
appidnumber
roomIdstring
attributes{[k: string]: string}User profile objects
rescodenumber0: success
msgstringResponse description

Sample Request

    room.getUserAttributesByKeys({ uid, keys }).then(res => {
      console.log("getUserAttributesByKeys res:", res);
    }).catch(err => {
    });
getUserAttributes

Get all attributes of a specific user in a room

room.getUserAttributes({})

Request parameter

NameTypeDescription
uidstringUser ID

Response data: Promise<>

NameTypeDescription
appidnumber
roomIdstring
attributes{[k: string]: string}User profile objects
rescodenumber0: success
msgstringResponse description

Sample Request

    room.getUserAttributes({ uid, keys }).then(res => {
      console.log("getUserAttributes res:", res);
    }).catch(err => {
    });
setRoomAttributes

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

NameTypeDescription
attributes{[k: string]: string}key-value pair of room profiles
optionsObjectOptions, see details in options

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

    let req = { attributes, options: { enableNotification: true } }
    room.setRoomAttributes(req).then(res => {
      console.log("setRoomAttributes res:", res);
    }).catch(err => {
      console.log(err)
    })
deleteRoomAttributesByKeys

Delete specific profiles of a specific room

room.deleteRoomAttributesByKeys({})

Request parameter

NameTypeDescription
keysstring[]Room profile key array
optionsObjectOptions, see details in options

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

   let req = { keys, options: { enableNotification: enableNotification } };
    room.deleteroomAttributesByKeys(req).then(res => {
      console.log("deleteroomAttributesByKeys Res: ", res);
    }).catch(err => {
      console.log(err)
    })
addOrUpdateRoomAttributes

Update room attributes

room.addOrUpdateRoomAttributes({})

Request parameter

NameTypeDescription
attributes{[k: string]: string}key-value pair of room profiles
optionsObjectOptions, see details in options

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

    let params = { attributes , options : {}};
    room.addOrUpdateRoomAttributes(params).then(res => {
      console.log("addOrUpdateRoomAttributes res: ", res);
    }).catch(err => {
      console.log(err)
    })
clearRoomAttributes

Clear attributes of a specific room.

room.clearRoomAttributes({})

Request parameter

NameTypeDescription
optionsObjectOptions, see details in options

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse description

Sample Request

    let req = { options: { enableNotification: true } };
    room.clearRoomAttributes(req).then(res => {
      console.log("clearRoomAttributes res: ", res);
    }).catch(err => {
      console.log(err)
    })
getRoomAttributes

Get all profiles of a specific room

room.getRoomAttributes()

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse 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)
    })
getRoomAttributesByKeys

Get attributes of specific profile names of a room

room.getRoomAttributesByKeys()

Request parameter

NameTypeDescription
keysstring[]Room profile key array

Response data: Promise<>

NameTypeDescription
rescodenumber0: success
msgstringResponse 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)
    })
getRoomMemberCount

Search the number of users in one or multiple rooms in a pre-configured region.

client.getRoomMemberCount({})

Request parameter

NameTypeDescription
region?stringService registration region ("cn"/"ap_southeast"/"ap_south" / "us" / "me_east" / "sa_east")
roomIdsstring[]List of rooms in the same region

Response data: Promise<>

NameTypeDescription
userCount{[roomId: string]: number}
rescodenumber0: success
msgstringResponse 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":""}

Auxiliary Tools

getInstanceInfo

Get an API of an instance to help search the online status of the instance, which facilitates debugging.

Request parameter

NameType
NA

Response data:

NameTypeDescription
appidnumber
uidstringUser ID
instanceIdnumberInstance 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 }

encodeStringToUtf8Bytes

Encode a string to Utf8 Binary

Sample Request

Hummer.Utify.encodeStringToUtf8Bytes(content);

decodeUtf8BytesToString

Dcode a string to Utf8 Binary

Sample Request

Hummer.Utify.decodeUtf8BytesToString(content);

Enumeration

options

Option object

NameTypeDescription
optionsObjectParameter object

Parameters

NameTypeDescription
enableNotificationBooleanWhether to inform

Sample

{
    enableNotification: true //Whether to inform
}

Was this page helpful?

Helpful Not helpful
Submitted! Your feedback would help us improve the website.
Feedback
Top