Functional APIs

API List

  • HMR

Public Static FunctionMethod Signature
StategetState()
voidinit(Context appContext, long appId)
voidopen(long uid, String region, Set tag, String token, HMR.Completion completion)
voidclose(Completion completion)
voidrefreshToken(String token)
voidrefreshToken(String token, HMR.Completion completion)
voidaddStateListener(StateListener listener)
voidremoveStateListener(StateListener listener)
voidaddTokenInvalidListener(TokenInvalidListener listener)
voidremoveTokenInvalidListener(TokenInvalidListener listener)
StringgetVersion()
ServicegetService(Class serviceClass)
  • ChannelStateService

Public Member FunctionMethod Signature
ChannelStategetState
voidaddChannelStateListener(ChannelStateListener listener)
voidremoveChannelStateListener(ChannelStateListener listener)
  • ChatRoomService

Public Member FunctionMethod Signature
voidsetRegion(String region)
voidcreateChatRoom(ChatRoomInfo chatRoomInfo, HMR.CompletionArg completion)
voiddismissChatRoom(ChatRoom chatRoom, HMR.Completion completion)
voidjoin(ChatRoom chatRoom, Map<String, String> joinProps, Challenges.JoiningCompletion completion)
voidleave(ChatRoom chatRoom, HMR.Completion completion)
voidkick(ChatRoom chatRoom, User member, Map<EKickInfo, String> extraInfo, HMR.Completion completion)
voidaddRole(ChatRoom chatRoom, User member, String role, HMR.Completion completion)
voidremoveRole(ChatRoom chatRoom, User member, String role, HMR.Completion completion)
voidfetchMembers(ChatRoom chatRoom, int num, int offset, HMR.CompletionArg<List> completion)
voidfetchRoleMembers(ChatRoom chatRoom, boolean online, HMR.CompletionArg<Map<String, List>> completion)
voidfetchBasicInfo(ChatRoom chatRoom, HMR.CompletionArg completion)
voidfetchChatRoomInfo(ChatRoom chatRoom, HMR.CompletionArg<Map<String, String>> completion)
voidfetchMemberCount(ChatRoom chatRoom, HMR.CompletionArg completion)
voidchangeBasicInfo(ChatRoom chatRoom, Map<ChatRoomInfo.BasicInfoType, String> propInfo, HMR.Completion completion)
voidmuteMember(ChatRoom chatRoom, User member, String reason, HMR.Completion completion)
voidunmuteMember(ChatRoom chatRoom, User member, String reason, HMR.Completion completion)
voidfetchMutedUsers(ChatRoom chatRoom, HMR.CompletionArg<Set> completion)
voidisMuted(ChatRoom chatRoom, User member, HMR.CompletionArg completion);
voidsetUserInfo(ChatRoom chatRoom, Map<String, String> infoMap, HMR.Completion completion)
voiddeleteUserInfoByKeys(ChatRoom chatRoom, Set keys, HMR.Completion completion)
voidaddOrUpdateUserInfo(ChatRoom chatRoom, Map<String, String> infoMap, HMR.Completion completion)
voidfetchUserInfo( ChatRoom chatRoom, User member, HMR.CompletionArg<Map<String, String>> completion)
voidbatchFetchUserInfos(ChatRoom chatRoom, Set users, HMR.CompletionArg<Map<User, Map<String, String>>> completion)
voidfetchOnlineUserInfoList(ChatRoom chatRoom, HMR.CompletionArg<Map<User, Map<String, String>>> completion)
voidaddListener(ChatRoomListener listener)
voidremoveListener(ChatRoomListener listener)
voidaddMemberListener(MemberListener listener)
voidremoveMemberListener(MemberListener listener)
  • ChatService

Public Member FunctionMethod Signature
voidsend(Message message, HMR.Completion completion)
voidaddMessageListener(Identifiable target, MessageListener listener)
voidremoveMessageListener(Identifiable target, MessageListener listener)

API Details

HMR

HMR.getState

public static State getState()

Get the SDK current status. See details in HMR.State.

Return

SDK current status


HMR.init

public static void init(@NonNull final Context appContext, final long appId) 

Initialize Hummer

Notes:

  • Unless otherwise specified, all API functions of Hummer are asynchronously called, and the API is called in the same thread.
