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, create, and publish to a room
Subscribe to streams of members in a room
Initializing
Java
importandroid.content.Context;importcom.phenixrts.common.RequestStatus;importcom.phenixrts.environment.android.AndroidContext;importcom.phenixrts.express.PCastExpress;importcom.phenixrts.express.PCastExpressFactory;importcom.phenixrts.express.PCastExpressOptions;importcom.phenixrts.express.RoomExpress;importcom.phenixrts.express.RoomExpressFactory;importcom.phenixrts.express.RoomExpressOptions;importcom.phenixrts.pcast.PCastInitializeOptions;// 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);finalPCastExpressOptions pcastExpressOptions =PCastExpressFactory.createPCastExpressOptionsBuilder().withStreamToken("DIGEST:eyJhc...").withUnrecoverableErrorCallback((RequestStatus status, String description) -> {// Best to restart app, or attempt to re-create PCastExpress }).buildPCastExpressOptions();finalRoomExpressOptions roomExpressOptions =RoomExpressFactory.createRoomExpressOptionsBuilder().withPCastExpressOptions(pcastExpressOptions).buildPCastExpressOptions();finalRoomExpress roomExpress =RoomExpressFactory.createRoomExpress(roomExpressOptions);
Join a room and optionally, automatically subscribe to member changes.
Java
importcom.phenixrts.common.RequestStatus;importcom.phenixrts.express.JoinRoomOptions;importcom.phenixrts.express.RoomExpress;importcom.phenixrts.express.RoomExpressFactory;importcom.phenixrts.room.Member;importcom.phenixrts.room.RoomService;finalRoomExpress roomExpress =...;// previously obtainedfinalJoinRoomOptions joinRoomOptions =RoomExpressFactory.createJoinRoomOptionsBuilder().withRoomAlias("myRoom42").buildJoinRoomOptions();roomExpress.joinRoom(joinRoomOptions, (RequestStatus status, RoomService roomService) -> {if (status ==RequestStatus.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:this.roomExpress.joinRoom( joinRoomOptions, (RequestStatus status, RoomService roomService) -> {if (status ==RequestStatus.OK) {// Hold on to roomService reference for as long as you wish to stay in the room } else {// Handle error } }, (Member[] members) -> {// Do something with room members });
Express Join Room Parameters
Name
Type
Description
options (required)
JoinRoomOptions
Options to join room with
joinRoomCallback (required)
RoomExpress.JoinRoomCallback
Function to call on success/failure of joining the room
membersChangedCallback (optional)
RoomExpress.MembersChangedCallback
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.
Java
importandroid.view.SurfaceView;importcom.phenixrts.common.RequestStatus;importcom.phenixrts.express.RoomExpress;importcom.phenixrts.express.RoomExpressFactory;importcom.phenixrts.express.SubscribeToMemberStreamOptions;importcom.phenixrts.room.ImmutableRoom;importcom.phenixrts.room.Member;importcom.phenixrts.room.Stream;importcom.phenixrts.pcast.android.AndroidVideoRenderSurface;finalRoomExpress roomExpress =...;// previously obtainedfinalImmutableRoom room =...;// previously obtainedfinalSurfaceView view =...;// previously obtainedfinalAndroidVideoRenderSurface renderSurface =newAndroidVideoRenderSurface(view.getHolder());// 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.finalMember member =room.getObservableMembers().getValue()[0];finalStream memberStream =member.getObservableStreams().getValue()[0];finalSubscribeToMemberStreamOptions options =RoomExpressFactory.createSubscribeToMemberStreamOptionsBuilder().withStreamToken("DIGEST:eyJhc...").withRenderer(renderSurface).buildSubscribeToMemberStreamOptions();roomExpress.subscribeToMemberStream( memberStream, options, (status, subscriber, renderer) -> {if (status !=RequestStatus.OK) {// Handle subscribe errorreturn; }// Important: Store subscriber reference, otherwise we will stop subscription immediately://currentSubscriber = subscriber; });
Optional renderer if renderer was enabled, else nil
Publish to a Room
Publish local media to a room. An error will be returned if a room corresponding to the Room Options passed does not exist. If you have not entered the room via joinRoom or publishToRoom methods then a model for Self will be created.
Java
importandroid.view.SurfaceView;importcom.phenixrts.common.RequestStatus;importcom.phenixrts.express.PCastExpressFactory;importcom.phenixrts.express.PublishOptions;importcom.phenixrts.express.PublishToRoomOptions;importcom.phenixrts.express.RoomExpress;importcom.phenixrts.express.RoomExpressFactory;importcom.phenixrts.pcast.DeviceCapability;importcom.phenixrts.pcast.FacingMode;importcom.phenixrts.pcast.RendererOptions;importcom.phenixrts.pcast.UserMediaOptionsimport com.phenixrts.pcast.android.AndroidVideoRenderSurface;importcom.phenixrts.room.MemberRole;importcom.phenixrts.room.RoomOptions;importcom.phenixrts.room.RoomServiceFactory;importcom.phenixrts.room.StreamType;finalRoomExpress roomExpress =...;// previously obtainedfinalSurfaceView view =...;// previously obtainedfinalAndroidVideoRenderSurface renderSurface =newAndroidVideoRenderSurface(view.getHolder());finalUserMediaOptions mediaConstraints =newUserMediaOptions();// Customize constraints if neededfinalPublishOptions publishOptions =PCastExpressFactory.createPublishOptionsBuilder().withStreamToken("DIGEST:eyJhc...").withMediaConstraints(mediaConstraints).withPreviewRenderer(renderSurface).buildPublishOptions();// Using RoomOptions means that the room may or may not already exist.// If the room ID is known in advance, it is recommended to use `withRoomId` instead// of `withRoomOptions` when assembling the `PublishToRoomOptions` belowfinalRoomOptions roomOptions =RoomServiceFactory.createRoomOptionsBuilder().withName("MyAwesomeRoom").buildRoomOptions();finalPublishToRoomOptions localPublishToRoomOptions =RoomExpressFactory.createPublishToRoomOptionsBuilder().withStreamType(StreamType.USER).withMemberRole(MemberRole.PARTICIPANT).withRoomOptions(roomOptions).withPublishOptions(publishOptions).buildPublishToRoomOptions();roomExpress.publishToRoom( localPublishToRoomOptions, (publishStatus, roomService, publisher, previewRenderer) -> {if (publishStatus !=RequestStatus.OK) {// Handle channel publish errorreturn; }// Important: Store publisher reference, otherwise we will stop publishing again immediately: currentPublisher = publisher; });
Underlying resources are kept alive for as long as you hold any references to any of the returned objects (room service, subscriber, renderer) an do not call close on them. Once those references as well as any reference to the room express instance itself have been released (or close has been called), all underlying resources will be automatically cleaned up and released.