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.
Java
importandroid.content.Context;importcom.phenixrts.chat.RoomChatService;importcom.phenixrts.chat.RoomChatServiceFactory;importcom.phenixrts.environment.android.AndroidContext;importcom.phenixrts.room.RoomService;// IMPORTANT: Before accessing any of the static factories, make sure the context is passed to Phenix:finalContext context =...;// e.g. Activity.getApplication();AndroidContext.setContext(context);finalRoomService roomService =...;// previously obtainedfinalRoomChatService chatService =RoomChatServiceFactory.createRoomChatService(roomService);// Use a custom batch size, i.e. max number of message returned by 'getObservableChatMessages'finalint batchSize =10;finalRoomChatService chatServiceWithBatchSize =RoomChatServiceFactory.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.
Java
importcom.phenixrts.common.RequestStatus;importcom.phenixrts.chat.ChatMessage;importcom.phenixrts.chat.RoomChatService;finalRoomChatService chatService =...;// previously obtained// Without callback:chatService.sendMessageToRoom("My First Message");// With callbackchatService.sendMessageToRoom("My First Message", (RequestStatus status, String message) -> {if (status ==RequestStatus.OK) {// Successfully sent } else {// handle error - send message again// (`message` may provide more information about what went wrong) }});
Send Message Parameters
Name
Type
Description
message (required)
String
Message to send to the room
sendMessageCallback (optional)
RoomChatService.SendMessageCallback
Callback with the status of the request
Send Message Callback Arguments
Name
Type
Description
status
RequestStatus
The status of the operation
message
String
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.