Parameters
ParameterDescription
appContextContext
appIdIt is used to identify specific services, and should be artificially applied for from Hummer service providers.

HMR.open

public static void open(final long uid,
                  @NonNull final String region,
                  @Nullable final Set<String> tags,
                  @NonNull final String token,
                  @Nullable final HMR.Completion completion)

Logging in an SDK, and starting to monitor server messages and pull corresponding message data.

Parameters
ParameterDescription
uidUser ID
regionParameters of a region where a server is should be connected. Consult related SDK developers for details.
tagsField reserved, can be left empty temporarily.
tokenA user token is required for service initialization
completionCallback of processing after completion

HMR.close

public static void close(@Nullable final Completion completion)

Log out an SDK

Notes:

  • SDK logout is an asynchronous operation.
  • Errors should be processed in completion callback.
Parameters
ParameterDescription
completionCallback of processing after completion

HMR.refreshToken

public static void refreshToken(@NonNull final String token)

Refresh a user token

Note:

This API is deprecated, use refreshToken(String token, HMR.Completion completion) instread.

Parameters
ParameterDescription
tokenA user token to be refreshed

[New]HMR.refreshToken

public static void refreshToken(@NonNull final String token,
																@Nullable final HMR.Completion completion)

Refresh a user token

Parameters
ParameterDescription
tokenA user token to be refreshed
completionCallback of error codes, which should be handled

HMR.addStateListener

public static void addStateListener(@NonNull final StateListener listener)

Add an SDK state change listener

Parameters
ParameterDescription
listenerA listener to be added. See details in StateListener.

HMR.removeStateListener

public static void removeStateListener(@NonNull final StateListener listener)

Remove an SDK state change listener

Parameters
ParameterDescription
listenerA listener to be removed. See details in StateListener.

HMR.addTokenInvalidListener

public static void addTokenInvalidListener(@NonNull final TokenInvalidListener listener)

Add a token invalid listener

Parameters
ParameterDescription
listenerA listener to be added. See details in TokenInvalidListener.

HMR.removeTokenInvalidListener

public static void removeTokenInvalidListener(@NonNull final TokenInvalidListener listener)

Remove a token invalid listener

Parameters
ParameterDescription
listenerA listener to be removed. See details in TokenInvalidListener.

HMR.getVersion

public static String getVersion()

Get SDK version information

Return
  • SDK version information

HMR.getService

public static <Service> Service getService(@NonNull Class<Service> serviceClass)

Get a service instance

Return

Service instance


HMR.State

public enum State { }

SDK current status

Enumeration ValueDescription
UnavailableAn unavailable status. The SDK is in this status while being not initialized.
OpeningOpening
OpenedOpened
ClosingClosing
ClosedClosed

ChannelStateService

ChannelStateService.getState

public ChannelState getState()

Get a current connection status. See details in ChannelStateService.ChannelState.

Return

Current connection status of SDK


ChannelStateService.addChannelStateListener

public void addChannelStateListener(@NonNull ChannelStateListener listener)

Add a connection state change listener

Parameters
ParameterDescription
listenerA listener to be added. See details in ChannelStateListener.

ChannelStateService.removeChannelStateListener

public void removeChannelStateListener(@NonNull ChannelStateListener listener)

Remove a connection state change listener

Parameters
ParameterDescription
listenerA listener to be removed. See details in ChannelStateListener.

ChatRoomService

ChatRoomService.setRegion

void setRegion(String region);

Set chatroom area.

Note:

  • Call this API before set other chatroom parameters.
  • It is China by default if this API is not configured.
Parameter
ParameterDescription
regionArea

ChatRoomService.createChatRoom

void createChatRoom(@NonNull ChatRoomInfo chatRoomInfo,
                    @NonNull HMR.CompletionArg<ChatRoom> completion);

Create a chatroom

Notes:

  • The chatroom must be created before it can be used, so you need to create a corresponding chatroom API.
  • After a chatroom is created, the server will return a corresponding chatroom ID used for identifying the chatroom in the future.
  • Chatroom information such as name, description, bulletin, and extension information, should be provided during chatroom creation.
