Public Static Function | Method Signature |
---|---|
void | init(uint32_t appId, const String& appVer, HummerEventHandler* handler) |
char* | getSDKVersion() |
RequestId | login(UserId userId, const String& region, const String& token) |
RequestId | logout() |
State | getState() |
UserId | getUserId() |
RequestId | refreshToken(const String& token) |
bool | setLoggerFilePath(const String& path) |
bool | setLogLevel(HMRLogLevel level |
bool | setLogCallback(HummerLogCallback* callback) |
bool | uploadLogsManually(const String& remark) |
Public Member Function | Method Signature |
---|---|
RequestId | addEventHandler(PeerEventHandler* handler) |
RequestId | removeEventHandler(PeerEventHandler* handler) |
RequestId | sendMessage(UserId userId, const Message& message, const MessagingOptions& options = MessagingOptions()) |
RequestId | queryUserOnlineStatus(UserId userIds[], int count) |
void init(uint32_t appId,
const String& appVer,
HummerEventHandler* handler)
Initialize a Hummer SDK
Notes:
- Unless otherwise specified, all Hummer API functions are called asynchronously, and the API is called in the same thread.
- The initial API must be called in the main thread.
Parameter | Description |
---|---|
appId | appid for distinguishing services |
appVer | Application version for data statistics and fault locating |
handler | Event listener |
const char* getSDKVersion()
Get SDK version information.
RequestId login(UserId userId,
const String& region,
const String& token)
Switch to the context of a specific user. This method is executed after a user logs in for upper-layer services.
Parameter | Description |
---|---|
userId | User ID |
region | Region configuration parameters for enabling user context |
token | A token for initializing services |
RequestId logout()
Log out an SDK.
Notes:
- This operation must be executed before a user deregisters (logs out of) with a service.
State getState()
Get the SDK current status. See details in hmr::State.
SDK current status
RequestId refreshToken(const String& token)
Refresh a user token.
Parameter | Description |
---|---|
token | A user token to be refreshed |
bool setLoggerFilePath(const String& path)
Set a log saving path. The caller should ensure that the path is valid.
Parameter | Description |
---|---|
path | Set the global default directory of the log root path |
bool setLogLevel(hmr::HMRLogLevel level)
Set log output level
Parameter | Description |
---|---|
level | Log level,See details in HMRLogLevel |
bool setLogCallback(HummerLogCallback* callback)
Set log output callback
Parameter | Description |
---|---|
callback | Log output callback,see details in HummerLogCallback |
bool uploadLogsManually(const String& remark)
Report logs manually.
Parameter | Description |
---|---|
remark | Remarks |
RequestId addEventHandler(PeerEventHandler* handler)
Add listeners for signaling messages.
Notes:
- A listener mode for adding listeners for member events
- Based on the principle that listener applicants release the listeners, properly manage listener release after applying for one.
- When releasing listeners, call removeEventHandler to remove the SDK listener reference.
Parameter | Description |
---|---|
handler | Listener to be added |
RequestId removeEventHandler(PeerEventHandler* handler)
Remove listeners for signaling messages.
Parameter | Description |
---|---|
handler | Listener to be removed |
RequestId sendMessage(UserId userId,
const Message& message,
const MessagingOptions& options = MessagingOptions())
Send P2P signaling messages.
Parameter | Description |
---|---|
userId | ID of a signaling message receiver |
message | Signaling messages to be sent |
options | Configuration for sending the message |
RequestId queryUserOnlineStatus(UserId userIds[], int count)
Batch search of online users can search the status of a specific user.
Parameter | Description |
---|---|
userIds | Search of a list of online users' IDs |
count | Number of user lists |
RequestId sendMessage(const RoomId& roomId,
const Message& message,
const MessagingOptions& options = MessagingOptions())
Send room messages.
Parameter | Description |
---|---|
roomId | Room ID for target operations |
message | Message |
options | Configuration for sending the message |
RequestId addMemberEventHandler(MemberEventHandler* handler)
Add listeners for Member.
Notes:
- A listener mode for adding listeners for member events.
- Based on the principle that listener applicants release the listeners, properly manage listener release after applying for one.
- When releasing listeners, call removeMemberEventHandler to remove the SDK listener reference.
Parameter | Description |
---|---|
handler | Listener to be added |
RequestId removeMemberEventHandler(MemberEventHandler* handler)
Remove listeners for Member.
Parameter | Description |
---|---|
handler | Listener to be removed |
RequestId addRoomEventHandler(RoomEventHandler* handler)
Add listeners for room events.
Notes:
- A listener mode for adding listeners for member events.
- Based on the principle that listener applicants release the listeners, properly manage listener release after applying for one.
- When releasing listeners, call removeRoomEventHandler to remove the SDK listener reference.
Parameter | Description |
---|---|
handler | Listener to be added |
RequestId removeRoomEventHandler(RoomEventHandler* handler)
Remove listeners for room events.
Parameter | Description |
---|---|
handler | Listener to be removed |
RequestId joinRoom(const RoomId& roomId,
const Dictionary& extras,
const RoomJoinningOptions& options = RoomJoinningOptions())
APIs for joining a room.
Parameter | Description |
---|---|
RoomId | Room: the room ID can contain only letters and digits selected from '[A,Z],[a,z],[0,9],-,_', with 64 bytes at maximum.[][][] |
extras | Extension information for joining a room |
options | Optional parameters for joining a room. See details in RoomJoiningOptions. |
RequestId leaveRoom(const RoomId& roomId)
APIs for exiting a room.
Parameter | Description |
---|---|
roomId | Room ID for target operations. See details in RoomId. |
RequestId setMemberAttributes(const RoomId& roomId,
UserId userId, const Dictionary& attributes,
const MemberAttributeOptions& options = MemberAttributeOptions())
Set user profiles in the current room.
Notes:
- Set user information in the current room.
- You can only set your own profiles at present.
- Size of a user's profile can be up to 8 KB. 32 profiles are supported at maximum.
Parameter | Description |
---|---|
roomId | Room ID for target operations |
userId | Room member |
attributes | Information |
options | Options, see details in MemberAttributeOptions |
RequestId addOrUpdateMemberAttributes(const RoomId& roomId,
UserId userId,
const Dictionary& attributes,
const MemberAttributeOptions& options = MemberAttributeOptions())
Add or update user profiles in the current room.
Notes:
- Update while there are profiles; otherwise, add profiles.
- You can only set your own profiles at present.
- Size of a user's profile can be up to 8 KB. 32 profiles are supported at maximum.
Parameter | Description |
---|---|
roomId | Room ID for target operations |
userId | Room member |
attributes | Information |
options | Options, see details in MemberAttributeOptions |
RequestId deleteMemberAttributes(const RoomId& roomId,
UserId userId, const String keys[],
int numberOfKeys,
const MemberAttributeOptions& options = MemberAttributeOptions())
Delete specific user profiles in the current room.
Notes:
- Return success if some user profiles are deleted while some user profiles do not exist.
- You can only set your own profiles at present.
Parameter | Description |
---|---|
roomId | Room ID |
userId | Room member |
keys | Set of attribute keys |
numberOfKeys | Size of profile key set |
options | Options, see details in MemberAttributeOptions |
RequestId clearMemberAttributes(const RoomId& roomId,
UserId userId,
const MemberAttributeOptions& options = MemberAttributeOptions())
Clear all user profiles in the room.
Notes:
- Return success if no profiles are set for the specific user.
- You can only set your own profiles at present.
Parameter | Description |
---|---|
roomId | Room ID |
userId | Room member |
options | Options, see details in MemberAttributeOptions |
RequestId queryMemberAttributes(const RoomId& roomId, UserId userId)
Search all user profiles in the current room.
Notes:
- Return success if no profiles are set for a user. The result is empty.
Parameter | Description |
---|---|
roomId | Room ID for target operations |
userId | User ID |
RequestId queryMemberAttributesByKeys(const RoomId& roomId,
UserId userId,
const String keys[],
int numberOfKeys)
Search specific user profiles in the current room.
Notes:
- Return success if the searched profiles does not exist, but the returned result is empty.
- If some profiles exist, return success only for existing profiles with these profiles being the result.
Parameter | Description |
---|---|
roomId | Room ID for target operations |
userId | User ID |
keys | Profile keys |
numberOfKeys | Size of profile key set |
RequestId setRoomAttributes(const RoomId& roomId,
const Dictionary& attributes,
const RoomAttributeOptions& options = RoomAttributeOptions())
Set room profiles (full configuration of room profiles is supported for joining and exiting a room).
Notes:
- Clear room profiles when this room keeps empty for 10 minutes.
- Size of each profile can be up to 8 KB.
- Each room contains 32 profiles at maximum.
Parameter | Description |
---|---|
roomId | Room ID for target operations |
attributes | Profiles |
options | Options, see details in MemberAttributeOptions |
RequestId addOrUpdateRoomAttributes(const RoomId& roomId,
const Dictionary& attributes,
const RoomAttributeOptions& options = RoomAttributeOptions())
Update profiles of specific rooms.
Notes:
- Update while profiles exist.
- Add while no profiles exist.
Parameter | Description |
---|---|
roomId | Room ID |
attributes | Profiles |
options | Options, see details in MemberAttributeOptions |
RequestId deleteRoomAttributes(const RoomId& roomId,
const String keys[],
int numberOfKeys,
const RoomAttributeOptions& options = RoomAttributeOptions())
Delete specific attributes of specific rooms
Parameter | Description |
---|---|
roomId | Room ID |
keys | Profile keys |
keys | Size of profile key set |
options | Options, see details in MemberAttributeOptions |
RequestId clearRoomAttributes(const RoomId& roomId, const RoomAttributeOptions& options = RoomAttributeOptions())
Clear profiles of specific rooms.
Notes:
- Clear room profiles when this room keeps empty for 10 minutes.
Parameter | Description |
---|---|
roomId | Room ID |
options | Options, see details in MemberAttributeOptions |
RequestId queryRoomAttributes(const RoomId& roomId)
Search all profiles of specific rooms.
Parameter | Description |
---|---|
roomId | Room ID |
RequestId queryRoomAttributesByKeys(const RoomId& roomId, const String keys[], int numberOfKeys)
Search specific profiles of specific rooms.
Parameter | Description |
---|---|
roomId | Room ID |
keys | Profile keys |
numberOfKeys | Number of profiles |
RequestId queryMemberCounts(const String& roomRegion,
const String roomIds[],
int numberOfIds)
Batch search of the number of room members.
Notes:
- Support concurrent search of 20 rooms at maximum.
Parameter | Description |
---|---|
roomRegion | Room region |
roomIds | Room list |
numberOfIds | Number of rooms |
RequestId queryMembers(const RoomId& roomId)
Search a list of room members.
Notes:
- When over 500 members have joined a room, 500 randomly selected members are returned.
Parameter | Description |
---|---|
roomId | Room ID |
/**
* SDK current status
*/
enum State {
/** Disconnected */
HMR_DISCONNECTED = 0,
/** Connecting */
HMR_CONNECTING = 1,
/** Re-connecting */
HMR_RECONNECTING = 2,
/** Connected */
HMR_CONNECTED = 3,
};
typedef uint64_t RequestId
/**
* String data structure
*
* Corresponding to the std::string data structure of c++. To avoid the STL version
* conflict, dedicated encapsulation is provided.
*/
struct StringImpl;
struct HMR_API String {
public:
String();
String(const char* ansiString);
String(const char* rawBytes, int size);
String(const String& cpy);
~String();
String& operator=(const String& rhs);
const char* c_str() const;
const char* operator()() const;
bool operator==(const String& _Right) const;
bool operator<(const String& _Right) const;
int size() const;
private:
StringImpl* impl;
};
/**
* Binary data item for Key-Value string
*
* Corresponding to the std::pair<std::string, std::string> data structure of c++. To avoid the STL version
* conflict, dedicated encapsulation is provided.
*/
struct KVItem {
const char* key;
const char* value;
};
/**
* Data structure of string dictionary
*
* Data structure corresponding to the std::map<std::string, std::string> of c++. To avoid the STL version
* conflict, dedicated encapsulation is provided.
*/
class DictionaryImpl;
struct HMR_API Dictionary {
public:
Dictionary();
Dictionary(const Dictionary& cpy);
Dictionary& operator = (const Dictionary& rhs);
~Dictionary();
/**
* Add KV data items
*
* @param key Index name of header data
* @param value Header data value
*/
void add(const char* key, const char* value);
/**
* Remove KV data items based on the value of key.
*
* @param Index name of header data
*/
void remove(const char* key);
/**
* Get the total quantity of data items
*/
int count() const;
/**
* Position data item, which is used for enumerating data when the value of key is unknown.
*/
const KVItem* itemAt(int position) const;
/**
* Query the header value based on the header data key
*
* @param key Index name of header data
*/
const char* valueFor(const char* key) const;
bool operator == (const Dictionary& rhs) const;
private:
DictionaryImpl* impl;
};
// Return code encapsulation.
struct Code {
HMRCode code;
String desc;
};
enum HMRLogLevel
{
HMR_LOG_LEVEL_TRACE = 0,
HMR_LOG_LEVEL_DEBUG = 1,
HMR_LOG_LEVEL_INFO = 2,
HMR_LOG_LEVEL_WARNING = 3,
HMR_LOG_LEVEL_ERROR = 4
};
class HummerLogCallback
{
public:
/**
* @brief Log output callback日
* @param [IN] level Level of the log to be output
* @param [IN] msg Log to be output
*/
virtual void onHummerLogWithLevel(HMRLogLevel level, const String& msg) = 0;
public:
virtual ~HummerLogCallback() {}
};
/**
* Message body
*/
struct Message {
String type;
String content;
Dictionary extras;
};
/**
* Message configuration information
*/
struct MessagingOptions {
};
/**
* Room body
* Uniquely identify a room with the room ID and room region.
*/
struct RoomId {
public:
RoomId();
RoomId(const String& id);
RoomId(const String& id, const String& region);
String getId() const;
void setId(const String& id);
String getRegion() const;
void setRegion(const String& region);
bool operator<(const RoomId& lhs) const;
String toString() const;
private:
String id;
String region;
};
struct RoomAttributeOptions
{
bool enableNotification = false; //Broadcasting is disabled by default
};
struct MemberAttributeOptions
{
bool enableNotification = false; //Broadcasting is disabled by default
};