//tips
//vivox理解
先のスクリプトにAudioとTextの状態も追加。
public void On_Audio_State_Changed(object sender,PropertyChangedEventArgs audioArgs)
{
IChannelSession source = (IChannelSession)sender;
switch (source.AudioState)
{
case ConnectionState.Connecting:
Debug.Log("AConnecting");
break;
case ConnectionState.Connected:
Debug.Log("AConnected");
break;
case ConnectionState.Disconnecting:
Debug.Log("ADisconnecting");
break;
case ConnectionState.Disconnected:
Debug.Log("ADisconnected");
break;
}
}
public void On_Text_State_Changed(object sender, PropertyChangedEventArgs audioArgs)
{
IChannelSession source = (IChannelSession)sender;
switch (source.TextState)
{
case ConnectionState.Connecting:
Debug.Log("TConnecting");
break;
case ConnectionState.Connected:
Debug.Log("TConnected");
break;
case ConnectionState.Disconnecting:
Debug.Log("TDisconnecting");
break;
case ConnectionState.Disconnected:
Debug.Log("TDisconnected");
break;
}
ここまでできたらスクリプトが長くなってしまったので機能単位に分割。
LoginCredentials
Base_Credentials
LobbyUI
の3つに分けることでスクリプトを見やすくしている。
ただ、相互の参照が必要になるのでそこは注意して修正していく。
ドキュメントを見ながら少しスクリプト理解の補足を行う。
Vivoxは個人のチャンネル参加について情報をポストする機能を持っており、参加時、退出時、話している時やタイピングしている時などのステータスの変化を確認できる。
The Vivox SDK posts information about individual participants in a channel that is visible to all other participants. This includes the following information:
When a user joins a channel
When a user leaves a channel
When there is an important change in user state, such as whether the user is speaking or typing
ユーザーのステータス情報を可視化するためには下記コードを使用する。
To provide a visualization of user state information, a game must handle the following messages:
IChannelSession.Participants.AfterKeyAdded
IChannelSession.Participants.BeforeKeyRemoved
IChannelSession.Participants.AfterValueUpdated
オリジナルスクリプトではBindを使用した部分に該当する。下記例。
private void BindChannelSessionHandlers(bool doBind, IChannelSession channelSession)
{
//Subscribing to the events
if (doBind)
{
// Participants
channelSession.Participants.AfterKeyAdded += OnParticipantAdded;
channelSession.Participants.BeforeKeyRemoved += OnParticipantRemoved;
channelSession.Participants.AfterValueUpdated += OnParticipantValueUpdated;
//Messaging
channelSession.MessageLog.AfterItemAdded += OnChannelMessageReceived;
}
//Unsubscribing to the events
else
{
// Participants
channelSession.Participants.AfterKeyAdded -= OnParticipantAdded;
channelSession.Participants.BeforeKeyRemoved -= OnParticipantRemoved;
channelSession.Participants.AfterValueUpdated -= OnParticipantValueUpdated;
//Messaging
channelSession.MessageLog.AfterItemAdded -= OnChannelMessageReceived;
}
}
イベントのモニタリングをしていることになる。
IChannelSessionはチャンネルに参加する際に作られるもので、その際にはアクセストークンが求められる。
To join a channel, you must create an IChannelSession by using a game-selected identifier for the channel and channel type, and then call its BeginConnect() method.
Joining a channel requires an access token.
チャンネル参加時にはaudioやテキストの接続許可などをBeginConnect()の引数として与えてあげる必要がある
When joining a channel, the game can choose whether to join with audio capability, which enables the player to participate in group audio, and whether to join text capability, which enables the player to participate in group text.
This is set with the connectAudio and connectText arguments to BeginConnect(), respectively.
Adding or dropping these capabilities can be performed without having to leave or rejoin the channel by calling IChannelSession.BeginSetAudioConnected() or IChannelSession.BeginSetTextConnected().
複数チャンネル間もスイッチチャンネルで扱えるが、そちらはin ILoginSessionにて取り扱われるので注意が必要。
In addition, the argument switchTransmission can be set to true to automatically switch audio transmission into only the new channel after connection. This overrides and changes the TransmissionMode set in ILoginSession. You can also manage channel transmission at any time by using ILoginSession.SetTransmissionMode().
述べられているaccess tokensとはvivoxに登録し、新規プロジェクトを作成した際に発行される
public Uri server = new Uri("https://mt1s.www.vivox.com/api2");
public string issuer = "052-vo35-dev";
public string domain = "mt1s.vivox.com";
public string tokenKey = "bu8";
のことで、ログイン・チャンネル参加・チャンネル終了・ミュート・録音などの重要なアクセスが発生する際には逐次求められることになる。
Player access to Vivox resources is controlled through Vivox access tokens.
Each privileged operation requires a token in a specific format. Privileged operations include the following tasks:
Logging in
Joining a channel (muted or unmuted)
Kicking a user from a channel or from the server (Vivox Core SDKClosed only)
Muting or unmuting a user in a channel for all users in the channel
Requesting the start of a transcription for an audio session.
アクセストークンの生成に先のvivox登録コードが必要になり、これらをベースに各ユーザーがセッションの取得とログインの実行を可能にする。
To generate your access token, call the GetLoginToken() member function of your ILoginSession instance or the GetConnectToken() member function of your IChannelSession instance with the following parameters:
The token signing key
The token time to live in seconds
例:
string _key = "demo-key";
TimeSpan _expirationTimeSpan = TimeSpan.FromSeconds(90);
// Login (This assumes an already initialized Client object);
var _loginSession = client.GetLoginSession(/* AccountID to login */);
_loginSession.GetLoginToken(_key, _expirationTimeSpan);
// Join (This assumes an already signed in ILoginSession object);
var _channelSession = _loginSession.GetChannelSession(/* ChannelID to join */);
_channelSession.GetConnectToken(_key, _expirationTimeSpan);
市場に出す場合には、サーバーでのトークン化を行う必要があり、token with key and SHA256などと暗号通貨と同じように暗号化作業を行なう必要がある。