400-881-9892

文档中心

官方文档,可查阅产品介绍、快速入门、用户指南、开发指南、API参考、SDK参考、帮助等信息。

文档中心 互动课堂

Signaling And Modify Attributes

    sendMessage
    • A brief description - Send a chat message

    The callback for receiving chat messages: - (void)onMessageReceived(RoomUser user, JSONObject message, long ts)。

    • Interface Name

    - (int)sendMessage(String message, String toId, Map<String, Object> atts);

    • Parameters
    Parameter Name Required Type Description
    message Yes string The chat message body sent
    toID Yes string Indicates the recipient of the message, of String type. For details, see the relevant definitions in the “Getting Started with Custom Signals” section. It can be a specific user ID, indicating that the message is sent only to that user
    atts No Map Message extension content
    • Method Example

    TKRoomManager.getInstance().sendMessage(msg, SignalingRole.ALL, null);

    • Return Value Description
    Type Description
    int 0: Indicates successful invocation; Non-zero: Indicates invocation failure
    pubMsg
    • A brief description - Publish Custom Signals

    After successfully entering the room, you can send custom signals for communication between users. - After publishing custom signals, the signal callback is received: -(void)onRemotePubMsg(String id, String name, long ts, String dataJson, boolean inList, String fromId, String associatedMsgId, String associatedUserId)

    For more information about custom signals, see: Getting Started - Custom Signals

    • Interface Name
    1
    2
    3
    4
     - (int)pubMsg(String msgName, String msgId, String toId, Object data, boolean save, String associatedMsgId, String associatedUserId);
    - (int)pubMsg(String msgName, String msgId, String toId, Object data, boolean save, String associatedMsgId, String associatedUserId, HashMap<String, Object> attrMap);
    - (int)pubMsg(String msgName, String msgId, String toId, Object data, boolean save, long expiresabs);
    - (int)pubMsg(String msgName, String msgId, String toId, Object data, boolean save, long expiresabs, long expires);
    
    • Parameters
    Parameter Name Required Type Description
    msgName Yes string Signal Name
    msgID Yes string Signal ID
    toID Yes String The recipient of the signal. For details, see the relevant definitions in the “Getting Started with Custom Signals” section. It can be a specific user ID, indicating that the signal is sent only to that user
    data Yes Object Signal Content Data
    save Yes BOOL Whether to Save. For details, see Getting Started: Custom Signals
    associatedMsgID No string Indicates that this signal can be associated with another signal. If the associated signal is deleted, this signal will also be deleted. If association is needed, provide the ID of another signal; otherwise, use null
    associatedUserID No string Indicates that this signal is associated with a user ID. If the associated user leaves the classroom, this signal will also be deleted. If association is needed, provide the user ID; otherwise, use null
    expires Yes Long Indicates the duration after which the signal will expire, measured in seconds. A value of 0 means no expiration. For example, when publishing the ClassBegin signal (indicating the start of a class), the server will delete the ClassBegin signal after the specified expires duration (indicating the end of the class)
    attrMap No Map Signal extension content, which can be extended according to specific needs.
    • Method Example
    1
    2
    3
    4
     - (int)pubMsg(String msgName, String msgId, String toId, Object data, boolean save, String associatedMsgId, String associatedUserId);
    - (int)pubMsg(String msgName, String msgId, String toId, Object data, boolean save, String associatedMsgId, String associatedUserId, HashMap<String, Object> attrMap);
    - (int)pubMsg(String msgName, String msgId, String toId, Object data, boolean save, long expiresabs);
    - (int)pubMsg(String msgName, String msgId, String toId, Object data, boolean save, long expiresabs, long expires);
    
    • Return Value Description
    Type Description
    int 0: Indicates successful invocation; Non-zero: Indicates invocation failure
    delMsg
    • A brief description - Delete Custom Signal

    Delete Signal Callback: -(void) onRemoteDelMsg(String id, String name, long ts, String dataJson, boolean inList, String fromId, String associatedMsgId, String associatedUserId);

    • Interface Name

    - (int)delMsg(String msgName, String msgId, String toId, Object data);

    • Parameters
    Parameter Name Required Type Description
    msgName Yes string Signal Name
    msgID Yes string Signal ID
    toID Yes String The recipient of the signal. For details, see the relevant definitions in the “Getting Started with Custom Signals” section. It can be a specific user ID, indicating that the signal is sent only to that user
    data No Object Signal content data, which can be null
    • Method Example

    TKRoomManager.getInstance().delMsg(msgName, msgID, "__none", null);

    • Return Value Description
    Type Description
    int 0: Indicates successful invocation; Non-zero: Indicates invocation failure
    evictUser
    • A brief description - Kick user out of room

    • Interface Name

    1
    2
     - (int)(String peerId);
    - (int)evictUser(String peerId, int reason);
    
    • Parameters
    Parameter Name Required Type Description
    peerID Yes string Kicked User ID
    reason Yes int Reason for being kicked, which can be customized according to business needs. Refer to the server-side documentation for kick error codes
    • Method Example

    TKRoomManager.getInstance().evictUser(roomUser.getPeerId(), 1);

    • Return Value Description
    Type Description
    int 0: Indicates successful invocation; Non-zero: Indicates invocation failure
    switchOnlyAudioRoom
    • A brief description - Switch to audio-only room

    You can freely switch the room to audio-only or a normal room. Audio-only room: In this type of room, all users will only publish audio, with no video. - After a successful switch, the callback is: -(void)onAudioRoomSwitch(String fromId, boolean isSwitch);

    • Interface Name

    - (void)switchOnlyAudioRoom(boolean isSwitch);

    • Parameters
    Parameter Name Required Type Description
    isSwitch Yes boolean Whether to switch
    • Method Example

    TKRoomManager.getInstance().switchOnlyAudioRoom(true);

    • Return Value Description
    Type Description
    int 0: Indicates successful invocation; Non-zero: Indicates invocation failure
    switchService
    • A brief description - Switch server

    By calling this interface, you can switch the server connected by the SDK. You can call the -getServiceList interface to obtain the list of available servers for the room.

    • Interface Name

    - (int)switchService(String serverName);

    • Parameters
    Parameter Name Required Type Description
    serverName Yes String Server name
    • Method Example

    TKRoomManager.getInstance().switchService(servername);

    • Return Value Description
    Type Description
    int 0: Indicates successful invocation; Non-zero: Indicates invocation failure
    changeUserProperty
    • A brief description - Modify user attributes

    You can call this interface to modify the attributes of a specified user, such as the number of trophies. - After calling, both yourself and other users will receive a callback for the successful modification: - (void)onUserPropertyChanged(RoomUser user, Map changedProperties, String fromId)

    • Interface Name
    1
    2
    3
    - (int)changeUserProperty(String peerId, String tellWhom, String key, Object value);
    - (int)changeUserProperty(String peerId, String tellWhom, String key, Object value, HashMap<String, Object> opt);
    - (int)changeUserProperty(String peerId, String tellWhom, HashMap<String, Object> property);
    
    • Parameters
    Parameter Name Required Type Description
    peerID Yes String User ID
    tellWhom Yes String After successfully modifying a user’s attributes, it is necessary to notify other users in the room of this attribute change. For details, see the relevant definitions in the “Getting Started Guide - Custom Signaling”. It can be a specific user ID, indicating that this signaling is only sent to that user
    key Yes String The name of the modified attribute
    value Yes Object The value corresponding to the modified attribute name
    property Yes Map The modified attribute in key-value form, where the key represents the attribute name and the value represents the value corresponding to the attribute name
    opt No Map Extended information, which can be appended according to business needs
    • Method Example

    TKRoomManager.getInstance().changeUserProperty(roomUser.getPeerId(), SignalingRole.ALL, "raisehand", true);

    • Return Value Description
    Type Description
    int 0: Indicates successful invocation; Non-zero: Indicates invocation failure