Creating Sessions

Overview

A Vonage Video session is where users connect to interact in real-time. Your application server generates the session so that the clients can join.

This how-to will go over:

  • Creating a session

Before you start

As previously mentioned, you will need an application server running to create a session.

Create a Session

When creating a session, there are a few options you can specify depending on your needs. They are media mode, archiving preference and location hint. You can find more information on these options in the Create a Session guide.

// Create a session that will attempt to transmit streams directly between
// clients. If clients cannot connect, the session uses the Vonage TURN server:
try {
    const session = await vonage.video.createSession();
    // save the sessionId
    db.save("session", session.sessionId, done);
} catch(error) {
    console.error("Error creating session: ", error);
}

// The session will use the Vonage Media Router:
try {
    const session = await vonage.video.createSession({ mediaMode: MediaMode.ROUTED });
    // save the sessionId
    db.save("session", session.sessionId, done);
} catch(error) {
    console.error("Error creating session: ", error);
}

// A Session with a location hint
try {
    const session = await vonage.video.createSession({ location: "12.34.56.78" });
    // save the sessionId
    db.save("session", session.sessionId, done);
} catch(error) {
    console.error("Error creating session: ", error);
}

// A Session with an automatic archiving
try {
    const session = await vonage.video.createSession({ mediaMode: MediaMode.ROUTED, archiveMode: "always" });
    // save the sessionId
    db.save("session", session.sessionId, done);
} catch(error) {
    console.error("Error creating session: ", error);
}

In addition to the Server SDKs, a session can be created by making an API call to an endpoint. You can find more information in the Vonage Video API Reference

The session ID will be returned and can then be passed to the client to allow users to connect and interact with their tokens.

See also