gpg:: NearbyConnections
#include <nearby_connections.h>
यह एपीआई, एक ही लोकल नेटवर्क पर ऐप्लिकेशन के बीच कनेक्शन बनाने और कम्यूनिकेशन करने के लिए इस्तेमाल किया जाता है.
खास जानकारी
कंस्ट्रक्टर और डिस्ट्रक्टर |
|
---|---|
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
दिए गए आईडी वाले रिमोट एंडपॉइंट से डिसकनेक्ट करता है.
|
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
दिए गए आईडी का इस्तेमाल करके, रिमोट एंडपॉइंट पर भरोसेमंद मैसेज भेजता है.
|
SendReliableMessage(const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload)
|
void
तय किए गए आईडी के साथ, रिमोट एंडपॉइंट पर भरोसेमंद मैसेज भेजता है.
|
SendUnreliableMessage(const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload)
|
void
दिए गए आईडी वाले रिमोट एंडपॉइंट पर, गलत मैसेज भेजता है.
|
SendUnreliableMessage(const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload)
|
void
तय किए गए आईडी वाले रिमोट एंडपॉइंट पर, गैर-भरोसेमंद मैसेज भेजता है.
|
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
यह, बताए गए सेवा आईडी वाले रिमोट एंडपॉइंट ढूंढता है और ऐप्लिकेशन को, एंडपॉइंट मिलने और उन्हें खो देने पर बार-बार लिसनर को ट्रिगर करता है.
|
StartDiscovery(const std::string & service_id, Duration duration, EndpointDiscoveryListenerHelper helper)
|
void
दिए गए सेवा आईडी वाले रिमोट एंडपॉइंट को ढूंढता है.
|
Stop()
|
void
यह सभी रिमोट एंडपॉइंट से डिसकनेक्ट हो जाता है. साथ ही, चल रहे किसी भी विज्ञापन या खोज को रोकता है.
|
StopAdvertising()
|
void
लोकल एंडपॉइंट का विज्ञापन बंद करता है.
|
StopDiscovery(const std::string & service_id)
|
void
पहले से तय सेवा आईडी के लिए, रिमोट एंडपॉइंट ढूंढने की सुविधा बंद कर देता है.
|
क्लास |
|
---|---|
gpg:: |
Builder क्लास का इस्तेमाल, NearbyConnections ऑब्जेक्ट को बनाने के लिए किया गया है. |
सार्वजनिक फ़ंक्शन
AcceptConnectionRequest
void AcceptConnectionRequest( const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload, IMessageListener *listener )
कनेक्शन के अनुरोध को स्वीकार करता है.
इसके बाद, ऐप्लिकेशन बताए गए एंडपॉइंट पर मैसेज भेज सकता है और उनसे मैसेज पा सकता है. listener
का इस्तेमाल करके, ऐसा तब तक किया जा सकता है, जब तक कि ऐप्लिकेशन अन्य एंडपॉइंट से डिसकनेक्ट न हो जाए. remote_endpoint_id
का मिलान उस रिमोट एंडपॉइंट के आईडी से होना चाहिए जिससे कनेक्शन का अनुरोध किया गया था. ConnectionRequestCallback
यह आईडी देता है. 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 )
दिए गए आईडी वाले रिमोट एंडपॉइंट से डिसकनेक्ट करता है.
NearbyConnections
NearbyConnections()
RejectConnectionRequest
void RejectConnectionRequest( const std::string & remote_endpoint_id )
कनेक्शन के अनुरोध को अस्वीकार करता है.
remote_endpoint_id
का मिलान उस रिमोट एंडपॉइंट के आईडी से होना चाहिए जिससे कनेक्शन का अनुरोध किया गया था. ConnectionRequestCallback
यह आईडी देता है.
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
, उस रिमोट एंडपॉइंट का आईडी है जिससे यह ऐप्लिकेशन कनेक्ट करने का अनुरोध भेज रहा है. कनेक्शन के अनुरोध के साथ भेजने के लिए, payload
में पसंद के मुताबिक मैसेज भेजा जा सकता है. इसके अलावा, पेलोड के बजाय आपका ऐप्लिकेशन एक खाली बाइट वेक्टर पास कर सकता है. यह फ़ंक्शन, अनुरोध के जवाब में बताए गए कॉलबैक को शुरू करता है. कार्रवाई पूरी होने पर, "कनेक्शन स्वीकार किया गया" या "कनेक्शन अस्वीकार किया गया" वाला जवाब मिलता है. ऐसा न होने पर, यह गड़बड़ी का मैसेज जनरेट करता है. स्वीकार किए गए कनेक्शन की स्थिति में, ऐप्लिकेशन रिमोट एंडपॉइंट पर मैसेज भेज सकता है और रिमोट एंडपॉइंट से कोई मैसेज मिलने या डिसकनेक्ट होने पर, ऐप्लिकेशन तय लिसनर को शुरू करता है.
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 )
दिए गए आईडी का इस्तेमाल करके, रिमोट एंडपॉइंट पर भरोसेमंद मैसेज भेजता है.
SendReliableMessage
void SendReliableMessage( const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload )
तय किए गए आईडी के साथ, रिमोट एंडपॉइंट पर भरोसेमंद मैसेज भेजता है.
SendUnreliableMessage
void SendUnreliableMessage( const std::string & remote_endpoint_id, const std::vector< uint8_t > & payload )
दिए गए आईडी वाले रिमोट एंडपॉइंट पर, गलत मैसेज भेजता है.
SendUnreliableMessage
void SendUnreliableMessage( const std::vector< std::string > & remote_endpoint_ids, const std::vector< uint8_t > & payload )
तय किए गए आईडी वाले रिमोट एंडपॉइंट पर, गैर-भरोसेमंद मैसेज भेजता है.
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 )
यह, बताए गए सेवा आईडी वाले रिमोट एंडपॉइंट ढूंढता है और ऐप्लिकेशन को, एंडपॉइंट मिलने और उन्हें खो देने पर बार-बार लिसनर को ट्रिगर करता है.
ऐसा तब तक जारी रहेगा, जब तक ऐप्लिकेशन बताए गए सेवा आईडी से StopDiscovery
को शुरू नहीं कर देता. StartAdvertising
के ज़रिए विज्ञापन दिखाते समय, ऐप्लिकेशन की दी गई वैल्यू से service_id
मेल खाना चाहिए. duration
, डिस्कवरी को चलाए जाने के लिए ज़्यादा से ज़्यादा समय (मिलीसेकंड में) तय करता है (अगर ऐप्लिकेशन StopDiscovery()
को शुरू करता है, तो यह जल्द ही बंद हो सकती है). अगर Duration
की वैल्यू gpg::Duration::zero()
के बराबर है, तो ऐप्लिकेशन के StopDiscovery()
या Stop()
को कॉल करने तक, खोज की सुविधा हमेशा के लिए जारी रहती है. अगर दिए गए सेवा आईडी के लिए एंडपॉइंट ढूंढने के लिए, पहले से ही कोई लिसनर रजिस्टर है, तो यह कॉल नहीं हो पाएगा.
StartDiscovery
void StartDiscovery( const std::string & service_id, Duration duration, EndpointDiscoveryListenerHelper helper )
दिए गए सेवा आईडी वाले रिमोट एंडपॉइंट को ढूंढता है.
यह फ़ंक्शन सिर्फ़ StartDiscovery
से अलग है, क्योंकि यह IEndpointDiscoveryListener
के बजाय EndpointDiscoveryListenerHelper
का इस्तेमाल करता है.
रोकें
void Stop()
यह सभी रिमोट एंडपॉइंट से डिसकनेक्ट हो जाता है. साथ ही, चल रहे किसी भी विज्ञापन या खोज को रोकता है.
अंदरूनी स्थिति साफ़ करता है.
StopAdvertising
void StopAdvertising()
लोकल एंडपॉइंट का विज्ञापन बंद करता है.
ऐसा करने से मौजूदा कनेक्शन खत्म नहीं होंगे.
StopDiscovery
void StopDiscovery( const std::string & service_id )
पहले से तय सेवा आईडी के लिए, रिमोट एंडपॉइंट ढूंढने की सुविधा बंद कर देता है.
~आस-पास कनेक्शन
~NearbyConnections()