Suggestions

close search

Back to Basic Video Chat Overview

Basic Video Chat Step 5: Publishing a stream to the session

  1. 1
    Basic Video Chat Step 1:
    Setting up the test web service
  2. 2
    Basic Video Chat Step 2:
    Configuring and testing the app
  3. 3
    Basic Video Chat Step 3:
    Initializing an OpenTok session
  4. 4
    Basic Video Chat Step 4:
    Connecting to the session
  5. 5
    Basic Video Chat Step 5:
    Publishing a stream to the session
  6. 6
    Basic Video Chat Step 6:
    Subscribing to audio-video streams

Upon successfully connecting to the OpenTok session (see the previous section), the application initializes an OpenTok Publisher object and publishes an audio-video stream to the session. This is done inside the completion handler for the connect() method, since you should only publish to the session once you are connected to it.

The Publisher object is initialized as shown below. The OT.initPublisher() method takes three optional parameters:

var publisherOptions = {
  insertMode: 'append',
  width: '100%',
  height: '100%'
};
var publisher = OT.initPublisher('publisher', publisherOptions, function(error) {
  if (error) {
    console.log('There was an error initializing the publisher: ', error.name, error.message);
    return;
  }
  session.publish(publisher);
});

Once the Publisher object is initialized, we publish to the session using the publish() method of the Session object:

session.publish(publisher);
Got it! Go to step 6
  1. 1
    Basic Video Chat Step 1:
    Setting up the test web service
  2. 2
    Basic Video Chat Step 2:
    Configuring and testing the app
  3. 3
    Basic Video Chat Step 3:
    Initializing an OpenTok session
  4. 4
    Basic Video Chat Step 4:
    Connecting to the session
  5. 5
    Basic Video Chat Step 5:
    Publishing a stream to the session
  6. 6
    Basic Video Chat Step 6:
    Subscribing to audio-video streams