Parameters
ParameterDescription
chatRoomInfoChatroom information objects include name, description, bulletin and extension information. See details in ChatRoomInfo.
completionOne CompletionArg object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.dismissChatRoom

void dismissChatRoom(@NonNull ChatRoom chatRoom,
                     @Nullable HMR.Completion completion);

Close a chatroom

Notes:

  • During destruction, you should provide the chatroom's ID so the server can correctly identify and destroy the desired chatroom.
  • Destruction requires Owner permission.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomChatroom ID
completionOne Completion object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.join

void join(@NonNull ChatRoom chatRoom,
          @NonNull Map<String, String> joinProps,
          @NonNull Challenges.JoiningCompletion completion);

Join a chatroom

Notes:

  • You must join a chatroom before you can properly perform operations for that chatroom—for example, sending and receiving public screen or signaling messages.

  • Joining a chatroom follows a logic of “multi-user mutual removal”. For details, consult the background configuration.

  • A single user’s chatroom joining frequency is limited to 10 times per 5 seconds.

Parameters
ParameterDescription
chatRoomChatroom ID
joinPropsAn extension field for service extension. The SDK is only responsible for pass-through.
completionOne JoiningCompletion object
- Calling succeeded: A local user receives callback onSucceed.
- Calling failed: A local user receives callback onFailure. See Code for error codes.

ChatRoomService.leave

void leave(@NonNull ChatRoom chatRoom, @Nullable HMR.Completion completion);

Exit a chatroom

Notes:

  • Once all the necessary logistics for joining the chatroom are processed, you can end interactions with the chatroom by exiting it. Listening to public screen or signaling messages and corresponding callback notifications will also be terminated.
Parameters
ParameterDescription
chatRoomChatroom ID
completionOne Completion object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.kick

void kick(@NonNull ChatRoom chatRoom,
          @NonNull User member,
          @Nullable Map<EKickInfo, String> extraInfo,
          @NonNull HMR.Completion completion);

Remove chatroom users

Notes:

  • Only certain roles (Admin and Owner) can remove chatroom members. Though Admin roles cannot remove other Admin and Owner roles, Owner roles can remove any members in the channel.

  • Also, removed members and members to be removed can have to be removed from within the channel.

  • After successful chatroom member removal, the SDK background does not restrict that member from re-joining; however, the SDK will pass-through to the business server, which can then determine whether to allow re-joining.

  • A single user’s call frequency limit is 10 times per 5 seconds.

Parameter
ParameterDescription
chatRoomChatroom ID
memberRemoved chatroom member
extraInfoSEI on removal. See EKickInfo
for key values. Currently two Key values are supported:
1. Reason, Key bearing the reason for removal, for which only the character string corresponding to the Key’s removal reason needs to be filled into Value;
2. Time, Key bearing the duration of restriction, for which only a character string equal to the duration of restriction in seconds needs to be filled into Value. These are pass-through fields that do not need to be processed by the server.
completionOne Completion object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.addRole

void addRole(@NonNull ChatRoom chatRoom,
             @NonNull User member,
             @NonNull String role,
             @NonNull HMR.Completion completion);

Calling failed: A local user receives callback onFailed.

Notes:

  • Owner roles in the chatroom can add Admin roles to common users, but Admin roles cannot.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomChatroom ID
memberA single user’s call frequency limit is 10 times per 5 seconds.
roleRole type. Currently, only Admin can be filled in. See details in ChatRoomService.Roles.
completionOne Completion object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.removeRole

void removeRole(@NonNull ChatRoom chatRoom,
                @NonNull User member,
                @NonNull String role,
                @NonNull HMR.Completion completion);

Remove a chatroom permission role

Notes:

  • Only a chatroom Owner can remove Admin roles; AdminRole cannot remove the AdminRole role.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomChatroom ID
memberChatroom member of removed role
roleRole type. Currently, only Admin can be filled in. See details in ChatRoomService.Roles.
completionOne Completion object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.fetchMembers

void fetchMembers(@NonNull ChatRoom chatRoom, 
                  int num, 
                  int offset,
                  @NonNull HMR.CompletionArg<List<User>> completion);

Get a chatroom member list

