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

Builder 클래스를 사용합니다.NearbyConnections

공개 함수

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()

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'(연결 수락됨)이 생성됩니다. 또는 '연결 거부됨' 있습니다. 그렇지 않으면 실패 메시지가 생성됩니다. 연결이 수락된 경우 앱은 원격 엔드포인트로 메시지를 보낼 수 있으며, 앱은 메시지를 수신하거나 원격 엔드포인트와의 연결이 끊길 때 지정된 리스너를 호출합니다.

SendConnectionRequest

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

원격 엔드포인트에 대한 연결을 요청합니다.

IMessageListener 대신 MessageListenerHelper를 사용한다는 점만 SendConnectionRequest와 다릅니다.

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_idStartAdvertising를 통해 광고할 때 앱이 제공하는 값과 일치해야 합니다. duration는 검색을 실행할 최대 시간 (밀리초)을 지정합니다 (앱이 StopDiscovery()를 호출하면 더 빨리 중지될 수 있음). Duration 값이 gpg::Duration::zero()와 같으면 앱이 StopDiscovery() 또는 Stop()를 호출할 때까지 검색이 무기한 계속됩니다. 지정된 서비스 ID의 엔드포인트를 찾기 위해 등록된 리스너가 이미 있는 경우, 이 호출은 실패합니다.

StartDiscovery

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

지정된 서비스 ID가 있는 원격 엔드포인트를 찾습니다.

이 함수는 IEndpointDiscoveryListener 대신 EndpointDiscoveryListenerHelper를 사용한다는 점만 StartDiscovery와 다릅니다.

중지

void Stop()

모든 원격 엔드포인트와의 연결을 해제합니다. 발생하는 모든 광고나 발견을 중단합니다.

내부 상태를 정리합니다.

StopAdvertising

void StopAdvertising()

로컬 엔드포인트의 공지를 중지합니다.

이렇게 해도 기존 연결이 끊어지지는 않습니다.

StopDiscovery

void StopDiscovery(
  const std::string & service_id
)

이전에 지정된 서비스 ID의 원격 엔드포인트 찾기를 중지합니다.

~NearbyConnections

 ~NearbyConnections()