All room members that are subscribed to the chat will receive the text messages. You must first enter the room before you may send and receive messages.
Initializing
First, instantiate the chat service. A Room Service is required to obtain the chat service.
Swift
importPhenixSdklet roomService: PhenixRoomService = ... // previously obtainedlet chatService = PhenixRoomChatServiceFactory.createRoomChatService(roomService)!// Use a custom batch size, i.e. max number of message returned by 'getObservableChatMessages'let batchSize: UInt = 10let chatServiceWithBatchSize = PhenixRoomChatServiceFactory.createRoomChatService(roomService, batchSize)!
The chat service exposes an observable of the most recent N (batchSize) messages in the active room up to a max of 100 messages. To view older messages you will need to use the getMessages method.
Send a single message to the active room. If the message is successfully sent the chatMessageObservable will trigger notifications on all subscribers with the new chat message.
Swift
importPhenixSdklet chatService: PhenixRoomChatService = ... // previously obtained// Without callback:chatService.sendMessage(toRoom: "My First Message")// With callbackchatService.sendMessage(toRoom: "My First Message") { (status: PhenixRequestStatus, message: String?) inif status != .ok {// handle error - send message again }}
Send Message Parameters
Name
Type
Description
message (required)
String
Message to send to the room
sendMessageCallback (optional)
Function
Callback with the status of the request
Send Message Callback Arguments
Name
Type
Description
status
PhenixRequestStatus
The status of the operation
message
NSString
Optional additional error status in case of a failure
Send Message Callback Status Codes
Status
Description
ok
Send message succeeded
varies
Send message failed for other reasons
Chat Message History
Get messages older than the most recent N buffered in the chatMessageObservable.