セッションの作成
概要
Vonage Videoセッションは、ユーザがリアルタイムで対話するために接続する場所です。アプリケーション・サーバーは、クライアントが参加できるようにセッションを生成します。
このハウツーでは、その詳細を説明する:
- セッションの作成
始める前に
前述したように、セッションを作成するにはアプリケーションサーバーが稼動している必要があります。
セッションの作成
セッションを作成するとき、ニーズに応じて指定できるオプションがいくつかあります。メディアモード、アーカイブの優先順位、ロケーションヒントです。これらのオプションの詳細については セッションガイドの作成.
コピー
// 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);
コピー
use Vonage\Video\MediaMode;
use Vonage\Video\SessionOptions;
use Vonage\Video\Archive\ArchiveMode;
// Create a session that attempts to use peer-to-peer streaming:
$session = $client->video()->createSession();
// A session that uses the Vonage Video Media Router, which is required for archiving:
$session = $client->video()->createSession(new SessionOptions(['mediaMode' => MediaMode::ROUTED]));
// A session with a location hint:
$session = $client->video()->createSession(new SessionOptions(['location' => '12.34.56.78']));
// An automatically archived session:
$sessionOptions = new SessionOptions([
'archiveMode' => ArchiveMode::ALWAYS,
'mediaMode' => MediaMode::ROUTED
]);
$session = $client->video()->createSession($sessionOptions);
// Store this sessionId in the database for later use
$sessionId = $session->getSessionId();
コピー
from vonage_video.models import VideoSession
# Create a session
session_info: VideoSession = vonage_client.video.create_session()
# A session that doesn't use the Vonage Media Router and instead sends
# information between peers directly
from vonage_video.models import SessionOptions
options = SessionOptions(media_mode='relayed')
session_info = vonage_client.video.create_session(options)
# An automatically archived session:
options = SessionOptions(media_mode='routed', archive_mode='always')
session_info = vonage_client.video.create_session(options)
# A session with a location hint
options = SessionOptions(location='12.34.56.78')
session_info = vonage_client.video.create_session(options)
# Extract the session ID to be stored in a database
session_id = session_info.session_id
コピー
# 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
サーバー SDK に加え、エンドポイントへの API 呼び出しによってもセッションを作成できます。詳細は Video API リファレンス
セッションIDが返され、それをクライアントに渡すことで、ユーザーがトークンに接続して対話できるようになる。