gpg::NearbyConnections

#include <nearby_connections.h>

An API used for creating connections and communicating between apps on the same local network.

Summary

Constructors and Destructors

NearbyConnections()
~NearbyConnections()

Public functions

AcceptConnectionRequest(const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, IMessageListener *listener)
void
Accepts a connection request.
AcceptConnectionRequest(const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, MessageListenerHelper helper)
void
Accepts a connection request.
Disconnect(const std::string & remote_endpoint_id)
void
Disconnects from the remote endpoint with the specified ID.
RejectConnectionRequest(const std::string & remote_endpoint_id)
void
Rejects a connection request.
SendConnectionRequest(const std::string & name, const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, ConnectionResponseCallback callback, IMessageListener *listener)
void
Requests that a connection be established with a remote endpoint.
SendConnectionRequest(const std::string & name, const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, ConnectionResponseCallback callback, MessageListenerHelper helper)
void
Requests a connection to a remote endpoint.
SendReliableMessage(const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload)
void
Sends a reliable message to the remote endpoint with the specified ID.
SendReliableMessage(const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload)
void
Sends a reliable message to the remote endpoints with the specified IDs.
SendUnreliableMessage(const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload)
void
Sends an unreliable message to the remote endpoint with the specified ID.
SendUnreliableMessage(const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload)
void
Sends an unreliable message to the remote endpoints with the specified IDs.
StartAdvertising(const std::string & name, const std::vector< AppIdentifier > & app_identifiers, Duration duration, StartAdvertisingCallback start_advertising_callback, ConnectionRequestCallback request_callback)
void
Starts advertising an endpoint for a local app.
StartDiscovery(const std::string & service_id, Duration duration, IEndpointDiscoveryListener *listener)
void
Finds remote endpoints with the specified service ID, and invokes the listener repeatedly as the app finds and loses endpoints.
StartDiscovery(const std::string & service_id, Duration duration, EndpointDiscoveryListenerHelper helper)
void
Finds remote endpoints with the specified service ID.
Stop()
void
Disconnects from all remote endpoints; stops any advertising or discovery that is taking place.
StopAdvertising()
void
Stops advertising the local endpoint.
StopDiscovery(const std::string & service_id)
void
Stops finding remote endpoints for a previously specified service ID.

Classes

gpg::NearbyConnections::Builder

Builder class used to construct NearbyConnections objects.

Public functions

AcceptConnectionRequest

void AcceptConnectionRequest(
  const std::string & remote_endpoint_id,
  const std::vector< uint8_t > & payload,
  IMessageListener *listener
)

Accepts a connection request.

Subsequently, the app can send messages to, and receive them from, the specified endpoint. It can do so, using listener, until the app disconnects from the other endpoint. remote_endpoint_id must match the ID of the remote endpoint that requested the connection. ConnectionRequestCallback provides that ID. payload can hold a message to send along with the connection response. listener specifies a listener to be notified of events for this connection.

AcceptConnectionRequest

void AcceptConnectionRequest(
  const std::string & remote_endpoint_id,
  const std::vector< uint8_t > & payload,
  MessageListenerHelper helper
)

Accepts a connection request.

This function only differs from AcceptConnectionRequest in that it uses MessageListenerHelper, rather than IMessageListener.

Disconnect

void Disconnect(
  const std::string & remote_endpoint_id
)

Disconnects from the remote endpoint with the specified ID.

NearbyConnections

 NearbyConnections()

RejectConnectionRequest

void RejectConnectionRequest(
  const std::string & remote_endpoint_id
)

Rejects a connection request.

remote_endpoint_id must match the ID of the remote endpoint that requested the connection. ConnectionRequestCallback provides that ID.

SendConnectionRequest

void SendConnectionRequest(
  const std::string & name,
  const std::string & remote_endpoint_id,
  const std::vector< uint8_t > & payload,
  ConnectionResponseCallback callback,
  IMessageListener *listener
)

Requests that a connection be established with a remote endpoint.

