Get Stream Information
The following methods provide stream-related information such as the as the type of the stream, media tracks, state, and so on.
iOS SDK provides the following methods and properties:
- streamId: Provides the Stream ID to identify a stream.
- isLocal: To know if a stream is a local or remote stream.
- publishStreamId: To provide the ID of your local stream.
- streamsByStreamId: To provide the stream information for a Stream ID.
- remoteStreams: To provide the list of remote streams available in a room.
- attachRenderer(): To attach a stream to Player View.
- detachRenderer(): To detach a stream from Player View.
Get Stream ID
The Stream ID is used to identify every stream, be it a local or a remote stream, a canvas stream, or a screen sharing stream. The Stream ID of a stream can be obtained from its streamId
property.
Class: EnxStream
Property: streamId
Verify the Availability of Media Tracks in a Stream
EnxStream
class provides the following methods to check the presence of a particular media track in the stream.
Methods
Method | Description |
---|---|
- (BOOL)hasAudio | To check if the stream includes an audio track. |
- (BOOL)hasVideo | To check if the stream includes a video track. |
- (BOOL)hasData | To check if the stream includes a aata track. |
Sample Code
if ([stream hasVideo] ) {// The Stream has a Video Track in it}// Other methods are also used in the similar manner.
Know if Stream is Local or Remote
The isLocal
property of a stream is used to know if the stream is a local or a remote stream.
Property: isLocal
– BOOL
Sample Code
if (stream.isLocal) {// It's a Local Stream}else {// It's a Remote Stream}
Get Local Stream ID
The publishStreamId
property provides the ID of your local stream published in a room.
Property: NSString publishStreamId
Sample Code
NSString* publishStreamID = room.publishStreamId;
Get Stream by Stream ID
The streamsByStreamId
property provides the stream information for a specific Stream ID.
Property: NSDictionary streamsByStreamId
Sample Code
NSDictionary* streamsDict = room.streamsByStreamId; // Get DictionaryEnxStream* stream = streamsDict[@"StreamID"]; // Get specific stream object
Get the list of Remote Streams
The remoteStreams
property provides the list of remote streams available in a room.
Property: NSArray remoteStreams
Sample Code
NSArray* remoteStreams = room.remoteStreams;
Play a Stream
You can play a local stream and all subscribed remote streams, including screen sharing and canvas streams, within the EnxPlayerView
object. Therefore, you must create an object of the EnxPlayerView
class and attach the stream to Player View using EnxStream.attachRenderer()
method.
To stop playing a stream, detach the stream from Player View by using EnxStream.detachRenderer()
.
Classes:
Class | Description |
---|---|
EnxPlayerView | To initiate a Player View object. |
EnxStream | To attach a stream to the Player View. |
Method: - (void)attachRenderer :(EnxPlayerView*)ObjEnxPlayerView;
: To play a stream.
Parameter: ObjEnxPlayerView
: JSON Object. A Player View object.
Method: - (void)detachRenderer;
: To stop playing a stream.
Sample Code
// To Initialize Local Stream Player View ObjectEnxPlayerView *playerView = [[EnxPlayerView alloc] initLocalView:(CGRect)];// To Initialize Remote Stream Player View Object// EnxPlayerView *playerView = [[EnxPlayerView alloc] initRemoteView:(CGRect)];[stream attachRenderer:PlayerView]; // Attach stream to playerview to play[yourCustomView addSubview:PlayerView]; // Add playerView to your view[stream detachRenderer]; // Detach Renderer to stop playing