Blockchain code Metaverse VR

Unity×VR×Blockchain(277)

スポンサーリンク

//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などと暗号通貨と同じように暗号化作業を行なう必要がある。

人気の記事

1

皆さん、ついに、エアラインでも、サブスクリプションが始まったのはご存じですか? まだ実験段階ですが、ANAが、定額全国住み放題サービスを提供する「ADDress」と組んで、国内線を4回まで定額利用可能 ...

2

無料でネットショップを開けるアプリとして多くの人に驚きを与えたBASE株式会社が、2019年10月25日東証マザーズに上場しました。2020年2月時点で90万店を超えるショップを抱えるまでに成長してい ...

3

2011年にサービスを開始してから圧倒的な成長率を誇るインテリア通販サイト 【FLYMEe/フライミー】を皆さんご存じでしょうか。 「自分のイメージするインテリア、本当に欲しいインテリアがどこにあるの ...

4

ついに、noteの月間アクティブユーザー数が4400万人(2020年3月時点)に到達しました。 そもそも、「note」とは、クリエイターが、文章やマンガ、写真、音声を投稿することができ、ユーザーはその ...

5

ボードゲームカフェが1日2回転で儲かるという記事をみつけたので興味を持ち、調べてみました。 まずは、需要がどれくらいあるのか、市場のようすからみていきましょう。 世界最大のボードゲーム市場はドイツで、 ...

-Blockchain, code, Metaverse, VR
-, ,

Copyright© BUSINESS HUNTER , 2023 All Rights Reserved Powered by AFFINGER5.