ojo / ios

:iphone:
0 stars 0 forks source link

Now Playing Info: Don't broadcast NPI if its expired. Check the timestamp + length on receipt. #56

Closed btc closed 7 years ago

btc commented 7 years ago

We now handle this in the playback manager:

https://github.com/ojo/ios/blob/master/ojo/PlaybackManager.swift#L192

private func incomingNowPlayingInfo(info: NowPlayingInfo) {

        // only proceed if there is a current station
        guard let station = station else { return }
        // ignore stale data
        guard info.stationTag == station.tag else { return }
        // make sure this info is current
        guard !info.expired() else { return }

        nowPlayingInfo = info

        // invalidate info if it's still around after expiry!
        guard info.expires() else { return }
        info.onExpiry().then { _ -> Void in

            // if there's no currentInfo, there's no point in doing anything else
            guard let currentInfo = self.nowPlayingInfo else { return }

            if currentInfo == info {
                // then it's time to say goodbye
                self.nowPlayingInfo = nil
            }
        }.catch { _ in
            print("tried to listen for expiry on a value that doesn't expire")
        }
    }

@ojo/android