Android Room Service - PhenixRTS Docs
Room Service
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.
import android.content.Context;
import com.phenixrts.environment.android.AndroidContext;
import com.phenixrts.pcast.PCast;
import com.phenixrts.room.RoomService;
import com.phenixrts.room.RoomServiceFactory;
// IMPORTANT: Before accessing any of the static factories, make sure the context is passed to Phenix:
final Context context = ...; // e.g. Activity.getApplication();
AndroidContext.setContext(context);
final PCast pcast = ...; // previously obtained
final RoomService roomService = RoomServiceFactory.createRoomService(pcast);
Initializing Parameters
| Name |
Type |
Description |
| pcast (required) |
PCast |
Instantiated PCast™ object. Must already be authenticated |
RoomService
| Name |
Signature |
Returns |
Description |
| leaveRoom |
(callback) |
void |
See Leave a Room |
| getSelf |
() |
Observable of Member) |
Observable of self member |
| getObservableActiveRoom |
() |
Observable of Room) |
Observable of the active room |
Instantiate Self Member Model
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.
import com.phenixrts.common.RequestStatus;
import com.phenixrts.room.Member;
import com.phenixrts.room.MemberRole;
import com.phenixrts.room.RoomService;
final RoomService roomService = ...; // previously obtained
final Member selfMember = roomService.getSelf();
selfMember.getObservableScreenName().setValue("My New Screen Name");
selfMember.getObservableRole().setValue(MemberRole.AUDIENCE);
// Commit changes to self if already in a room
selfMember.commitChanges((RequestStatus status, String message) -> {
if (status == RequestStatus.OK) {
// Successfully updated self
} else {
// Handle error
}
});
To undo uncommitted local changes, use reload:
import com.phenixrts.room.Member;
import com.phenixrts.room.MemberRole;
import com.phenixrts.room.RoomService;
final RoomService roomService = ...; // previously obtained
final Member selfMember = roomService.getSelf();
selfMember.getObservableScreenName().setValue("My New Screen Name");
selfMember.getObservableRole().setValue(MemberRole.AUDIENCE);
// Decided to undo changes
selfMember.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.
import com.phenixrts.room.Member;
import com.phenixrts.room.RoomService;
import com.phenixrts.room.Stream;
import com.phenixrts.room.StreamType;
import com.phenixrts.room.TrackState;
final RoomService roomService = ...; // previously obtained
final Member selfMember = roomService.getSelf();
final Stream selfStream = roomService.createStream(
"http://myuri.stream", StreamType.USER, TrackState.ENABLED, TrackState.ENABLED);
selfMember.getObservableStreams().setValue(new Stream[] {selfStream});
// Now commit changes
Set Self Streams Parameters
| Name |
Type |
Description |
| uri (required) |
String |
Unique identifier for stream. |
| type (required) |
StreamType |
Type of stream - see Stream Types |
| audioState (required) |
TrackState |
State of the audio track - see Stream Track States |
| videoState (required) |
TrackState |
State of the video track - see Stream Track States |
Subscribe to Room Member Streams
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.
import com.phenixrts.common.Disposable;
import com.phenixrts.common.Observable;
import com.phenixrts.common.RequestStatus;
import com.phenixrts.room.Member;
import com.phenixrts.room.Room;
import com.phenixrts.room.RoomService;
import com.phenixrts.room.Stream;
final RoomService roomService = ...; // previously obtained
final Observable<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 updates
final Room activeRoom = observableActiveRoom.getValue();
final Observable<Member[]> observableMembers = activeRoom.getObservableMembers();
final Disposable subscription = observableMembers.subscribe((change) -> {
final Member[] currentMembers = (Member[])change;
for (Member member : currentMembers) {
final Stream[] 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.
import com.phenixrts.common.RequestStatus;
import com.phenixrts.room.Room;
import com.phenixrts.room.RoomService;
final RoomService roomService = ...; // previously obtained
final Room 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.
import com.phenixrts.common.RequestStatus;
import com.phenixrts.room.Room;
import com.phenixrts.room.RoomService;
final RoomService roomService = ...; // previously obtained
roomService.leaveRoom((RoomService roomService, RequestStatus status) -> {
if (status == RequestStatus.OK) {
// Successfully left room, no action required
} else {
// Handle error
}
});
Leave Room Parameters
| Name |
Type |
Description |
| callback (required) |
RoomService.LeaveRoomCallback |
Callback with the status of the request |
Leave Room Callback Arguments
| Name |
Type |
Description |
| roomService |
RoomService |
The room service making the callback |
| status |
RequestStatus |
The status of the operation |
Leave Room Callback Status Codes
| Status |
Description |
| ok |
Leave room succeeded |
| varies |
Leave room failed for other reasons |
Observe Room size
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.
import com.phenixrts.common.Disposable;
import com.phenixrts.room.ImmutableRoom;
final ImmutableRoom room = ... // previously obtained
final Disposable disposable = room.getObservableEstimatedSize().subscribe((change) -> {
final Long currentEstimatedRoomSize = (Long) change;
// E.g. update UI
});
Room Model
The following details technical specifications for the Room, Members, and Streams.
ImmutableRoom
| Name |
Signature |
Returns |
Description |
| getRoomId |
() |
String |
The room ID |
| getObservableAlias |
() |
Observable(of String) |
Observable of room alias |
| getObservableName |
() |
Observable(of String) |
Observable of room name |
| getObservableDescription |
() |
Observable(of String) |
Observable of room description |
| getObservableType |
() |
Observable(of RoomType) |
Observable of room type |
| getObservableMembers |
() |
Observable(of Member[]) |
Observable of array of visible members in the room |
| getObservableBridgeId |
() |
Observable(of String) |
Observable of room bridgeId |
| getObservablePin |
() |
Observable(of String) |
Observable of room pin |
| getObservableEstimatedSize |
() |
Observable(of Long) |
Observable of estimated room size. This is a cumulative count of all members in the room, including audience members |
Room
Room extends ImmutableRoom
| Name |
Signature |
Returns |
Description |
| commitChanges |
(Room.CommitCallback) |
void |
Attempts to update server room model with any changes made locally |
| reload |
() |
void |
Reverts all local changes to the server room model |
Room Types
| Type |
Description |
| RoomType.DIRECT_CHAT |
One to one chat |
| RoomType.MULTI_PARTY_CHAT |
Many to many or few to many chat |
| RoomType.MODERATED_CHAT |
Moderated chat with integrated SIP Bridge for conferencing abilities (join by phone). |
| RoomType.TOWN_HALL |
Chat with a few active participants or presenters and many audience or inactive participants |
| RoomType.CHANNEL |
View only room with a single active member at a time. Broadcast content to many viewers. |
Member
| Name |
Signature |
Returns |
Description |
| getSessionId |
() |
String |
The session ID of the member in the room |
| getObservableRole |
() |
Observable(of MemberRole) |
Observable of member role |
| getObservableState |
() |
Observable(of MemberState) |
Observable of member state |
| getObservableScreenName |
() |
Observable(of String) |
Observable of member screen name |
| getObservableStreams |
() |
Observable(of Stream[]) |
Observable of array of streams belonging to the member |
| getObservableLastUpdate |
() |
Observable(of Date) |
Observable of utc timestamp |
| commitChanges |
(Member.CommitCallback) |
void |
Attempts to update server member model with any changes made locally |
| reload |
() |
void |
Reverts all local changes to the server member model |
Member Roles
| Role |
Description |
| MemberRole.PARTICIPANT |
Member with streams and is visible to all members |
| MemberRole.AUDIENCE |
Member with no streams and is not visible to other members |
| MemberRole.PRESENTER |
Presenter participant member |
| MemberRole.MODERATOR |
Privileged participant member |
Member States
| Role |
Description |
| MemberState.ACTIVE |
Member is active |
| MemberState.PASSIVE |
Member is not active |
| MemberState.HAND_RAISED |
Member is requesting to become active |
| MemberState.INACTIVE |
Member is not away |
| MemberState.OFFLINE |
Member has left the room |
Stream
The stream object may be used to represent any value that will be shared between all members.
| Name |
Signature |
Returns |
Description |
| getUri |
() |
String |
The stream uri (may or may not be associated with phenix stream ID) |
| getType |
() |
StreamType |
The stream type |
| getObservableAudioState |
() |
Observable(of TrackState) |
Observable of stream video state |
| getObservableVideoState |
() |
Observable(of TrackState) |
Observable of stream audio state |
Stream Types
| Type |
Description |
| StreamType.USER |
General purpose stream |
| StreamType.PRESENTATION |
Privileged stream |
| StreamType.AUDIO |
Audio-only stream |
Stream Track States
| State |
Description |
| TrackState.ENABLED |
Track is enabled |
| TrackState.DISABLED |
Track is disabled |
| TrackState.ENDED |
Track has ended |