Single-step configuration based API for setting up a room - a solution for all your other streaming applications including Group Broadcast, Group Chat, and One to One Chat. The Room Express extends the lower-level Room Service API to provide easy solutions to:
Join and publish to a room
Subscribe to streams of members in a room
Initializing
Swift
importPhenixSdklet pcastExpressOptions = PhenixPCastExpressFactory.createPCastExpressOptionsBuilder(unrecoverableErrorCallback: { status, errorDescription in// Best option is to try rebuilding the ChannelExpress instance and/or quit your app }) .buildPCastExpressOptions()let roomExpressOptions = PhenixRoomExpressFactory.createRoomExpressOptionsBuilder() .withPCastExpressOptions(pcastExpressOptions) .buildRoomExpressOptions()let roomExpress = PhenixRoomExpressFactory.createRoomExpress(roomExpressOptions)
Join a room and optionally, automatically subscribe to member changes.
Swift
importPhenixSdklet roomExpress: PhenixRoomExpress = ... // previously obtainedlet joinRoomOptions = PhenixRoomExpressFactory.createJoinRoomOptionsBuilder() .withStreamToken("stream token") .buildJoinRoomOptions()roomExpress.joinRoom(joinRoomOptions, { (status: PhenixRequestStatus, roomService: PhenixRoomService?) inif status == .ok {// Hold on to roomService reference for as long as you wish to stay in the room } else {// Handle error } })// With optional member update notification:roomExpress.joinRoom( joinRoomOptions, { (status: PhenixRequestStatus, roomService: PhenixRoomService?) inif status == .ok {// Hold on to roomService reference for as long as you wish to stay in the room } else {// Handle error } }, { (members: [PhenixMember]?) in// Do something with room members })
Express Join Room Parameters
Name
Type
Description
options (required)
PhenixJoinRoomOptions
Options to join room with
joinRoomCallback (required)
Function
Function to call on success/failure of joining the room
membersChangedCallback (optional)
Function
Function to call on when the participant members in the room changes. Returns array of Members. Callback is guaranteed to be called at least once when room is joined.
Subscribe to a room member's stream and automatically handle audio and video state changes.
Swift
importPhenixSdklet roomExpress: PhenixRoomExpress = ... // previously obtainedlet room: PhenixImmutableRoom = ... // previously obtainedlet renderLayer: CALayer = ... // previously obtained// Just an example showing how to get a stream from a member.// In a real-world app you would want to subscribe to the room-members-observable on the room// to receive updates when the list of members changes, and then subscribe to the streams-observable// on each member to access their streams.let member = room.getObservableMembers().getValue()[0] as! PhenixMemberlet memberStream = member.getObservableStreams().getValue[0] as! PhenixStreamlet options = PhenixRoomExpressFactory.createSubscribeToMemberStreamOptionsBuilder() .withStreamToken("DIGEST:eyJhc...") .withRenderer(renderLayer) .buildSubscribeToMemberStreamOptions()roomExpress.subscribe(toMemberStream: memberStream, options, { [weakself] (status: PhenixRequestStatus,subscriber: PhenixExpressSubscriber?,renderer: PhenixRenderer?) inguard status == .ok, let strongSelf = selfelse {// Handle subscribe errorreturn }// Important: Store subscriber reference, otherwise we will stop subscription immediately: strongSelf.currentSubscriber = subscriber })
Underlying resources are kept alive for as long as you hold any references to any of the returned objects (room service, subscriber, renderer). Once those references as well as any reference to the room express instance itself have been released, all underlying resources will be automatically cleaned up and released.