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

Nearby オブジェクトの作成に使用される 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
)

接続リクエストを受け入れます。

この関数は、IMessageListener ではなく MessageListenerHelper を使用するという点でのみ異なります。AcceptConnectionRequest

接続解除

void Disconnect(
  const std::string & remote_endpoint_id
)

指定された ID のリモート エンドポイントから切断します。

NearbyConnections

 NearbyConnections()

拒否接続リクエスト

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 の信頼できないメッセージをリモート エンドポイントに送信します。

広告を開始

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 を呼び出すか、指定された時間が経過するまで、このエンドポイントの存在をアドバタイズし続けます。すでにアドバタイズされているエンドポイントがある場合、この呼び出しは失敗します。

調査の開始

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 のエンドポイントを検出するためにすでにリスナーが登録されている場合、この呼び出しは失敗します。

調査の開始

void StartDiscovery(
  const std::string & service_id,
  Duration duration,
  EndpointDiscoveryListenerHelper helper
)

指定されたサービス ID のリモート エンドポイントを検索します。

この関数は、IEndpointDiscoveryListener の代わりに EndpointDiscoveryListenerHelper を使用するという点でのみ StartDiscovery と異なります。

停止

void Stop()

すべてのリモート エンドポイントとの接続を解除します。アドバタイズや検出が行われても停止します。

内部状態をクリアします。

広告掲載の停止

void StopAdvertising()

ローカル エンドポイントのアドバタイズを停止します。

この操作によって、既存の接続が破棄されることはありません。

検出を停止

void StopDiscovery(
  const std::string & service_id
)

以前に指定したサービス ID のリモート エンドポイントの検索を停止します。

~NearbyConnections

 ~NearbyConnections()