Web 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 creating, joining, and leaving a room. As well, use this object for managing the room you enter (active room), members, and the model of your Self.
var roomService = new sdk.RoomService(pcast);
Initializing Parameters
| Name |
Type |
Description |
| pcast (required) |
[object PCast] |
Instantiated PCast™ object. Must already be authenticated |
[object RoomService]
| Name |
Signature |
Returns |
Description |
| start |
(role, screenName) |
void |
See Instantiate Self Member Model |
| getRoomInfo |
(roomId, alias, getRoomInfoCallback) |
[[object Room]](/content/docs/sdk_ref/web/room/#object-room/index.html) |
See Get Room Info |
| createRoom |
(room, createRoomCallback) |
[[object Room]](/content/docs/sdk_ref/web/room/#object-room/index.html) |
See Create a Room |
| enterRoom |
(roomId, alias, enterRoomCallback) |
[[object Room]](/content/docs/sdk_ref/web/room/#object-room/index.html) |
See Join a Room |
| leaveRoom |
(leaveRoomCallback, isForceLeaveRoom) |
void |
See Leave a Room |
| getRoomChatService |
() |
[[object ChatService]](/content/docs/sdk_ref/web/chat/#object-chatservice/index.html) |
Returns instantiated chat service associated with active room |
| getSelf |
() |
Observable(of [[object Member]](/content/docs/sdk_ref/web/room/#object-member/index.html)) |
Observable of self member |
| getObservableActiveRoom |
() |
Observable(of [[object Room]](/content/docs/sdk_ref/web/room/#object-room/index.html)) |
Observable of the active room |
Instantiate Self Member Model
Before entering a room the [object RoomService] must have a model of the member you would like to join as, or Self. The Self member model may be updated at any time by changing observable values and calling commitChanges. See Updating Self Model.
roomService.start(role, screenName);
Instantiate Self Parameters
| Name |
Type |
Description |
| role (required) |
String |
Self member role - see Member Roles |
| screenName (required) |
String |
Self member screen name |
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.
var self = roomService.getSelf();
self.getObservableScreenName.setValue('My New Screen Name');
// Commit changes to self if already in a room
self.commitChanges(function commitChangesCallback(error, response) {
if (error) {
// Handle error
}
if (response.status !== 'ok' && response.status !== 'not-in-room') {
// Handle error
}
if (response.status === 'not-in-room') {
// Changes not committed. Enter a room and the self model will automatically be committed.
}
if (response.status === 'ok') {
// Successfully updated self
}
});
Update Self Callback Arguments
| Name |
Type |
Description |
| status |
String |
The status of the operation |
Update Self Callback Status Codes
| Status |
Description |
| ok |
Update self succeeded |
| not-in-room |
Update self failed. Not currently in a room - Join a room and changes will automatically be committed |
| varies |
Update self failed for other reasons |
Set Self Streams
The self model must have at least one stream when joining the room as any member role besides Audience.
var self = roomService.getSelf();
var selfStream = {
uri: publisher.getStreamId(),
type: 'User',
audioState: 'TrackEnabled',
videoState: 'TrackEnabled',
};
self.setStreams([selfStream]);
Set Self Parameters
| Name |
Type |
Description |
| uri (required) |
String |
Unique identifier for stream. |
| type (required) |
String |
Type of stream - see Stream Types |
| audioState (required) |
String |
State of the audio track - see Stream Track States |
| videoState (required) |
String |
State of the video track - see Stream Track States |
Get Room Info
Get room info with the provided room details without joining the room.
roomService.getRoomInfo(
roomId,
alias,
function getRoomInfoCallback(error, response) {
if (error) {
// Handle error
}
if (response.status !== 'ok') {
// Handle error
}
// Successfully got room info
if (response.status === 'ok' && response.room) {
// Do something with room
}
}
);
Get Room Info Parameters
| Name |
Type |
Description |
| roomId (required) |
String |
ID of the room |
| alias (optional) |
String |
Alternative to roomId - alias of the room |
| getRoomInfoCallback (required) |
Function |
Callback with the status of the request and the room model |
Get Room Info Callback Arguments
| Name |
Type |
Description |
| status |
String |
The status of the operation |
| room |
[[object Room]](/content/docs/sdk_ref/web/room/#object-room/index.html) |
Immutable room object |
Get Room Info Callback Status Codes
| Status |
Description |
| ok |
Get room info succeeded |
| not-found |
Get room info failed. Room does not exist - verify room data or create the room |
| varies |
Get room info failed for other reasons |
Create a Room (deprecated)
Creation of Rooms from client SDKs is deprecated. Rooms should be created by the backend using the REST API.
Create a room with the provided details.
roomService.createRoom(room, function createRoomCallback(error, response) {
if (error) {
// Handle error
}
if (response.status === 'already-exists') {
// No action required
}
if (response.status !== 'ok') {
// Handle error
}
// Successfully created room
if (response.status === 'ok' && response.room) {
// Do something with room
}
});
Create Room Parameters
| Name |
Type |
Description |
| room (required) |
Object |
Values of the room to create - See Room Options |
| getRoomInfoCallback (required) |
Function |
Callback with the status of the request and the room model |
Room Options
| Name |
Type |
Description |
| name (required) |
String |
Room Name |
| type (required) |
String |
Room Type |
| alias (Optional) |
String |
Room Alias |
| description (Optional) |
String |
Description of the Room |
Create Room Callback Arguments
Create Room Callback Status Codes
| Status |
Description |
| ok |
Create room succeeded |
| already-exists |
Create room failed. Room already exists - verify room data and either join or create a different room |
| varies |
Create room failed for other reasons |
Join a Room
Join a room with the Self model. After successfully joining a room that room becomes the active room and can be returned via the getObservableActiveRoom method.
roomService.enterRoom(
roomId,
alias,
function enterRoomCallback(error, response) {
if (error) {
// Handle error
}
if (response.status === 'not-found') {
// Handle room not found - createRoom
}
if (response.status !== 'ok') {
// Handle error
}
// Successfully entered room
if (response.status === 'ok' && response.room) {
// Do something with room model - now the active room
}
}
);
Join Room Parameters
| Name |
Type |
Description |
| roomId (required) |
String |
ID of the room |
| alias (optional) |
String |
Alternative to roomId - alias of the room |
| enterRoomCallback (required) |
Function |
Callback with the status of the request and the room model |
Join Room Callback Arguments
| Name |
Type |
Description |
| status |
String |
The status of the operation |
| room |
[[object Room]](/content/docs/sdk_ref/web/room/#object-room/index.html) |
Mutable room object |
Join Room Callback Status Codes
| Status |
Description |
| ok |
Join room succeeded |
| not-found |
Join room failed. Room does not exist - create room first |
| varies |
Join room failed for other reasons |
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 parsing the stream ID associated with the member stream's uri.
var observableActiveRoom = roomService.getObservableActiveRoom();
var activeRoom = observableActiveRoom.getValue();
var membersObservable = activeRoom.getObservableMembers();
var pcastStreamURIPrefix = 'pcast://phenixp2p.com/';
membersObservable.subscribe(function (members) {
members.forEach(function (member) {
var memberStreams = member.getObservableStreams().getValue();
memberStreams.forEach(function (stream) {
// Subscribe if its a PCast stream
if (stream.uri.indexOf(pcastStreamURIPrefix) === 0) {
var streamId = stream.uri.substring(
pcastStreamURIPrefix.length,
stream.uri.length
);
// subscribe with pcast.subscribe
}
});
});
});
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.
var room = roomService.getObservableActiveRoom().getValue();
room.getObservableDescription().setValue('My New Room Description');
// Commit changes to self if already in a room
room.commitChanges(function commitChangesCallback(error, response) {
if (error) {
// Handle error
}
if (response.status !== 'ok' && response.status !== 'not-in-room') {
// Handle error
}
if (response.status === 'not-in-room') {
// Changes not committed. Enter the room and then re-submit
}
if (response.status === 'ok') {
// Successfully updated room
}
});
Update Room Parameters
| Name |
Type |
Description |
| commitChangesCallback (required) |
Function |
Callback with the status of the request |
Update Room Callback Arguments
| Name |
Type |
Description |
| status |
String |
The status of the operation |
Update Room Callback Status Codes
| Status |
Description |
| ok |
Update room succeeded |
| not-in-room |
Update room failed. Not currently in a room - Join a room first |
| varies |
Update room failed for other reasons |
Leave a Room
Leave the current active room. Self is not modified.
roomService.leaveRoom(function leaveRoomCallback(error, response) {
// No action required
});
Setting isForceLeaveRoom to false will delay the response to the callback until the backend confirms that the client has left the room.
const doNotForcefullyLeaveRoom = false;
roomService.leaveRoom(function leaveRoomCallback(error, response) {
if (error) {
// Handle error
}
if (response.status === 'not-in-room') {
// Do nothing
}
if (response.status !== 'ok') {
// Handle error
}
// Successfully left room
if (response.status === 'ok') {
// No action required
}
}, doNotForcefullyLeaveRoom);
Leave Room Parameters
| Name |
Type |
Description |
| leaveRoomCallback (required) |
Function |
Callback with the status of the request |
| isForceLeaveRoom (optional) |
Boolean |
Indicates whether to skip waiting for confirmation. If isForceLeaveRoom is true then the leave request is sent and no response from backend is waited upon. By default isForceLeaveRoom is true. |
Leave Room Callback Arguments
| Name |
Type |
Description |
| status |
String |
The status of the operation |
Update Room Callback Status Codes
| Status |
Description |
| ok |
Leave room succeeded |
| not-in-room |
Leave room failed. Not currently in a room. Do nothing |
| varies |
Leave room failed for other reasons |
Room Model
The following details technical specifications for the Room, Members, and Streams.
[object Room]
| 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 string) |
Observable of room type |
| getObservableMembers |
() |
Observable(of array) |
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 |
| toJson |
() |
object |
Returns room object with current observable values |
| commitChanges |
() |
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 |
| DirectChat |
One to one chat |
| MultiPartyChat |
Many to many or few to many chat |
| ModeratedChat |
Moderated chat with integrated SIP Bridge for conferencing abilities (join by phone). |
| TownHall |
Chat with a few active participants or presenters and many audience or inactive participants |
| Channel |
View only room with a single active member at a time. Broadcast content to many viewers. |
[object Member]
| Name |
Signature |
Returns |
Description |
| getSessionId |
() |
string |
The session ID of the member in the room |
| getObservableRole |
() |
Observable(of string) |
Observable of member role |
| getObservableState |
() |
Observable(of string) |
Observable of member state |
| getObservableScreenName |
() |
Observable(of string) |
Observable of member screen name |
| getObservableStreams |
() |
Observable(of array) |
Observable of array of streams belonging to the member |
| getObservableLastUpdate |
() |
Observable(of number) |
Observable of utc timestamp |
| getLastUpdate |
() |
Number |
Current last update value of the member |
| setStreams |
(streams) |
void |
Set member streams. To be used only on self member model |
| toJson |
() |
object |
Returns member object with current observable values |
| commitChanges |
() |
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 |
| Participant |
Member with streams and is visible to all members |
| Audience |
Member with no streams and is not visible to other members |
| Presenter |
Presenter participant member |
| Moderator |
Privileged participant member |
Member States
| Role |
Description |
| Active |
Member is active |
| Passive |
Member is not active |
| HandRaised |
Member is requesting to become active |
| Inactive |
Member is not active |
| Offline |
Member has left the room |
[object Stream]
The stream object represent any stream resource that will be shared between all members. The simplest configuration would be to use a PCast™ StreamId as the streamUri. This associates streams published locally to the member and enables other room members to subscribe to that stream. See Subscribe to Room Member Streams.
| Name |
Signature |
Returns |
Description |
| getUri |
() |
string |
The stream uri (may or may not be associated with phenix stream ID) |
| getType |
() |
string |
The stream type |
| getObservableAudioState |
() |
Observable(of string) |
Observable of stream video state |
| getObservableVideoState |
() |
Observable(of string) |
Observable of stream audio state |
Stream Types
| Type |
Description |
| User |
General purpose stream |
| Presentation |
Presentation stream |
| Audio |
Audio-only stream |
Stream Track States
| State |
Description |
| TrackEnabled |
Track is enabled |
| TrackDisabled |
Track is disabled |
| TrackEnded |
Track has ended |