Création de sessions
Vue d'ensemble
Une session vidéo Vonage est l'endroit où les utilisateurs se connectent pour interagir en temps réel. Votre serveur d'application génère la session pour que les clients puissent la rejoindre.
Ce mode d'emploi aborde les points suivants :
- Création d'une session
Avant de commencer
Comme indiqué précédemment, vous aurez besoin d'un serveur d'application en cours d'exécution pour créer une session.
Créer une session
Lors de la création d'une session, vous pouvez spécifier quelques options en fonction de vos besoins. Il s'agit du mode média, de la préférence d'archivage et de l'indication d'emplacement. Vous trouverez plus d'informations sur ces options dans la section Créer un guide de la session.
// 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);
}
// A session that attempts to stream media directly between clients:
CreateSessionResponse session = videoClient.createSession();
// A session that uses the Vonage Video Media Router:
CreateSessionResponse session = videoClient.createSession(
CreateSessionRequest.builder().mediaMode(MediaMode.ROUTED).build()
);
// A Session with a location hint:
CreateSessionResponse session = videoClient.createSession(
CreateSessionRequest.builder().location("12.34.56.78").build()
);
// A session that is automatically archived (it must used the routed media mode)
CreateSessionResponse session = videoClient.createSession(
CreateSessionRequest.builder()
.mediaMode(MediaMode.ROUTED)
.archiveMode(ArchiveMode.ALWAYS)
.build()
);
// Store this sessionId in the database for later use:
String sessionId = session.getSessionId();
// Create a session that will attempt to transmit streams directly between clients
Result<CreateSessionRequest> request = CreateSessionRequest.Default;
// Or create a custom request
Result<CreateSessionRequest> request = CreateSessionRequest.Build()
.WithLocation("192.168.1.1")
.WithMediaMode(MediaMode.Routed)
.WithArchiveMode(ArchiveMode.Always)
.Create();
// Send the request to the API
Result<CreateSessionResponse> response = await client.SessionClient.CreateSessionAsync(request);
# Creating a session using the default settings (media_mode defaults to 'routed', which will use the Vonage Media Router, and archive_mode defaults to 'manual', which does not automatically create an archive):
session = client.video.create_session
# Creating a session that will attempt to transmit streams directly between clients (note that archive_mode MUST BE 'manual', which is the default, for media_mode to be 'relayed'):
session = client.video.create_session(media_mode: 'relayed')
# Creating a session with a location hint:
session = client.video.create_session(location: '12.34.56.78')
# Creating a session with automatic archiving (MUST use the 'routed' media mode, which is the default):
session = client.video.create_session(archive_mode: 'always')
# You can use the session_id accessor method of the returned Vonage::Response instance to get the session ID of the created session. This can be assigned to a variable or later use, such as when generating tokens:
session_id = session.session_id
Outre les SDK du serveur, une session peut être créée par un appel API à un point d'extrémité. Vous trouverez plus d'informations dans la section Référence de l'API Video de Vonage
L'identifiant de session est renvoyé et peut être transmis au client pour permettre aux utilisateurs de se connecter et d'interagir avec leurs jetons.