0

I am trying to code around the fact that the messageLostHandler doesn't fire for many minutes after a device is out of range using Audio (or Earshot for Android).

I was hoping that every few secs a message would be received from another device. It fires once. Is this expected? Since I can't rely on the messageLost handler - how do I know when a device is truly out of range of the ultrasonic?

I coded up a timer after receiving the subscriptionWithMessageFoundHandler hoping another message coming in I could just invalidate or restart the timer. If the timer fired, I'd know that x seconds passed and that the other device must be out of range. No such luck.

UPDATE: Here is the code in question:

let strategy = GNSStrategy.init(paramsBlock: { (params: GNSStrategyParams!) -> Void in
    params.discoveryMediums = .Audio
})

publication = messageMgr.publicationWithMessage(pubMessage, paramsBlock: { (pubParams: GNSPublicationParams!) in
    pubParams.strategy = strategy
})

subscription = messageMgr.subscriptionWithMessageFoundHandler({[unowned self] (message: GNSMessage!) -> Void in
    self.messageViewController.addMessage(String(data: message.content, encoding:NSUTF8StringEncoding))

    // We only seem to get a 1x notification of a message. So this timer is folly.
    print("PING") //Only 1x per discovery.

}, messageLostHandler: {[unowned self](message: GNSMessage!) -> Void in
    self.messageViewController.removeMessage(String(data: message.content, encoding: NSUTF8StringEncoding))
}, paramsBlock: { (subParams: GNSSubscriptionParams!) -> Void in
    subParams.strategy = strategy
})

Notice that the "PING" only prints once.

1 Answers1

2

When a device goes out of range, Nearby waits for 2 minutes before flushing the other device's token from its cache. So if you wait for 2 minutes, the messageLost handler should be called. Can you verify this? Also, is it safe to assume that you'd like to have a timeout shorter than 2 minutes? This timeout has been a topic of discussion, and there's been some talk of adding a parameter so apps can choose a value that's more appropriate for its use case.

Dan Webb
  • 348
  • 1
  • 7
  • I'll verify this weekend or the latest on Monday. A parameter would be super wonderful with a default value of two minutes. – Radagast the Brown Jun 03 '16 at 22:00
  • I found it was more on the order of 3 minutes but close to 2 regardless. Again, a parameter would be wonderful. I understand why the default 2 minutes is being used and in some circumstances for what I am doing, it's fine. – Radagast the Brown Jun 06 '16 at 14:07
  • Thanks for the feedback! I won't let this issue drop on the floor. – Dan Webb Jun 07 '16 at 16:54