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
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((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().withStreamToken("stream token").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; });
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 dispose on them.
Once those references as well as any reference to the room express instance itself have been
released (or dispose has been called), all underlying resources will be automatically cleaned up
and released.