Connecting to a session

Once you have a session ID, and initialized a session object using it, the next step is to connect to the session.

Learn how to connect to sessions below by selecting your platform/language of choice:

When you add an OTSession component it automatically connects to the Vonage Video API session.

<OTSession
  applicationId="your-application-ID"
  sessionId="your-session-id"
  token="your-session-token"
>
  <OTPublisher/>
  <OTSubscriber/>
</OTSession>

Replace your-application-ID, your-session-id, and your-session-token with your API key, a session ID, and a token for the session.

Note that you add the OTPublisher and OTSubscriber components and children of the OTSession component.

You can pass an error and sessionConnected event handlers in the OTSession component. The error event handler is called if the client fails to connect to the session. And the sessionConnected event handler is called when the client connects to the session:

<OTSession
  applicationId="your-application-ID"
  sessionId="your-session-id"
  token="your-session-token"
  eventHandlers={{
    error: event => {
        console.log('error', event);
      },
    sessionConnected: event => {
      console.log('session connected', event);
    },
  }}
>
  <OTPublisher style={{ width: 100, height: 100 }}/>
  <OTSubscriber style={{ width: 100, height: 100 }} />
</OTSession>