STSChatManager
@interface STSChatManager : NSObject
StraaS.io chat room manager, support multi-connection management.
-
Init STSChatManager with the config.
Declaration
Objective-C
- (nonnull instancetype)initWithChatManagerConfig: (STSChatManagerConfig *_Nullable)chatManagerConfig;Swift
init(chatManagerConfig: STSChatManagerConfig?)Parameters
STSChatManagerConfigThe STSChatManagerConfig. Not to set this or sets this to nil to use the default value.
-
Connect to chat room with user JWT.
Declaration
Objective-C
- (void)connectToChatroom:(nonnull NSString *)chatroomName JWT:(nonnull NSString *)JWT eventDelegate:(nullable id<STSChatEventDelegate>)eventDelegate;Swift
func connect(toChatroom chatroomName: String, jwt JWT: String, eventDelegate: STSChatEventDelegate?)Parameters
chatroomNameIdentifier of chat room. Don’t pass nil or this method return early.
JWTUser identity information. For StraaS.io CMS member, a member JWT should be used here. Use an empty string to represent guest. Don’t pass nil or this method return early.
eventDelegateChat event delegate. Chat manager not retain this delegate.
-
Get chat room active users, maximum 200 users.
Declaration
Objective-C
- (void)getUsersForChatroom:(nonnull STSChat *)chatroom userType:(STSGetUsersType)userType success:(nonnull void (^)(NSArray<STSChatUser *> *_Nonnull)) success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func getUsersForChatroom(_ chatroom: STSChat, userType: STSGetUsersType, success: @escaping ([STSChatUser]) -> Void, failure: @escaping (Error) -> Void)Parameters
chatroomThe STSChat object you want to get users.
userTypeThe type of users you want to get.
successHandler for successful request. It takes an
NSArrayofSTSChatUserargument that contains chat room active users.failureError handler.
-
Get chat room messages. Note: If there are over 5000 ccu in the chatroom, this method will return an empty array.
Declaration
Objective-C
- (void)getMessagesForChatroom:(nonnull STSChat *)chatroom configuration: (STSGetMessagesConfiguration *_Nullable)configuration success:(nonnull void (^)( NSArray<STSChatMessage *> *_Nonnull))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func getMessagesForChatroom(_ chatroom: STSChat, configuration: STSGetMessagesConfiguration?, success: @escaping ([STSChatMessage]) -> Void, failure: @escaping (Error) -> Void)Parameters
chatroomThe STSChat object you want to get messages.
configurationA STSGetMessagesConfiguration object that specifies the request rules for getting messages.
successHandler for successful request. It takes an
NSArrayofSTSChatMessageargument that contains chat room messages.failureError handler.
-
Update nickname for guest user.
Declaration
Objective-C
- (void)updateGuestNickname:(nonnull NSString *)nickname chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func updateGuestNickname(_ nickname: String, chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
nicknameNew nickname. Should be between 1~20 characters.
chatroomThe STSChat object you want to update nickname.
successHandler for successful request.
failureError handler.
-
Update role for given user.
Declaration
Objective-C
- (void)updateUserRole:(nonnull NSString *)role targetUser:(nonnull STSChatUser *)targetUser chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func updateUserRole(_ role: String, targetUser: STSChatUser, chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
roleThe role want to be updated for target user. Role can be either kSTSUserRoleNormal or kSTSUserRoleModerator only.
targetUserThe users needs to be updated.
chatroomThe STSChat object you want to update user role.
successHandler for successful request.
failureError handler.
-
Update role for given memberId.
Declaration
Objective-C
- (void)updateUserRole:(nonnull NSString *)role memberId:(nonnull NSString *)memberId chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func updateUserRole(_ role: String, memberId: String, chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
roleThe role want to be updated for target user. Role can be either kSTSUserRoleNormal or kSTSUserRoleModerator only.
memberIdThe CMS member id.
chatroomThe STSChat object you want to update user role.
successHandler for successful request.
failureError handler.
-
Block users by current user. Only succeed when current user has the privilege.
Declaration
Objective-C
- (void)blockUsers:(nonnull NSArray<STSChatUser *> *)users chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func blockUsers(_ users: [STSChatUser], chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
usersThe users in chat going to be blocked
chatroomThe STSChat object you want to block users.
successHandler for successful request.
failureError handler.
-
Revive users by current user. Only succeed when current user has the privilege.
Declaration
Objective-C
- (void)reviveUsers:(nonnull NSArray<STSChatUser *> *)users chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func reviveUsers(_ users: [STSChatUser], chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
usersThe users in chat going to be revived.
chatroomThe STSChat object you want to revive users.
successHandler for successful request.
failureError handler.
-
Send message to chatroom. Note: Call this method more than once a second is not allowed.
Declaration
Objective-C
- (void)sendMessage:(nonnull NSString *)message chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func sendMessage(_ message: String, chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
messageMessage text. Should be between 1~500 characters.
chatroomThe STSChat object you want to send message.
successHandler for successful request.
failureError handler.
-
Remove chat message. Note: This method works only when the current user of target chatroom has the privilege.
Declaration
Objective-C
- (void)removeMessage:(nonnull NSString *)messageId chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func removeMessage(_ messageId: String, chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
messageIdThe message Id which you want to remove.
chatroomThe STSChat object you want to remove message.
successHandler for successful request.
failureError handler.
-
Get the pinned message of a chatroom.
Declaration
Objective-C
- (void)getPinnedMessageForChat:(nonnull STSChat *)chatroom success: (nonnull void (^)(STSChatMessage *_Nullable))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func getPinnedMessage(for chatroom: STSChat, success: @escaping (STSChatMessage?) -> Void, failure: @escaping (Error) -> Void)Parameters
chatroomThe STSChat object you want to get the pinned message.
successHandler for successful request.
failureError handler.
-
Pins a message to the chatroom.
Note: 1. A chatroom can only have a pinned message at once, it means this method will override the last pinned message. 2. This method works only when the current user of target chatroom has the privilege.
Declaration
Objective-C
- (void)pinMessage:(nonnull NSString *)messageId chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func pinMessage(_ messageId: String, chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
messageIdThe message Id which you want to pin.
chatroomThe STSChat object you want to pin the message.
successHandler for successful request.
failureError handler.
-
Unpins a message from the given chatroom. Note: This method works only when the current user of target chatroom has the privilege.
Declaration
Objective-C
- (void)unpinMessageFromChatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func unpinMessage(fromChatroom chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
chatroomThe STSChat object you want to unpin the message.
successHandler for successful request.
failureError handler.
-
Sets metadata key-value pair to a chatroom
Note
- This method works only when the current user of target chatroom has the privilege.
- Sets a value to an existing key will overwrite the previous one.
- The value should be an instance of
NSString,NSNumber,NSNullor a valid JSON object. Max size is 1k ifbroadcastisYES, max size is 4k ifbroadcastisNO. - The key name must match the regular expression format
^[A-Za-z0-9][A-Za-z0-9_32@#-]{0,29}$.
Rate limit
1 request per second per chatroom (if
broadcastisYES); 1 request per 30 second per chatroom (ifbroadcastisNO).Declaration
Objective-C
- (void)setMetadataValue:(nonnull id)value forKey:(nonnull NSString *)key chatroom:(nonnull STSChat *)chatroom broadcast:(BOOL)broadcast success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func setMetadataValue(_ value: Any, forKey key: String, chatroom: STSChat, broadcast: Bool, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
valueThe value of metadata. Refer notes for the format constraint.
keyThe key of metadata. Refer notes for the format constraint.
chatroomThe
STSChatobject you want to set metadata.broadcastIndicates whether the change of the metadata should be broadcasted via socket or not.
successHandler for successful request.
failureError handler.
-
Gets metadata key-value pairs of a chatroom.
Rate limit
1 request per second per chatroom. 3000 per days per chatroom.
Declaration
Objective-C
- (void)getMetadataForKeys:(NSArray<NSString *> *_Nullable)keys chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)( NSDictionary<NSString *, STSChatMetadata *> *_Nonnull))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func getMetadataForKeys(_ keys: [String]?, chatroom: STSChat, success: @escaping ([String : STSChatMetadata]) -> Void, failure: @escaping (Error) -> Void)Parameters
keysThe array contains keys to get. Pass
nilif you want to get the metadata for all keys.chatroomThe STSChat object you want to get metadata.
successHandler for successful request.
failureError handler.
-
Returns the chat object.
Declaration
Objective-C
- (nullable STSChat *)chatForChatroomName:(nonnull NSString *)chatroomName;Swift
func chat(forChatroomName chatroomName: String) -> STSChat?Parameters
chatroomNameIdentifier of chat room.
Return Value
A
STSChatinstance if the chat room is connected, or nil. -
Returns the current chat user object.
Declaration
Objective-C
- (nullable STSChatUser *)currentUserForChatroom:(nonnull STSChat *)chatroom;Swift
func currentUser(forChatroom chatroom: STSChat) -> STSChatUser?Parameters
chatroomThe STSChat object you want to get current user.
Return Value
A
STSChatUserinstance if the chat room is connected, or nil. -
Returns the cooldown to send next message for chat room.
Declaration
Objective-C
- (NSTimeInterval)cooldownForChatroom:(nonnull STSChat *)chatroom;Swift
func cooldown(forChatroom chatroom: STSChat) -> TimeIntervalParameters
chatroomThe STSChat object you want to get the cooldown time.
Return Value
The cooldown in seconds.
-
Update the chat room event delegate.
Declaration
Objective-C
- (void)setEventDelegate:(nullable id<STSChatEventDelegate>)delegate forChatroom:(nonnull STSChat *)chatroom;Swift
func setEventDelegate(_ delegate: STSChatEventDelegate?, forChatroom chatroom: STSChat)Parameters
delegateChat room event delegate.
chatroomThe STSChat object you want to set with the event delegate.
-
Send a key to the data channel which will be aggregated to STSAggregatedItem in
chatroom:aggregatedItemsAdded:.Declaration
Objective-C
- (void)sendAggregatedDataWithKey:(nonnull NSString *)key chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func sendAggregatedData(withKey key: String, chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
keyThe Aggregated item string key. Should be between 1~100 characters.
chatroomThe STSChat object you want to send message.
successHandler for successful request.
failureError handler.
-
Send raw data to data channel. Raw data should be a valid JSON object only. ref: https://developer.apple.com/reference/foundation/jsonserialization/1418461-isvalidjsonobject
Declaration
Objective-C
- (void)sendRawData:(nonnull id)rawData chatroom:(nonnull STSChat *)chatroom success:(nonnull void (^)(void))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func sendRawData(_ rawData: Any, chatroom: STSChat, success: @escaping () -> Void, failure: @escaping (Error) -> Void)Parameters
rawDataThe jsonObject raw data.
chatroomThe STSChat object you want to send message.
successHandler for successful request.
failureError handler.
-
Get chat room aggregated data.
Declaration
Objective-C
- (void) getAggregatedDataForChatroom:(nonnull STSChat *)chatroom configuration: (STSGetMessagesConfiguration *_Nullable)configuration success: (nonnull void (^)( NSArray<STSAggregatedData *> *_Nonnull))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func getAggregatedData(forChatroom chatroom: STSChat, configuration: STSGetMessagesConfiguration?, success: @escaping ([STSAggregatedData]) -> Void, failure: @escaping (Error) -> Void)Parameters
chatroomThe STSChat object you want to get aggregated data.
configurationA STSGetMessagesConfiguration object that specifies the request rules for getting messages.
successHandler for successful request. It takes an
NSArrayofSTSChatMessageargument that contains chat room messages.failureError handler.
-
Get chat room raw data.
Declaration
Objective-C
- (void)getRawDataForChatroom:(nonnull STSChat *)chatroom configuration: (STSGetMessagesConfiguration *_Nullable)configuration success:(nonnull void (^)( NSArray<STSChatMessage *> *_Nonnull))success failure:(nonnull void (^)(NSError *_Nonnull))failure;Swift
func getRawData(forChatroom chatroom: STSChat, configuration: STSGetMessagesConfiguration?, success: @escaping ([STSChatMessage]) -> Void, failure: @escaping (Error) -> Void)Parameters
chatroomThe STSChat object you want to get raw data.
configurationA STSGetMessagesConfiguration object that specifies the request rules for getting messages.
successHandler for successful request. It takes an
NSArrayofSTSChatMessageargument that contains chat room messages.failureError handler.
View on GitHub
Install in Dash
STSChatManager Class Reference