Steve
Steve

Reputation: 55615

ChromeCast Sender Discovery Logic

The ChromeCast sample iOS Github project provided by Google attempts to reconnect to a previous device when a device is discovered.

The problem is that each time the app is backgrounded and foregrounded the discovery process occurs again and the previous device is connected to regardless if another application has connected to the Chromecast (see code below). This essentially clobbers the other application, and the current one takes over.

Is there anyway to determine whether another app has connected or not, and only attempt to connect if one has not?

- (void)deviceDidComeOnline:(GCKDevice *)device 
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString* lastDeviceID = [defaults objectForKey:@"lastDeviceID"];
    if (lastDeviceID != nil && [[device deviceID] isEqualToString:lastDeviceID])
    {
        self.isReconnecting = YES;
        [self connectToDevice:device];
    }
}

Upvotes: 0

Views: 68

Answers (1)

Ali Naddaf
Ali Naddaf

Reputation: 19094

Reconnection logic should take into account the previous session id; only reconnect if the current session id (on chromecast) matches with the (persisted) one on the phone. I haven't looked at the iOS app to know if it is being enforced there or not, but basically you can connect and then try to join (calling joinApplication) with the old session id and if it succeeds, then you are good and if not, then you should disconnect. Here is a set of diagrams that depict this flow.

Upvotes: 1

Related Questions