Set up a room and manage members, streams, and chat. Some typical uses for rooms include:
Broadcast video chats between multiple people - few to many
Large-scale video chat
Conference calls with integrated video chat
Real-time web channels for hosting media content. See View a Channel with the Express API
Town hall meetings
To get started, create a room of the type associated with your need.
Initializing
First you will need to initialize a room service object. This object is used for joining and leaving a room. Also use this object for managing the room you enter (active room), members, and the model of your Self.
Note: PCast™ must be initialized and started when invoking createRoomService so that a valid session ID is present.
Java
importandroid.content.Context;importcom.phenixrts.environment.android.AndroidContext;importcom.phenixrts.pcast.PCast;importcom.phenixrts.room.RoomService;importcom.phenixrts.room.RoomServiceFactory;// 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);finalPCast pcast =...;// previously obtainedfinalRoomService roomService =RoomServiceFactory.createRoomService(pcast);
Initializing Parameters
Name
Type
Description
pcast (required)
PCast
Instantiated PCast™ object. Must already be authenticated
Before entering a room the RoomService must have a valid model of the Self member. The Self member model may be updated at any time by changing observable values and calling commitChanges. See Update Self Model.
Update Self Model
Broadcast local changes of the Self model to all the members in the room. These changes are sent to our server which forwards the changes to all members in the room. This works whether or not you are currently in a room.
Java
importcom.phenixrts.common.RequestStatus;importcom.phenixrts.room.Member;importcom.phenixrts.room.MemberRole;importcom.phenixrts.room.RoomService;finalRoomService roomService =...;// previously obtainedfinalMember selfMember =roomService.getSelf();selfMember.getObservableScreenName().setValue("My New Screen Name");selfMember.getObservableRole().setValue(MemberRole.AUDIENCE);// Commit changes to self if already in a roomselfMember.commitChanges((RequestStatus status, String message) -> {if (status ==RequestStatus.OK) {// Successfully updated self } else {// Handle error }});
To undo uncommitted local changes, use reload:
Java
importcom.phenixrts.room.Member;importcom.phenixrts.room.MemberRole;importcom.phenixrts.room.RoomService;finalRoomService roomService =...;// previously obtainedfinalMember selfMember =roomService.getSelf();selfMember.getObservableScreenName().setValue("My New Screen Name");selfMember.getObservableRole().setValue(MemberRole.AUDIENCE);// Decided to undo changesselfMember.reload();
Update Self Callback Arguments
Name
Type
Description
status
RequestStatus
The status of the operation
message
String
Error message, if applicable
Set Self Streams
The self model must have at least one stream when joining the room as any member role besides Audience.
After entering a room you may use the active room to get the observable members and associated metadata. Here we provide an example for accessing each member's streams whenever the list of members is updated. Remember: Since each observable behaves like a Behavior Rx Subject, your subscriber will always get called back immediately with the current value (in this case the list of members), see Observable.
Java
importcom.phenixrts.common.Disposable;importcom.phenixrts.common.Observable;importcom.phenixrts.common.RequestStatus;importcom.phenixrts.room.Member;importcom.phenixrts.room.Room;importcom.phenixrts.room.RoomService;importcom.phenixrts.room.Stream;finalRoomService roomService =...;// previously obtainedfinalObservable<Room> observableActiveRoom =roomService.getObservableActiveRoom();// For this simple example, we assume that there is an active room.// In a production environment, this can return null if we have not currently joined a room. In that case// you would want to listen as a subscriber on the 'observableActiveRoom' for updatesfinalRoom activeRoom =observableActiveRoom.getValue();finalObservable<Member[]> observableMembers =activeRoom.getObservableMembers();finalDisposable subscription =observableMembers.subscribe((change) -> {finalMember[] currentMembers= (Member[])change;for (Membermember: currentMembers) {finalStream[] currentStreams=member.getObservableStreams().getValue();// Now do something with this member's streams }});// The subscription will remain active for as long as 'subscription' is kept alive or not disposed
Update Room Model
Broadcast local changes of the Room model to all the members in the room. These changes are sent to our server which forwards the changes to all members in the room.
Java
importcom.phenixrts.common.RequestStatus;importcom.phenixrts.room.Room;importcom.phenixrts.room.RoomService;finalRoomService roomService =...;// previously obtainedfinalRoom room =roomService.getObservableActiveRoom().getValue();room.getObservableDescription().setValue("My New Room Description");room.commitChanges((RequestStatus status, String message) -> {if (status ==RequestStatus.OK) {// Successfully updated room } else {// Handle error (`message` may provide more information about what went wrong) }});
Update Room Parameters
Name
Type
Description
callback (required)
Room.CommitCallback
Callback with the status of the request
Update Room Callback Arguments
Name
Type
Description
status
RequestStatus
The status of the operation
message
String
Error message, if applicable
Update Room Callback Status Codes
Status
Description
ok
Update room succeeded
varies
Update room failed for other reasons
Leave a Room
Leave the current active room. Self is not modified.
Subscribe to observable to receive periodic room size updates. The room size corresponds to the total number of members currently in the room, which does include audience members.
This is a so called cold observable, which means that you may not immediately receive an update. It also means that both getValue and setValue methods will cause a failure.
Updates will be provided for as long as the disposable reference is kept alive.