gpg:: NearbyConnections
#include <nearby_connections.h>
同じローカル ネットワーク上のアプリ間で接続を作成し、通信するために使用される API。
概要
コンストラクタとデストラクタ |
|
---|---|
NearbyConnections()
|
|
~NearbyConnections()
|
パブリック関数 |
|
---|---|
AcceptConnectionRequest(const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, IMessageListener *listener)
|
void
接続リクエストを受け入れます。
|
AcceptConnectionRequest(const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, MessageListenerHelper helper)
|
void
接続リクエストを受け入れます。
|
Disconnect(const std::string & remote_endpoint_id)
|
void
指定された ID を持つリモート エンドポイントから切断します。
|
RejectConnectionRequest(const std::string & remote_endpoint_id)
|
void
接続リクエストを拒否する。
|
SendConnectionRequest(const std::string & name, const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, ConnectionResponseCallback callback, IMessageListener *listener)
|
void
リモート エンドポイントとの接続を確立することをリクエストします。
|
SendConnectionRequest(const std::string & name, const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, ConnectionResponseCallback callback, MessageListenerHelper helper)
|
void
リモート エンドポイントへの接続をリクエストします。
|
SendReliableMessage(const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload)
|
void
指定された ID の信頼できるメッセージをリモート エンドポイントに送信します。
|
SendReliableMessage(const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload)
|
void
指定された ID のリモート エンドポイントに信頼性の高いメッセージを送信します。
|
SendUnreliableMessage(const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload)
|
void
指定された ID の信頼できないメッセージをリモート エンドポイントに送信します。
|
SendUnreliableMessage(const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload)
|
void
指定された ID のリモート エンドポイントに信頼性の低いメッセージを送信します。
|
StartAdvertising(const std::string & name, const std::vector< AppIdentifier > & app_identifiers, Duration duration, StartAdvertisingCallback start_advertising_callback, ConnectionRequestCallback request_callback)
|
void
ローカルアプリのエンドポイントのアドバタイジングを開始します。
|
StartDiscovery(const std::string & service_id, Duration duration, IEndpointDiscoveryListener *listener)
|
void
指定されたサービス ID を持つリモート エンドポイントを見つけて、アプリがエンドポイントを見つけて失われるとリスナーを繰り返し呼び出します。
|
StartDiscovery(const std::string & service_id, Duration duration, EndpointDiscoveryListenerHelper helper)
|
void
指定されたサービス ID のリモート エンドポイントを検索します。
|
Stop()
|
void
すべてのリモート エンドポイントから切断し、実行中のアドバタイジングまたは検出を停止します。
|
StopAdvertising()
|
void
ローカル エンドポイントのアドバタイジングを停止します。
|
StopDiscovery(const std::string & service_id)
|
void
以前に指定されたサービス ID のリモート エンドポイントの検索を停止します。
|
クラス |
|
---|---|
gpg:: |
NearbyConnections オブジェクトの作成に使用する Builder クラス |
パブリック関数
AcceptConnectionRequest
void AcceptConnectionRequest( const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, IMessageListener *listener )
接続リクエストを受け入れます。
その後、アプリは指定されたエンドポイントとの間でメッセージを送受信できます。アプリは他のエンドポイントから切断されるまで、listener
を使用して接続できます。remote_endpoint_id
は、接続をリクエストしたリモート エンドポイントの ID と一致する必要があります。ConnectionRequestCallback
はその ID を提供します。payload
は、接続レスポンスと一緒に送信するメッセージを保持できます。listener
は、この接続のイベントについて通知を受け取るリスナーを指定します。
AcceptConnectionRequest
void AcceptConnectionRequest( const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, MessageListenerHelper helper )
接続リクエストを受け入れます。
この関数が AcceptConnectionRequest
と異なる点は、IMessageListener
ではなく MessageListenerHelper
を使用する点のみです。
接続を解除
void Disconnect( const std::string & remote_endpoint_id )
指定された ID を持つリモート エンドポイントから切断します。
NearbyConnections
NearbyConnections()
RejectConnectionRequest
void RejectConnectionRequest( const std::string & remote_endpoint_id )
接続リクエストを拒否する。
remote_endpoint_id
は、接続をリクエストしたリモート エンドポイントの ID と一致する必要があります。ConnectionRequestCallback
はその ID を提供します。
SendConnectionRequest
void SendConnectionRequest( const std::string & name, const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, ConnectionResponseCallback callback, IMessageListener *listener )
リモート エンドポイントとの接続を確立することをリクエストします。
name
は、このエンドポイントを識別するためにアプリが別のデバイスのユーザーに表示できる名前です。空の文字列を指定すると、デバイス名が使用されます。remote_endpoint_id
は、このアプリが接続リクエストを送信するリモート エンドポイントの ID です。payload
は、接続リクエストと一緒に送信するカスタム メッセージを保持できます。または、ペイロードの代わりに空のバイトベクトルをアプリで渡すこともできます。この関数は、リクエストに応じて指定されたコールバックを呼び出します。オペレーションが成功すると、「Connection Accepted」または「Connection Rejected」のレスポンスが生成されます。それ以外の場合は、エラー メッセージが生成されます。接続が受け入れられた場合、アプリはリモート エンドポイントにメッセージを送信できます。アプリは、メッセージを受信するか、リモート エンドポイントから切断されたときに、指定されたリスナーを呼び出します。
SendConnectionRequest
void SendConnectionRequest( const std::string & name, const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, ConnectionResponseCallback callback, MessageListenerHelper helper )
リモート エンドポイントへの接続をリクエストします。
SendConnectionRequest
との違いは、IMessageListener
ではなく MessageListenerHelper
を使用する点だけです。
SendReliableMessage
void SendReliableMessage( const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload )
指定された ID の信頼できるメッセージをリモート エンドポイントに送信します。
SendReliableMessage
void SendReliableMessage( const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload )
指定された ID のリモート エンドポイントに信頼性の高いメッセージを送信します。
SendUnreliableMessage
void SendUnreliableMessage( const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload )
指定された ID の信頼できないメッセージをリモート エンドポイントに送信します。
SendUnreliableMessage
void SendUnreliableMessage( const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload )
指定された ID のリモート エンドポイントに信頼性の低いメッセージを送信します。
StartAdvertising
void StartAdvertising( const std::string & name, const std::vector< AppIdentifier > & app_identifiers, Duration duration, StartAdvertisingCallback start_advertising_callback, ConnectionRequestCallback request_callback )
ローカルアプリのエンドポイントのアドバタイジングを開始します。
name
には、エンドポイントを識別するためにアプリでユーザーに表示する名前を指定できます。空の文字列を指定すると、デバイス名が使用されます。指定した場合、app_identifiers
はさまざまなプラットフォームでこのアプリをインストールまたは起動する方法を指定します。duration
には、アドバタイズメントの実行期間(ミリ秒単位)を指定します。ただし、期間の満了前にアプリが StopAdvertising()
または Stop()
を呼び出した場合は例外です。duration
の値が gpg::Duration::zero()
と等しい場合は、アプリが StopAdvertising()
を呼び出すまでアドバタイジングが無期限に継続されます。この関数は、アドバタイジングの開始時または失敗時に start_advertising_callback
を呼び出します。このコールバックは、成功した場合はエンドポイント情報を受け取り、失敗した場合はエラーコードを受け取ります。この関数は、リモート エンドポイントがアプリのエンドポイントとの接続をリクエストすると、request_callback
を呼び出します。この関数は、アプリが StopAdvertising
を呼び出すか、時間が経過するまで、このエンドポイントの存在をアドバタイズし続けます。アドバタイズされているエンドポイントがすでに存在する場合、この呼び出しは失敗します。
StartDiscovery
void StartDiscovery( const std::string & service_id, Duration duration, IEndpointDiscoveryListener *listener )
指定されたサービス ID を持つリモート エンドポイントを見つけて、アプリがエンドポイントを見つけて失われるとリスナーを繰り返し呼び出します。
アプリが指定されたサービス ID で StopDiscovery
を呼び出すまで、この操作を続けます。service_id
は、StartAdvertising
で広告を掲載するときにアプリが提供する値と一致する必要があります。duration
は、検出を実行する最大時間(ミリ秒単位)を指定します(アプリが StopDiscovery()
を呼び出した場合はすぐに停止する可能性があります)。Duration
の値が gpg::Duration::zero()
の場合、アプリが StopDiscovery()
または Stop()
を呼び出すまで検出が無期限に続行されます。指定されたサービス ID のエンドポイントを検出するためにリスナーがすでに登録されている場合、この呼び出しは失敗します。
StartDiscovery
void StartDiscovery( const std::string & service_id, Duration duration, EndpointDiscoveryListenerHelper helper )
指定されたサービス ID のリモート エンドポイントを検索します。
この関数が StartDiscovery
と異なる点は、IEndpointDiscoveryListener
の代わりに EndpointDiscoveryListenerHelper
を使用する点のみです。
停止
void Stop()
すべてのリモート エンドポイントから切断し、実行中のアドバタイジングまたは検出を停止します。
内部状態をクリアします。
StopAdvertising
void StopAdvertising()
ローカル エンドポイントのアドバタイジングを停止します。
それによって既存の接続が切断されることはありません。
StopDiscovery
void StopDiscovery( const std::string & service_id )
以前に指定されたサービス ID のリモート エンドポイントの検索を停止します。
~NearbyConnections
~NearbyConnections()