JavaScript

Connecting to the Session and Creating a Publisher

You may have noticed the initializeSession() method being called in the last step after getting the session ID and token. This method initializes a session object and then connects to the session, but we haven't defined it in our code yet.

  1. Copy the following code and paste it below the existing code in your app.js file after the initializeSession() line:

This code connects us to a session, and publishes our camera and microphone to the application and the video call itself.

OT.initSession() takes our Application ID and Session ID to set up which video session we will be connecting to. This does not immediately connect us to the stream, since applications may have some additional bootstrapping before fully connecting.

OT.initPublisher() set up the browser to publish our camera and microphone to the video session itself. Like with OT.initSession(), it does not immediately publish the streams to the API, it just configures them to do so later.

session.connect() finally tells the SDK to connect to the API. It takes our token, which is our authentication token, and connects us to the API. Since we have configured our publisher already, it will also begin to stream once we are connected to the overall session.