Its important to publish your Media Stream into the Room for all others connected users to see and communicate with you. You may have a choice to continue publishing your stream until you exit or you may unpublish and re-publish your Media Stream multiple times within the same session if so desired.

After initializing the stream, you need to publish it in the room so that the other users in the room can see and hear the user.  The methods to publish, unpublish, and close a local stream are explained in this section.

Table of Contents

Publish Local Stream

The EnxRoom.publish() method publishes a local stream in the connected room. 

Method: EnxRoom.publish(LocalStream, PublishOpt, Callback)

Parameters:

  • LocalStream – Initiated Stream Object.
  • PublishOpt – Configurable options for publishing.

Notification Events:

  • stream-added – Notification to everyone in the Room when a new stream is published in the Room.
  • stream-failed – Notification to the Stream publisher when stream publishing fails.
// Configure Optional Publishing Options
var PublishOpt = {
     "minVideoBW":"Number",  
     "maxVideoBW": "Number" 
};

room.publish(localStream, PublishOpt, function(StreamId) {
});

// New Stream in Room Notification
room.addEventListener("stream-added", function(event) {
     if (localStream.getID() === event.stream.getID()) {
         // Your stream published
     } else {
         // Someone else has published
     }
});

room.addEventListener("stream-failed", function(event) {
     // Failed to publish
});

Error Codes / Exceptions

CodeDescription
1170The feature is not enabled because of room configuration or lack of license.

Unpublish Local Stream

The EnxRoom.unpublish() method disconnects the local stream from the room. Unpublishing a stream does not release the device access so that subsequent republishing does not require device-access-permission.  

Method: EnxRoom.unpublish(localStream, Callback)

Parameters:

localStream – Local Stream Object to be unpublished.

Notification:

stream-removed – Notification to everyone in the Room when a Stream is removed from the Room.

room.unpublish(localStream, function(result, error) {
    if (result === undefined) {
        // Failed       
     } else {
        // Unpublished      
     }  
});  

Close Local Stream

The EnxStream.close() method allows you to disconnect the local Stream from the Room similar to the unpublishing process. Closing the Stream leads to the following:

  • If stream has audio and video tracks, it stops capturing media stream from camera & microphone.
  • If the stream is published into the room, it unpublishes the stream.
  • If the stream is being played in Player, it stops playing.

Class: EnxStream

Method: EnxStream.close()

localStream.close();