Notes:

  • In some scenarios, a single chatroom may have many thousands of members; therefore, this SDK provides corresponding paged member lists according to your requirements. Meanwhile, a corresponding member list is sorted according to certain default rules.
  • You can use the API for retrieving the member list even without joining the chatroom.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomChatroom ID
numSet the number of members returned on each page (recommended no more than 200)
offsetSpecific page (the first page starts from 0)
completionOne CompletionArg object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.fetchRoleMembers

void fetchRoleMembers(@NonNull ChatRoom chatRoom, 
                      boolean online,
                      @NonNull HMR.CompletionArg<Map<String, List<User>>> completion);

Get a role-added member list for chatroom

Notes:

  • You can get corresponding role lists as needed; the service can display different UI interfaces according to the role lists as well as grant permissions for it.

  • You can obtain a role list before joining the chatroom.

  • A single user’s call frequency limit is 10 times per 5 seconds.

Parameters
ParameterDescription
chatRoomChatroom ID
onlineWhether to only get online users:
true: only get list of online members with roles added
false:get list of all role-added members
completionOne Completion object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed.. See Code for error codes.

ChatRoomService.fetchBasicInfo

void fetchBasicInfo(@NonNull ChatRoom chatRoom,
                    @NonNull HMR.CompletionArg<ChatRoomInfo> completion);

Get chatroom’s basic profile information

Notes:

  • Getting chatroom information includes chatroom name, description, and bulletin, as well as corresponding extended field information.
  • You can obtain chatroom information without joining the chatroom.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomChatroom ID
completionOne CompletionArg object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.fetchChatRoomInfo

void fetchChatRoomInfo(@NonNull ChatRoom chatRoom,
                       @Nullable HMR.CompletionArg<Map<String, String>> completion);

Get all information of a chatroom.

Parameters
ParameterDescription
chatRoomChatroom ID
completionCallback after completion, to which you can perform the corresponding operation

ChatRoomService.fetchMemberCount

void fetchMemberCount(@NonNull ChatRoom chatRoom,
                      @NonNull HMR.CompletionArg<Integer> completion);

Get the total number of members in a chatroom.

Parameters
ParameterDescription
chatRoomChatroom ID
completionCallback after completion

ChatRoomService.changeBasicInfo

void changeBasicInfo(@NonNull ChatRoom chatRoom,
                     @NonNull Map<ChatRoomInfo.BasicInfoType, String> propInfo,
                     @NonNull HMR.Completion completion);

Change chatroom’s basic profile information

Notes:

  • You can change chatroom information for one or more chatrooms according to your needs. Only the key-value pairs to be modified need to be specified in the s.
  • An Admin or Owner role is required to change chatroom information.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomChatroom ID
propInfoA modified profile value. See ChatRoomInfo.BasicInfoType for key enumeration values.
completionOne Completion object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.addOrUpdateChatRoomInfo

void addOrUpdateChatRoomInfo(@NonNull ChatRoom chatRoom,
                             @NonNull Map<String, String> infoMap,
                             @Nullable HMR.Completion completion);

Update the information of a specific chatroom.

Note:

If there is no attribute, you can add one.

Parameters
ParameterDescription
chatRoomChatroom ID
infoMapInformation to be updated, which is customizable
completionCallback after completion, to which you can perform the corresponding operation

ChatRoomService.muteMember

void muteMember(@NonNull ChatRoom chatRoom,
                @NonNull User member,
                @Nullable String reason,
                @NonNull HMR.Completion completion);

Mute chatroom members

Notes:

  • This service can mute a specific member according to your requirement. The default muting time is three days, after which the member will automatically be unmuted.
  • Only an Admin or Owner can enable mute. While an Admin can only mute regular members, an Owner can mute any channel member (including Admin).
  • Members to be muted have to already be in the chatroom.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomChatrooms that a member is in
memberA member to be muted
reasonReason for muting
completionOne Completion object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.unmuteMember

void unmuteMember(@NonNull ChatRoom chatRoom,
                  @NonNull User member,
                  @Nullable String reason,
                  @NonNull HMR.Completion completion);

Unmute chatroom member

Notes:

  • Members to be unmuted have to already be in the chatroom.
  • Only an Admin or Owner role can unmute. An Owner can unmute all channel members (Admin included), whereas Admin can only unmute common members.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomChatrooms that a member is in
