googlesamples / ios-nearby

68 stars 30 forks source link

Difference between subscription and publishing discovery mode? #8

Closed TheDreamsWind closed 2 years ago

TheDreamsWind commented 8 years ago

Hello, Nearby Team and thank you for this outstanding technology.

I have a question about it and hope you can help me. I am a bit confused about ability to configure disocvery mode for subscription and publishing: as i understand, when i try to subscribe, i should only be able to listen, so Is there any sense to configure discovery mode to kGNSDiscoveryModeBroadcast only or to kGNSDiscoveryModeDefault at least? Or should i always set it to kGNSDiscoveryModeScan for Nearby to work properly (and vice versa for publishing)?

Thank you in advance.

dan-webb commented 8 years ago

Hello,

Thanks for reaching out. This aspect of Nearby is indeed confusing at first, and it's important for our customers to understand it. Let me try to explain.

There are two distinct phases of operation: (1) device discovery, and (2) message delivery (from publisher to subscriber).

  1. Discovery of nearby devices happens when one device hears another device's token (via BLE, audio, etc.). Token exchange can happen in either direction. When it happens, the devices are considered to be nearby each other.
  2. After two devices are found to be nearby each other, messages are then delivered from publisher to subscriber.

Examples: a. A mobile game that uses Nearby to allow players to start games with each other. This is a scenario where both phones must broadcast and scan simultaneously in order to discover each other. b. A set-top box and a mobile phone that connects to it (e.g., to cast video to it). The set-top box can advertise, and the mobile device can scan.

I hope this helps. Please let me know if you have more questions.

TheDreamsWind commented 8 years ago

Thank you for clarification, but i have additional question now. Is it right, that device discovery state is a global state for publishing and subscribing? If so, should i set up only one strategy for both actions?

dan-webb commented 8 years ago

There is no global state. Device discovery is the union of all active publications and subscriptions created from the same message manager. If you want to prevent discovery from "leaking" between pubs/subs, you should be able to accomplish this by creating them from different message managers. Let me know if you try this and have problems getting it working as expected.