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.
Note: PhenixPCast must be initialized and started when invoking createRoomService so that a valid session ID is present.
Before entering a room the PhenixRoomService 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.
Swift
importPhenixSdklet roomService: PhenixRoomService = ... // previously obtainedlet selfMember = roomService.getSelf()selfMember.getObservableScreenName().setValue("My New Screen Name")selfMember.getObservableRole().setValue(NSNumber.init(value: PhenixMemberRole.audience.rawValue))// Commit changes to self if already in a roomselfMember.commitChanges({ (status: PhenixRequestStatus, message: String?) inif status == .ok {// Successfully updated self } else {// Handle error } })
To undo uncommitted local changes, use reload:
Swift
importPhenixSdklet roomService: PhenixRoomService = ... // previously obtainedlet selfMember = roomService.getSelf()selfMember.getObservableScreenName().setValue("My New Screen Name")selfMember.getObservableRole().setValue(NSNumber.init(value: PhenixMemberRole.audience.rawValue))// Decided to undo changesselfMember.reload()
Update Self Callback Arguments
Name
Type
Description
status
PhenixRequestStatus
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.
Swift
importPhenixSdklet roomService: PhenixRoomService = ... // previously obtainedlet observableActiveRoom = roomService.getObservableActiveRoom()!// For this simple example, we assume that there is an active room, hence we can force un-wrap.// In a production environment, this can return nil if we have not currently joined a room. In that case// you would want to listen as a subscriber on the 'observableActiveRoom' for updateslet activeRoom = observableActiveRoom.getValue()!let observableMembers = activeRoom.getObservableMembers()!let subscription = observableMembers.subscribe({ (change) inlet currentMembers = change?.value as! [PhenixMember]for member in currentMembers {let currentStreams = member.getObservableStreams().getValue() as! [PhenixStream]// Now do something with this member's streams }})// The subscription will remain active for as long as 'subscription' is kept alive
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.
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.