Setting the encryption secret
エンドツーエンドの暗号化セッションは、サーバーAPIを使用して作成されます。 REST API).
クライアントがパブリッシュまたはサブスクライブする前に Session.SetEncryptionSecret() メソッドを使用する:
Session.SetEncryptionSecret("encryption-secret");
Session.Connect(TOKEN);
有効な秘密は8文字以上256文字以下の文字列である。シークレットを変更するには Session.SetEncryptionSecret() メソッドをもう一度。
Events and errors
イベントとエラーは、ユーザー主導の暗号化の動作を管理するために不可欠である。エンドツーエンドの暗号化は、共有秘密モデルを使用します。セッション内の全員が、自分のメディアを暗号化し、他の全員のメディアを復号化するために、同じ秘密を使用することが期待されています。
クライアントが暗号化シークレットを設定せずにエンドツーエンドで暗号化されたセッションに接続しようとすると、Session.Errorイベントがエラーコードを設定して送られる。 ErrorCode.EncryptionSecretMissing:
private void Session_Error(object sender, ErrorEventArgs error)
{
if (Error.ErrorCode == ErrorCode.EncryptionSecretMissing) {
// Notify the user that they cannot join the session
}
}
Session.Error += Session_Error;
Session.Connect(TOKEN);
暗号化シークレットを指定せずにエンドツーエンドで暗号化されたセッションを公開しようとした場合、次のように呼び出す。 Session.Publish() 関数の結果は Publisher.Error イベントが送信される。 ErrorCode.EncryptionInternalError.最高のユーザーエクスペリエンスを得るためには、アプリケーションは Session.Publish() メソッドを使用する:
private void Publisher_Error(object sender, ErrorEventArgs error)
{
if (Error.ErrorCode == ErrorCode.EncryptionInternalError) {
// The application should communicate that the secret was not set.
}
}
Publisher.Error += Publisher_Error;
Session.Publish(Publisher);
不正確な暗号化シークレットのために、加入者がストリームのメディアをデコードできない場合は Subscriber.Error イベントが送信される。 ErrorCode.EncryptionSecretMismatch.メディアを受信できないのは、暗号化の不一致によるものであり、接続障害やオーディオ/ビデオの問題ではないことをユーザーに伝えることが重要です:
private void Subscriber_Error(object sender, ErrorEventArgs error)
{
if (Error.ErrorCode == ErrorCode.EncryptionSecretMismatch) {
// Activate a UI element communicating that there's been an encryption secret mismatch.
}
}
Subscriber.Error += Subscriber_Error;
Session.Subscribe(Subscriber);
サブスクライバーがパケットを復号化する際に内部エラーが発生した場合 Subscriber.Error イベントが送信される。 ErrorCode.DecryptionInternalError.