Skip to content
This repository was archived by the owner on Sep 16, 2020. It is now read-only.

Room Service

Frank Tarsillo edited this page Jan 29, 2017 · 13 revisions

Similar to the chat service, the Room Service provides real time support for chat room conversations using Room objects and listeners to receive events. When the service is instantiated as part of the SymphonyClient it will automatically detect room updates that the BOT user is a member of. As a result the service will create, cache and populate the Room object with associated room details and membership. This is then followed up with a notification event to all registered service callbacks that a new Chat room has been created.

In addition, the service provides callbacks for various room events such as new member joins...etc

The room service is accessible through the SymphonyClient

//From SymphonyClient symClient...
//...
symClient.getRoomService();

Room Service events

The RoomServiceListener can be registered to the service in support all room event callbacks.

 class aClass implements RoomServiceListener{
 ...
 SymphonyClient symClient...

 symClient.getRoomService().addRoomServiceListener(this);
 ...

Events

New room

Service will detect room conversations, cache (lazy) a Room object representing this room and issue new room event. The consumer of this event then has the opportunity to register the RoomListener to listen for room messages.

void onNewRoom(Room room);

Room deactivation

Notification event when a room is deactivated by an owner.

void onRoomDeactivatedMessage(RoomDeactivatedMessage roomDeactivatedMessage);

Room reactivation

Notification event when a room is reactivated

void onRoomReactivatedMessage(RoomReactivatedMessage roomReactivatedMessage);

Room member promoted

Notification event when a room member is promoted

void onRoomMemberPromotedToOwnerMessage(RoomMemberPromotedToOwnerMessage roomMemberPromotedToOwnerMessage);

Room member demotion

Notification event when a room member is demoted

void onRoomMemberDemotedFromOwnerMessage(RoomMemberDemotedFromOwnerMessage roomMemberDemotedFromOwnerMessage);

Room update

Notification event when a room property (definition) is updated.

void onRoomUpdatedMessage(RoomUpdatedMessage roomUpdatedMessage);

User joined room

Notification event when a user joins a room

void onUserJoinedRoomMessage(UserJoinedRoomMessage userJoinedRoomMessage);

User left room

Notification event when user leaves a room

void onUserLeftRoomMessage(UserLeftRoomMessage userLeftRoomMessage);

Room creation

Notification event when a room is created.

void onRoomCreatedMessage(RoomCreatedMessage roomCreatedMessage);

All room messages

Notification of all messages related to rooms. It is highly recommended to register individual RoomListener interfaces to Room objects to listen to specific room messages.

void onMessage(SymMessage symMessage);

Room Object

The Room object provides a structure defining properties, membership and registered listeners (RoomListener) to detect new message events. Room objects can be constructed manually or automatically generated through service detection. Again, room objects require registration of RoomListener interfaces for the room service to generate callback messages (SymMessage).

Manually create room, Register, Send message, listen for messages

 class aClass implements RoomListener{
 ...
        
 Room room = new Room();
 //Room stream can be found through search 
 room.setStream(roomStream);  
 room.setId(stream.getId());
 
 //Add a listener to the room for new incoming message events
 room.addListener(this);

 //You have to join the room in order for the service to issue new message events
 //Note this is "join" vs "add" or "create".  Logically you are joining the room conversation. 
 symClient.getRoomService().joinRoom(room);

 //Send a message to the room.
 symClient.getMessageService().sendMessage(room, aMessage);

 //Implementation of interface method to listen for new messages
 void onChatMessage(SymMessage message){

 }
 ...

Creating a room

The SymRoomAttributes object can be used to define room attributes required to create a room from the service. The room service can then be called to create and return a fully populated room object. It's important to note that the returned object is not registered with the room service nor does it have any listeners registered. The following example shows the creation and registration of the room to the service.

//Define the room to create
SymRoomAttributes roomAttributes = new SymRoomAttributes();
roomAttributes.setName("TEST ROOM 1");
roomAttributes.setDescription("SJC Test room creation");
roomAttributes.setDiscoverable(true);
roomAttributes.setPublic(true);

//Create the room
Room room = symClient.getRoomService().createRoom(roomAttributes);

//Add the listener
symClient.getRoomService().addRoomServiceListener(this);

//Join the room 
symClient.getRoomService().joinRoom(room);

Searching for a room

The SJC provides basic search queries through the StreamsClient. Construct a search using the SymRoomSearchCriteria object, which defines the criteria to query/filter on. Executed queries return a result set in the form of SymRoomSearchResults, which provide a list of SymRoomDetail objects that represent rooms found.

 //Construct and define search criteria
 SymRoomSearchCriteria symRoomSearchCriteria = new SymRoomSearchCriteria();
  
 symRoomSearchCriteria.setQuery(System.getProperty("TEST ROOM 1"));

 //Execute search
 SymRoomSearchResults symRoomSearchResults = symClient.getStreamsClient().roomSearch(symRoomSearchCriteria, 0, 100);

 //Iterate through results to identify rooms found
 for (SymRoomDetail symRoomDetail : symRoomSearchResults.getRooms()) {

  logger.info("Found room {}: {}", symRoomDetail.getRoomAttributes().getName(), symRoomDetail.getRoomSystemInfo().getId());


  }

Changing room membership

Adding and removing members from rooms can be managed using the RoomMembershipClient.

...
String roomId = room.getId();

//Add member to room
symClient.getRoomMembershipClient().addMemberToRoom(roomId,member1);

//Remove member from room
symClient.getRoomMembershipClient().removeMemberFromRoom(roomId,member2);

Next Topic: Presence Service

Clone this wiki locally