Handle a Local Stream
The iOS SDK provides the following methods to handle a local stream:
- switchCameraPreview(): To switch Camera Feed preview.
- publish(): To publish a local stream in a connected room.
- unpublish(): To disconnect the local stream from a room.
- switchCamera(): To switch between rear and front camera.
- switchMediaDevice(): To switch the audio source of a published stream to an alternate microphone.
- muteSelfAudio(): To mute/unmute the audio of a local stream.
- muteSelfVideo(): To mute/unmute the video of a local stream.
Switch Camera preview
This is to switch between Camera Feed to preview.
Class: EnxStream
Method: - (void)switchCameraPreview;
Sample Code
[stream switchCameraPreview];
Publish a Local Stream
It is important to publish your media stream into the room for other connected users to see and communicate with you. You can continue publishing your stream until you exit, or unpublish and republish your media stream multiple times within the same session if required.
After initializing the stream, you need to publish it in the room so that other users in the room can see and hear the user on this stream.
The EnxRoom.publish()
method publishes a local stream in the connected room.
Class: EnxRoom
Method: - (void)publish:(EnxStream *)stream;
Parameter: stream
: JSONObject. Initiated stream Object.
Delegate Methods
Delegate Method | Description |
---|---|
\- room:didPublishStream: | Acknowledgment to the stream publisher when the stream is published. |
\- room:didAddedStream: | Notification to everyone in a room when a new stream is published in the room. |
Sample Code
[room publish:localStream];- (void)room:(EnxRoom *)room didPublishStream:(EnxStream *)stream{// Your stream is published}-(void)room:(EnxRoom *)room didAddedStream:(EnxStream *)stream{// Announcement of a new stream in the Room// You may subscribe to the stream}
Error Codes and Exceptions
Code | Description |
---|---|
5013 | Failed to publish stream |
5015 | Unable to publish a stream without audio, video, and data. |
5016 | Unable to publish a stream with illegible attributes. |
5022 | Failed to publish stream because Floor Access not received in lecture mode room. |
5023 | The stream has already been published. |
5024 | Repeated publish() call while stream Publishing is in process. |
5025 | Failed to publish stream because publish() call is made on a Remote stream. |
1170 | The current subscription doesn't support the publishing of stream. |
Unpublish a Local Stream
The EnxRoom.unpublish()
method disconnects the local stream from the room. Unpublishing a stream does not release the device access, so subsequent republishing does not require device-access permission.
Class: EnxRoom
Method: - (void)unpublish;
Delegate Method: – room:didRemovedStream:
: Notification to everyone in the Room when a stream is removed from the Room.
Error Codes and Exceptions
Code | Description |
---|---|
5029 | Repeated unpublish call made while the previous request is in process. |
5030 | Non-Contextual use of method when the user tries to unpublish a stream before publishing it. |
Switch Camera, Microphone, and Speaker
The following APIs allow you to switch to alternate Media Devices after publishing stream, thus facilitating a switch on the fly.
Switch between Rear and Front Camera
The EnxStream.switchCamera()
method allows you to switch between the Rear and Front Camera as a source for the published stream.
Class: EnxStream
Method: - (NSException*) switchCamera;
Sample Code
[localstream switchCamera];
Error Codes and Exceptions
Code | Description |
---|---|
5021 | Unable to switch Camera in audio-only call mode. |
5097 | Unable to switch Camera in a Chat-Only Room. Non-Contextual Method Call. |
Switch to Alternate Microphone
The EnxRoom.switchMediaDevice()
method is used to switch the audio source of the published stream to an alternate Microphone. This method requires the audio device's name to switch to, which needs to be retrieved using EnxRoom.getDevices()
method.
Class: EnxRoom
Method: – (void)switchMediaDevice:(NSString *)mediaName
Parameter: mediaName
: String. Target Microphone Device Name.
Delegate Method: \- didNotifyDeviceUpdate:
Acknowledgment sent with the new audio Device ID after audio Device update is complete.
Sample Code
[room switchMediaDevice:@"mediaName"];-(void)didNotifyDeviceUpdate:(NSString *)updates{// updates carry new device name}
Mute or Unmute Audio in a Stream
The EnxStream.muteSelfAudio()
method is used to mute/unmute the audio of the local stream.
Class: EnxStream
Method: - (void) muteSelfAudio:(BOOL)isMuted;
Parameter: isMuted
: Boolean. true
- To mute audio. false
- To unmute audio.
Callbacks
Callback | Description |
---|---|
\- didRemoteStreamAudioMute: | Notification to everyone in the Room when a user mutes self audio. |
\- didRemoteStreamAudioUnMute: | Notification to everyone in the Room when a user unmutes self audio. |
`- didAudioEvent: | Acknowledgment to the user when self audio is muted/unmuted. |
Sample Code
[localStream muteSelfAudio:true]; // To mute audio of local stream[localStream muteSelfAudio:false]; // To unmute audio of local stream// This delegate method to self that audio is muted/unmuted.-(void)didAudioEvent:(NSDictionary *)data{//data is { "msg":"Audio On", "result":0 }}// This delegate method is to announce in the Room that a user// has muted his audio-(void)stream:(EnxStream *)stream didRemoteStreamAudioMute:(NSArray *)data{/* data is[ {"result":0,"clientId":"XXX","msg":"user muted audio"},"<null>"]*/}// This delegate method is to announce in the Room that a user// has unmuted his audio-(void)stream:(EnxStream *)stream didRemoteStreamAudioUnMute:(NSArray *)data{/* data is[ {"result":0,"clientId":"XXX","msg":"user unmuted audio"},"<null>"]*/}
Error Codes and Exceptions
Code | Description |
---|---|
5058 | Repeated muteSelfAudio() call made while a previous mute request is in process. |
5059 | Repeated muteSelfAudio() call made while a previous unmute request is in process. |
5060 | Repeated muteSelfAudio() call made after audio has been muted already. |
5061 | Trying to unmute audio without muting it first. |
5062 | Unable to unmute audio as audio hard-muted by the moderator. |
Note: In case of an error, <null>
is received at the first index and error info at the second index.
Mute or Unmute Video in a Stream
The EnxStream.muteSelfVideo()
method is used to mute/unmute the video of a local stream.
Class: EnxStream
Method: - (void) muteSelfVideo:(BOOL)isMuted;
Parameter: isMuted
: Boolean. true
: To mute the video. false
: To unmute the video.
Callbacks
Callback | Description |
---|---|
\- didRemoteStreamVideoMute: | Notification to everyone in the room when a user mutes self video. |
\- didRemoteStreamVideoUnMute: | Notification to everyone in the room when a user unmutes self video. |
\- didVideoEvent: | Acknowledgment to a user when the user's video is muted/unmuted. |
Sample Code
[localStream muteSelfVideo:true]; // To mute video of local stream.[localStream muteSelfVideo:false]; // To unmute video of local stream.// This delegate method to self. video is muted/unmuted.-(void)didVideoEvent:(NSDictionary *)data{//data is { "msg":"Video On", "result":0 }}// This delegate method is to announce in the Room that a user// has muted his video-(void)stream:(EnxStream *)stream didRemoteStreamVideoMute:(NSArray *)data{/* data is[ {"result":0,"clientId":"XXX","msg":"user muted video"},"<null>"]*/}// This delegate method is to announce in the Room that a user// has unmuted his video-(void)stream:(EnxStream *)stream didRemoteStreamVideoUnMute:(NSArray *)data{/* data is[ {"result":0,"clientId":"XXX","msg":"user unmuted video"},"<null>"]*/}
Error Codes and Exceptions
Code | Description |
---|---|
5020 | Unable to process muteSelfVideo() when the user has denied camera permission. |
5071 | Repeated muteSelfVideo() call made when a previous request is in process. |
5063 | Repeated muteSelfVideo() call made when the video has already been muted. |
5064 | Repeated muteSelfVideo() call made when the video has already been unmuted. |
5065 | When a user tries to unmute a video without muting it first. Non-contextual method call. |
5066 | Unable to unmute the video when the video is hard-muted by the moderator. |
5070 | Unable to unmute the video in a audio-only call mode. |
Note: In case of error, <null>
is received at the first index and error info at the second index.