name is a name that the app can display to users on the other device to identify this endpoint. If you specify an empty string, the device name is used. remote_endpoint_id is the ID of the remote endpoint to which this app is sending a request to connect. payload can hold a custom message to send along with the connection request. Alternatively, instead of a payload, your app can pass an empty byte vector. This function invokes the specified callback in response to the request. If the operation is successful, it produces a "Connection Accepted" or "Connection Rejected" response. Otherwise, it generates a failure message. In the case of an accepted connection, the app can send messages to the remote endpoint, and the app invokes the specified listener on receipt of a message or disconnection from the remote endpoint.

SendConnectionRequest

void SendConnectionRequest(
  const std::string & name,
  const std::string & remote_endpoint_id,
  const std::vector< uint8_t > & payload,
  ConnectionResponseCallback callback,
  MessageListenerHelper helper
)

Requests a connection to a remote endpoint.

Differs from SendConnectionRequest only in that it uses MessageListenerHelper instead of IMessageListener.

SendReliableMessage

void SendReliableMessage(
  const std::string & remote_endpoint_id,
  const std::vector< uint8_t > & payload
)

Sends a reliable message to the remote endpoint with the specified ID.

SendReliableMessage

void SendReliableMessage(
  const std::vector< std::string > & remote_endpoint_ids,
  const std::vector< uint8_t > & payload
)

Sends a reliable message to the remote endpoints with the specified IDs.

SendUnreliableMessage

void SendUnreliableMessage(
  const std::string & remote_endpoint_id,
  const std::vector< uint8_t > & payload
)

Sends an unreliable message to the remote endpoint with the specified ID.

SendUnreliableMessage

void SendUnreliableMessage(
  const std::vector< std::string > & remote_endpoint_ids,
  const std::vector< uint8_t > & payload
)

Sends an unreliable message to the remote endpoints with the specified IDs.

StartAdvertising

void StartAdvertising(
  const std::string & name,
  const std::vector< AppIdentifier > & app_identifiers,
  Duration duration,
  StartAdvertisingCallback start_advertising_callback,
  ConnectionRequestCallback request_callback
)

Starts advertising an endpoint for a local app.

name can be a name that the app displays to users to identify the endpoint. If you specify an empty string, the device name is used. If specified, app_identifiers specifies how to install or launch this app on different platforms. duration specifies the duration (in milliseconds) for which the advertisement will run, unless the app invokes StopAdvertising() or Stop() before the duration expires. If the value of duration is equal to gpg::Duration::zero(), advertising continues indefinitely until the app calls StopAdvertising(). This function invokes start_advertising_callback when advertising starts or fails; this callback receives the endpoint info on success or an error code on failure. This function invokes request_callback when a remote endpoint requests a connection with the app's endpoint. This function continues advertising the presence of this endpoint until the app calls StopAdvertising, or the duration elapses. If there is already an endpoint being advertised, this call fails.

StartDiscovery

void StartDiscovery(
  const std::string & service_id,
  Duration duration,
  IEndpointDiscoveryListener *listener
)

Finds remote endpoints with the specified service ID, and invokes the listener repeatedly as the app finds and loses endpoints.

Continues doing so until the app invokes StopDiscovery with the specified service ID. service_id should match the value apps provide when advertising via StartAdvertising. duration specifies the maximum duration (in milliseconds) for discovery to run (it may stop sooner if the app invokes StopDiscovery()). If the value of Duration is equal to gpg::Duration::zero(), discovery continues indefinitely until the app calls StopDiscovery() or Stop(). If there is already a listener registered for finding endpoints for the specified service ID, this call fails.

StartDiscovery

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

Finds remote endpoints with the specified service ID.

This function differs from StartDiscovery only in that it uses EndpointDiscoveryListenerHelper instead of IEndpointDiscoveryListener.

Stop

void Stop()

Disconnects from all remote endpoints; stops any advertising or discovery that is taking place.

Clears up internal state.

StopAdvertising

void StopAdvertising()

Stops advertising the local endpoint.

Doing so does NOT cause existing connections to be torn down.

StopDiscovery

void StopDiscovery(
  const std::string & service_id
)

Stops finding remote endpoints for a previously specified service ID.

~NearbyConnections

 ~NearbyConnections()

傳送您對下列選項的寶貴意見...

這個網頁
Play Games Services for C++
Play Games Services for C++