memberA member to be unmuted
reasonReason for unmuting
completionOne Completion object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See [Code]( for error codes.

ChatRoomService.fetchMutedUsers

void fetchMutedUsers(@NonNull ChatRoom chatRoom, 
                     @NonNull HMR.CompletionArg<Set<User>> completion);

Get a chatroom mute list

Notes:

  • Some users on the mute list might not be in the chatroom.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomA chatroom requiring a mute list
completionOne CompletionArg object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed.onFailed. See Code for error codes.

ChatRoomService.isMuted

void isMuted(@NonNull ChatRoom chatRoom,
             @NonNull User member,
             @NonNull HMR.CompletionArg<Boolean> completion);

Determine whether a certain user is on a chatroom’s mute list.

Notes:

  • A single user’s call frequency is limited to 10 times every 5 seconds.
Parameters
ParameterDescription
chatRoomChatroom requiring judgment
memberUser requiring judgment
completionOne CompletionArg object
- User requiring judgment
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.setUserInfo

void setUserInfo(@NonNull final ChatRoom chatRoom,
                 @NonNull final Map<String, String> infoMap,
                 @Nullable final HMR.Completion completion);

Set own user information

Notes:

  • Maximum capacity:
    set user profiles, the maximum number of supported attributes: 32
    Maximum value for a single user profile: 8K.
  • A single user’s call frequency limit is 10 times per 5 seconds.
Parameters
ParameterDescription
chatRoomChatroom that a member is in
infoMapUser information to be set
completionOne CompletionArg object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See details in Error Code

ChatRoomService.deleteUserInfoByKeys

void deleteUserInfoByKeys(@NonNull ChatRoom chatRoom,
                          @NonNull Set<String> keys,
                          @Nullable HMR.Completion completion);

Delete you own user information.

Note:

  • No more than 32 attributes are allowed, and the maximum size of each user attribute is 8k.
  • Frequency limit of single user call: 10/5s
Parameters
ParameterDescription
chatRoomChatroom where the member is in
keysInformation to be deleted
completionOne CompletionArg object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See details in Error Code

ChatRoomService.addOrUpdateUserInfo

void addOrUpdateUserInfo(@NonNull ChatRoom chatRoom,
                         @NonNull Map<String, String> infoMap,
                         @Nullable HMR.Completion completion);

Add or update information of a specific user.

Note:

If there is no attribute, you can add one.

Parameter
ParameterDescription
chatRoomChatroom where the member is in
infoMapAttribute
completionCallback after completion

ChatRoomService.fetchUserInfo

void fetchUserInfo(@NonNull ChatRoom chatRoom,
                   @NonNull User member,
                   @NonNull HMR.CompletionArg<Map<String, String>> completion

Get information of a specific user.

Parameters
ParameterDescription
chatRoomChatroom where the member is in
memberTarget member
completionOne CompletionArg object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See details in Error Code


ChatRoomService.batchFetchUserInfos

void batchFetchUserInfos(@NonNull ChatRoom chatRoom,
                         @NonNull Set<User> users,
                         @Nullable HMR.CompletionArg<Map<User, Map<String, String>>> completion);

Get the information of specific users in a batch.

Parameters
ParameterDescription
chatRoomChatroom where the member is in
memberTarget member
completionOne CompletionArg object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See details in Error Code

ChatRoomService.fetchOnlineUserInfoList

void fetchOnlineUserInfoList(@NonNull ChatRoom chatRoom,
                             @NonNull HMR.CompletionArg<Map<User, Map<String, String>>> completion);

Get a chatroom user information list

Notes:

  • A maximum of 100 member lists can be returned; if over 100 lists are called for, 100 random lists are returned.
Parameters
ParameterDescription
chatRoomA chatroom to be searched
completionHandlerOne CompletionArg object
- Calling succeeded: A local user receives callback onSuccess.
- Calling failed: A local user receives callback onFailed. See Code for error codes.

ChatRoomService.addListener

void addListener(@NonNull final ChatRoomListener listener);

Add a chatroom callback listener

Parameters
ParameterDescription
listenerA listener object. See details in ChatRoomListener.

ChatRoomService.removeListener

void removeListener(@NonNull final ChatRoomListener listener);

Remove a chatroom callback listener

Parameters
ParameterDescription
listenerA listener object. See details in ChatRoomListener.

ChatRoomService.addMemberListener

void addMemberListener(@NonNull final MemberListener listener);

Add a chatroom member callback listener

Parameters
ParameterDescription
listenerA listener object. See details in MemberListenerr.

ChatRoomService.removeMemberListener

void removeMemberListener(@NonNull final MemberListener listener);

Remove a chatroom member callback listener

Parameters
ParameterDescription
listenerA listener object. See details in MemberListenerr.

ChatService

ChatService.send

void send(@NonNull Message message, @Nullable HMR.Completion completion);
Note

A message sending API: supports sending a public screen (only supports text), unicast, or broadcast message. See details in Content.

**Notes

  • This service can compose a message body by itself, filling in corresponding content and sending it out.
  • This API also can resend the message in the case that the message sending fails.
  • A single user’s call frequency limit:
    For sending public screen messages: 10 times/5s
    For sending a custom unicast message: 50 times/5s
    For sending a custom broadcast message: 50 times/5s
  • Maximum capacity:
    For a single unicast message: 2K
    For a single broadcast message: 2K
Parameters
ParameterDescription
messageMessage instance
completionCallback of sending operation completion
Callback

There may be multiple stages/statuses in a message sending process, but The completion only conducts final completion callback. Obtain the corresponding callback with MessageListener.

ChatService.addMessageListener

void addMessageListener(@Nullable Identifiable target, @NonNull MessageListener listener);
Notes

Add a message sending/receiving listener.

Parameters
ParameterDescription
targetA message object to be subject to sending/receiving listening
listenerA listener object to be added

ChatService.removeMessageListener

void removeMessageListener(@Nullable Identifiable target, @NonNull MessageListener listener);
Notes

Remove a message sending/receiving listener

Parameters
ParameterDescription
targetA message object to be released from message sending/receiving listening
listenerA listener object to be removed

Parameter Type

HMR

HMR.Completion

public interface Completion {
		// Callback succeeded
    void onSuccess();
		// Callback failed
    void onFailed(Error err);
}

HMR.CompletionArg

Succeeded Calling Back the Result

public interface CompletionArg<Argument> {
  	// Callback succeeded,
    void onSuccess(Argument arg);
		// Callback failed
    void onFailed(Error err);
}

ChannelStateService

ChannelStateService.ChannelState

enum ChannelState {
    Unavailable,
    Disconnected,
    Connecting,
    Connected,
}
Enumeration ValueDescription
UnavailableChannel is not initialized
DisconnectedChannel is disconnected
ConnectingChannel is connecting
ConnectedChannel is connected

ChatRoomService

ChatRoomInfo

public final class ChatRoomInfo {
    public enum BasicInfoType {
        Name,
        Description,
        Bulletin,
        AppExtra,
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public String getBulletin() {
        return bulletin;
    }


    public String getAppExtra() {
        return appExtra;
    }

    public ChatRoomInfo(@NonNull String name, @Nullable String description,
                        @Nullable String bulletin, @Nullable String appExtra) {
        this.name = name;
        this.description = description;
        this.bulletin = bulletin;
        this.appExtra = appExtra;
    }

    private final String name;
    private final String description;
    private final String bulletin;
    private final String appExtra;
}

ChatRoomInfo.BasicInfoType

public enum BasicInfoType {
    Name,
    Description,
    Bulletin,
    AppExtra,
}

A basic chatroom information enumeration field: mainly used to modify and listen to chatroom information; it can identify which field is or needs to be changed.

Enumeration ValueDescription
NameChatroom name
DescriptionChatroom description
BulletinChatroom announcement
AppExtraChatroom extended field (1K at maximum)

ChatRoomService.Signal

final class Signal extends Content {
    public final User   user;
    public final String content;

    public static Signal unicast(@NonNull User user, @NonNull String content) {
        return new Signal(user, content);
    }

    public static Signal broadcast(@NonNull String content) {
        return new Signal(null, content);
    }

    private Signal(User user, @NonNull String content) {
        this.user    = user;
        this.content = content;
    }

    @Override
    public String toString() {
        return "ChatRoom.Signal{" + content + "}";
    }
}

Challenges.JoiningCompletion

public interface JoiningCompletion {
    void onSucceed();
    void onFailure(@NonNull Error error);

  	// Reseveration
    void onReceiveChallenge(Challenges.Password challenge);
  	// Reseveration
    void onReceiveChallenge(Challenges.AppChallenge challenge);
}

ChatRoomService.EKickInfo

enum EKickInfo {
    Time,
    Reason,
}

ChatRoomService.Roles

final class Roles {
  	// Administrator
    public static final String Admin = "admin";
  	// Room owner
    public static final String Owner = "owner";
}

ChatRoomService.KickOff

public class KickOff {

    /**
     * Reasons for kicking out
     */
    private String reason;

    /**
     *  Kicking type
     */
    private KickOffEnum kickOffEnum;

    public KickOff(String reason, KickOffEnum kickOffEnum) {
        this.reason = reason;
        this.kickOffEnum = kickOffEnum;
    }

    public String getReason() {
        return reason;
    }

    public KickOffEnum getKickOffEnum() {
        return kickOffEnum;
    }
}

KickOffEnum

public enum KickOffEnum {

    /**
     * Kick out
     */
    KICK_OFF(0),

    /**
     * Mutiple platforms interfere with each other
     */
    MULTIJOIN_KICK_OFF(1),

    /**
     * Undefined
     */
    UNDEFINED(-1);

    private int type;

    KickOffEnum(int type) {
        this.type = type;
    }

    public int getType() {
        return type;
    }
}

ChatService

Message

public final class Message {
    /**
     * Build a null ChatMessage object
     */
    public Message() {
    }

    /**
     * Build a ChatMessage object that presets a message receiver and message content
     *
     * @param receiver Object for message receiving
     * @param content  Message content
     */
    public Message(Identifiable receiver, Content content) {
        this.chatContent = content;
        this.receiver = receiver;
        this.timestamp = 0L;
    }
  
    /**
     * Stattus abstract concept of ChatMessage
     */
    public interface State {
    }

    /**
     * Get the message content
     */
    public Content getContent() {
        return this.chatContent;
    }

    /**
     * Set the message content
     */
    public void setContent(Content content) {
        this.chatContent = content;
    }

    /**
     * Message sender. Due to the chat message (Message), it must originate from user. Therefore, its type can only be User
     * In case of user instance, rapidly judge whether this message is sent by the current user through HMR.isMe() when rendering the session interface.
     */
    public Identifiable getSender() {
        return sender;
    }

    /**
     * Set the message sender. In case of the message sent out locally, it will be automatically covered as the local user (Me) when calling ChatService.send method
     *
     * @param sender Message sender
     */
    public void setSender(Identifiable sender) {
        this.sender = sender;
    }

    /**
     * Message receiver. Specific type is multi-state,which may be Person (user chat session),Group (group chat session)……
     */
    public Identifiable getReceiver() {
        return receiver;
    }

    /**
     * Set the message receiver. For the message sent locally, the service must display that ChatMessage displays and configure the Receiver attribute.
     *
     * @param receiver Message receiver
     */
    public void setReceiver(Identifiable receiver) {
        this.receiver = receiver;
    }

    /**
     * For the current user, the method is used to return the target object corresponding to the chat.
     *
     * @return In caes of P2P message, return the user object beyond the current user. In case of group, chatroom, official number and other messages, return receiver as target
     */
    public Identifiable getTarget() {
        // For P2P chat messages, the logical table for determining target of conversation is as follows:
        // 1. sender: me,     receiver: me          <- receiver
        // 2. sender: me,     receiver: fellow      <- receiver
        // 3. sender: fellow, receiver: me          <- sender
        // 4. sender: fellow, receiver: fellow    <-N/A We should not have received this message
        if (sender instanceof User && receiver instanceof User) {
            if (HMR.isMe(sender)) {
                return receiver;
            } else if (HMR.isMe(receiver)) {
                return sender;
            } else {
                return null;
            }
        }
        // For non-P2P messages including group message, chatroom message, and public account message, receiver must be the relationship object itself
        // sender is the person sending message to the relationship, therefore receiver can be returned directly
        return receiver;
    }

    /**
     * timestamp attribute is a message timstamp. When the message is sent (will be sent), the timestamp is the local timestamp of device; and when it is sent completely, the time stamp is Hummer server
     * Returned timestamp. Considering the time difference between the local timestamp and server time, as well as the time difference between the servers in the server cluster, the timestamp
     * can only be taken as the basis for approximately (in most cases) judging the message sequence.
     */
    public long getTimestamp() {
        return this.timestamp;
    }

    /**
     * Set the message timestamp
     */
    public void setTimestamp(long ts) {
        this.timestamp = ts;
    }

    /**
     * uuid is the (approximately) uniquely identified id of message, and as uuid is independently generated at the local client, the conflict may occur theoretically. But
     * this probability is very low, so it can be used as the uniquely identified id of message to remove the repeated message.
     */
    public String getUuid() {
        return this.uuid;
    }

    /**
     * Set the unique identifer of message, which is usually generated in Hummer and set. Generally, the service does not call this method
     */
    public void setUuid(String id) {
        this.uuid = id;
    }

    /**
     * Each ChatMessage object can attach to a service expansion information. This information can help the service pass through user avatar and other data closely related to the service logic. Hummer only
     * pass through this data, rather than specificially explaining and processing.
     */
    public String getAppExtra() {
        return appExtra;
    }

    /**
     * Set the service pass-through data of message
     */
    public void setAppExtra(String appExtra) {
        this.appExtra = appExtra;
    }

    private String uuid;
    private Identifiable sender;
    private Identifiable receiver;
    private PushContent pushContent;
    private Long timestamp;
    private String appExtra;
    private Content chatContent;
}
Profile (value)Note
uuidUnique message ID
senderMessage sender. See details in Identifiable.
receiverMessage receiver. See detail in Identifiable.
timestampMessage timestamp
appExtraSEI. The service can analyze and perform special processing on this profile.
chatContentMessage content: text, unicast and broadcast. See details in Content.

Identifiable

Abstract class of unique identifiers

public abstract class Identifiable {
    /**
     * Both User and Chatroom must have the unique identifier, and getId is used to return such identifier.
     * But, User and Chatroom may have the same id value.
     * Therefore, it must keep in mind that, different message senders and receivers cannot be judged through the features of id value.
     */
    public abstract long getId();
}
Implementation ClassNote
UserA unique identifiers class. See details in User.
ChatRoomA chatroom unique identifier class. See details in ChatRoom.

User

A user object identifier for identifying Hummer system

public final class User extends Identifiable {
    /**
     * Build the user ID object
     * @param uid User uid,For Hummer,when uid is 0, it indicates anonymous user
     */
    public User(long uid) {
        this.uid = uid;
    }

    /**
     * Get user ID value
     */
    @Override
    public long getId() {
        return uid;
    }

    private final long uid;
}

ChatRoom

Chatroom unique identifier class

public final class ChatRoom extends Identifiable {
		public ChatRoom(long id) {
        this.roomId = id;
    }

    @Override
    public long getId() {
        return roomId;
    }

    private final long roomId;
}

Content

Used to represent a chatroom content type, with the specific type implemented by sub-classes, such as Text and Signal.

public class Content {}
Inheritance ClassNote
TextText message content type. See details in Text.
SignalChatroom signaling messages (includes unicast and broadcast). See details in ChatRoomService.Signal.

Text

Text message content type

public final class Text extends Content {
    /**
     * Build a text message
     * @param text Text content of message
     */
    public Text(String text) {
        this.text = text;
    }

    /**
     * Get the message text
     */
    public String getText() {
        return text;
    }

    private String text;
}

Error

Hummer indicates general error types, common in requests that require network communication, such as sending or receiving messages. See Code for enumeration of Error.code.

public final class Error {
    /**
     * code attribute is mainly used for machine judgement, rapid log location and other functions
     */
    public final int code;

    /**
     * reason attribute describes mCode through readable text form
     */
    public final String desc;

    /**
     * Build Error instance,
     *
     * @param code Code of processed result
     * @param desc Text description of processed result
     */
    public Error(int code, String desc) {
        this.code = code;
      	this.desc = desc;
    }
}

Was this page helpful?

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