400-881-9892

文档中心

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

文档中心 互动课堂

Signaling and modifying attributes

    sendMessage
    • Brief description

    Send chat message

    Callback for receiving a chat message:

    -(void)roomManagerMessageReceived:(NSString )message fromID:(NSString )peerID extension:(NSDictionary *)extension.

    • Interface name
    1
    2
    3
        - (int)sendMessage:(NSObject *)message
                  toID:(NSString *)toID
         extensionJson:(NSObject * _Nullable)extension;
    
    • Parameter
    Parameter Name Required Type Description
    message Yes NSObject The chat message body only supports NSString and NSDictionary
    toID Yes NSString Indicates the recipient of the message, of type NSString. For details, see the relevant definitions in TKRoomDefines.h. It can be a specific user ID, indicating that the message is sent only to that user
    extension No BOOL Message extension content, for example: message type type; supports NSString (JSON string) and NSDictionary
    • Method Example
    1
    2
    3
    4
    5
    6
        NSMutableDictionary * msgDic = [[NSMutableDictionary alloc] initWithCapacity:3];
        [msgDic setObject:@"The first chat message" forKey:@"msg"];
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"HH:mm"];
        NSString *time = [dateFormatter stringFromDate:[NSDate date]];
        NSDictionary *messageDic = @{@"type" : @0, @"time" : time};
    
    • Return Value Description
    Type Description
    int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

    pubMsg

    • Brief description

    Publish custom signaling

    After publishing custom signaling, the signaling callback is received:

    -(void)roomManagerOnRemotePubMsgWithMsgID:(NSString )msgID msgName:(NSString )msgName data:(NSObject )data fromID:(NSString )fromID inList:(BOOL)inlist ts:(long)ts

    For details on custom signaling, see: Getting Started - Custom Signaling

    • Interface name
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    - (int)pubMsg:(NSString *)msgName
            msgID:(NSString *)msgID
             toID:(NSString *)toID
             data:(NSObject * _Nullable)data
             save:(BOOL)save
       completion:(completion_block _Nullable)completion;
    - (int)pubMsg:(NSString *)msgName
            msgID:(NSString *)msgID
             toID:(NSString *)toID
             data:(NSObject * _Nullable)data
             save:(BOOL)saveextensionData:(NSDictionary * _Nullable)extensionData
        completion:(completion_block _Nullable)completion;
    - (int)pubMsg:(NSString *)msgName
            msgID:(NSString *)msgID
             toID:(NSString *)toID
             data:(NSObject * _Nullable)data
             save:(BOOL)saveassociatedMsgID:(NSString * _Nullable)associatedMsgIDassociatedUserID:(NSString * _Nullable)associatedUserID
          expires:(NSTimeInterval)expires
       completion:(completion_block _Nullable)completion;
    - (int)pubMsg:(NSString *)msgName
            msgID:(NSString *)msgID
             toID:(NSString *)toID
             data:(NSObject *)data
             save:(BOOL)saveassociatedMsgID:(NSString *)associatedMsgIDassociatedUserID:(NSString *)associatedUserID
          expires:(NSTimeInterval)expiresextensionJson:(NSDictionary * _Nullable)extensionJson
       completion:(completion_block _Nullable)completion;
    
    • Parameter
    Parameter Name Required Type Description
    msgName Yes NSString Signaling Name
    msgID Yes NSString Signaling ID
    toID Yes NSString The recipient of the signaling. Type NSString. For details, see the relevant definitions in TKRoomDefines.h. It can be a specific user ID, indicating that the signaling is sent only to that user
    data Yes NSObject Signaling content data, which can be Number, NSString, NSDictionary, or NSArray
    save Yes BOOL Whether to save. For details, see: Getting Started - Custom Signaling
    associatedMsgID No NSString Indicates that this signaling can be associated with another signaling. If the associated signaling is deleted, this signaling will also be deleted. If association is needed, provide the ID of another signaling; otherwise, pass nil
    associatedUserID No NSString Indicates that this signaling is associated with a user ID. If the associated user leaves the room, this signaling will also be deleted. If association is needed, provide the user ID; otherwise, pass nil
    expires Yes NSTimeInterval Indicates how long this signaling will last, in seconds, as a relative time. 0: Indicates no expiration. For example, if you publish a ClassBegin signaling (indicating the start of a class), after the specified expires time (relative time) has elapsed, the server will delete the ClassBegin signaling (indicating the end of the class)
    extensionJson No NSDictionary Signaling extension content, which can be extended according to your own needs.
    completion No completion_block Callback for completion of the call
    • Method Example
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
       NSDictionary * dict = @{@"nickname": @""};       //Can be customized
       [_roomMgr pubMsg:@"msgName"                      // Customizable signaling name
                       msgID:@"msgID"                            // Customizable Signaling ID
                          toID:TKRoomPubMsgTellAll
                          data:dict
                          save:NO
         associatedMsgID:nil
        associatedUserID:nil
                      expires:0
               extensionJson:@{@"write2DB" : @YES}      //Can be extended according to business needs
                completion:nil];
    
    • Return Value Description
    Type Description
    int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

    delMsg

    • Brief description

    Delete custom signaling

    Callback for deleting signaling:

    -(void)roomManagerOnRemoteDelMsgWithMsgID:(NSString )msgID msgName:(NSString )msgName data:(NSObject )data fromID:(NSString )fromID inList:(BOOL)inlist ts:(long)ts

    • Interface name
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    - (int)delMsg:(NSString *)msgName
              msgID:(NSString *)msgID
                toID:(NSString *)toID
                data:(NSObject * _Nullable)data
       completion:(completion_block _Nullable)completion;
    - (int)delMsg:(NSString *)msgName
              msgID:(NSString *)msgID
                toID:(NSString *)toID
                data:(NSObject * _Nullable)dataextensionJson:(NSDictionary * _Nullable)extensionJson
       completion:(completion_block _Nullable)completion;
    
    • Parameter
    Parameter Name Required Type Description
    msgName Yes TKLogLevel Signaling Name
    msgID Yes NSString Signaling ID
    toID Yes NSString The recipient of the signaling. Type NSString. For details, see the relevant definitions in TKRoomDefines.h. It can be a specific user ID, indicating that this signaling is sent only to that user
    data No NSObject Signaling content data, which can be Number, NSString, NSDictionary, or NSArray, and can be nil
    extensionJson No NSDictionary Signaling extension content, which can be extended according to your own needs
    completion No completion_block Callback for call completion
    • Method Example
    1
    2
    3
    4
    5
    6
       [_roomMgr  delMsg:@"ChatShow"               //Custom Name
                              msgID:@"ChatShow"             //Custom ID
                              toID:TKRoomPubMsgTellAll
                             data:nil
                  extensionJson:nil
                    completion:nil];
    
    • Return Value Description
    Type Description
    int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

    evictUser

    • Brief description

    Kick the user out of the room

    • Interface name
    1
    2
    - (int)evictUser:(NSString *)peerID evictReason:(NSNumber *)reason completion:(completion_block _Nullable)completion;
    - (int)evictUser:(NSString *)peerID completion:(completion_block _Nullable)completion;
    
    • Parameter
    Parameter Name Required Type Description
    peerID Yes NSString The ID of the user being kicked out
    reason Yes NSNumber Reason for being kicked out, which can be customized according to business needs
    completion No completion_block Callback for call completion
    • Method Example
    1
    2
    3
          [_roomMgr  evictUser:@"abd235674"
                      evictReason:@(400)            // Can be customized according to business needs
                        completion:nil];
    
    • Return Value Description
    Type Description
    int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

    switchOnlyAudioRoom

    • Brief description

    Switch to an 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 and no video. After a successful switch, the callback is: -(void)roomManagerOnAudioRoomSwitch:(NSString *)fromId onlyAudio:(BOOL)onlyAudio

    • Interface name

    - (int)switchOnlyAudioRoom:(BOOL)isSwitch;

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

    [_roomMgr switchOnlyAudioRoom:NO];

    • Return Value Description
    Type Description
    int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

    changeCurrentServer

    • Brief description

    Switch server

    By calling this interface, you can switch the server connected by the SDK. You can call the interface - (NSArray * _Nullable)getServerList to obtain the list of available servers for the room.

    • Interface name

    - (int)changeCurrentServer:(NSString *)serverName;

    • Parameter
    Parameter Name Required Type Description
    serverName Yes NSString Server Name
    • Method Example

    [_roomMgr changeCurrentServer:@"global"];

    • Return Value Description
    Type Description
    int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

    changeUserProperty

    • 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 this, both you and other users will receive a callback for the successful modification: -(void)roomManagerUserPropertyChanged:(NSString )peerID properties:(NSDictionary )properties fromId:(NSString *)fromId

    • Interface name
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    - (int)changeUserProperty:(NSString *)peerID
                           tellWhom:(NSString *)tellWhom
                                   key:(NSString *)key
                                  value:(NSObject *)value
                      completion:(completion_block _Nullable)completion;
    - (int)changeUserProperty:(NSString *)peerID
                           tellWhom:(NSString *)tellWhom
                                   data:(NSDictionary *)data
                       completion:(completion_block _Nullable)completion;
    - (int)changeUserProperty:(NSString *)peerID
                            tellWhom:(NSString *)tellWhom
                             property:(NSDictionary *)property
                      extensionJson:(NSDictionary * _Nullable)extensionJson
                       completion:(completion_block _Nullable)completion;
    
    • Parameter
    Parameter Name Required Type Description
    peerID Yes NSString User ID
    tellWhom Yes NSString Indicates that after successfully modifying the attributes of a specific user, the notification of this attribute change needs to be sent to other users in the room. Type NSString. For details, see the relevant definitions in TKRoomDefines.h. It can be a specific user ID, indicating that this signaling is sent only to that user
    key Yes NSString The name of the modified property
    value Yes NSObject The value corresponding to the modified property name
    data Yes NSDictionary The modified properties in key-value form, where the key represents the property name and the value represents the value corresponding to the property name
    extensionJson No NSDictionary Extension information, which can be appended according to business needs
    completion No completion_block Callback for completion of the call
    • Method Example
    1
    2
    3
    4
    5
    6
    7
    8
    9
     [_roomMgr changeUserProperty:@"adc123456"
                                         tellWhom:TKRoomPubMsgTellAll
                                                data:@{@"publishState" : @"3"}
                                       completion:nil];OR:
     [_roomMgr changeUserProperty:@"adc123456"
                                      tellWhom:TKRoomPubMsgTellAll
                                              key:@"publishState"
                                           value:@"3"
                                   completion:nil];
    
    • Return Value Description
    Type Description
    int 0: Indicates that the call was successful. Non-zero: Indicates that the call failed

    Notes

    For more return error codes, please refer to the error code descriptions in TKRoomErrorCode