diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140c..fb2dffc 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -27,8 +27,6 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> - - - - + + - - ) { + let castState = GCKCastContext.sharedInstance().castState + print("cast state change to: \(castState.rawValue)") + notifyCastState(castState: castState) + } + + private func notifyCastState(castState: GCKCastState) { + let castStateRaw = castState.rawValue + // Android CastStates are 1-to-4, while iOS CastStates are 0-to-3. I align iOS to Android by adding 1 + let castStateRawAdjusted = castStateRaw + 1 + self.channel.invokeMethod(MethodNames.onCastStateChanged.rawValue, arguments: castStateRawAdjusted) } public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { @@ -36,7 +98,67 @@ public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin { } deinit { - stateObserver?.invalidate() - stateObserver = nil + castStateObserver?.invalidate() + castStateObserver = nil + } + + // MARK: - GCKSessionManagerListener + + // onSessionSuspended + public func sessionManager(_ sessionManager: GCKSessionManager, didSuspend session: GCKCastSession, with reason: GCKConnectionSuspendReason) { + print("SessionListener: didSuspend") + channel.invokeMethod(MethodNames.onSessionSuspended.rawValue, arguments: nil) + } + + // onSessionStarting + public func sessionManager(_ sessionManager: GCKSessionManager, willStart session: GCKCastSession) { + print("SessionListener: willStart") + channel.invokeMethod(MethodNames.onSessionStarting.rawValue, arguments: nil) + + castSession = session + } + + // onSessionResuming + public func sessionManager(_ sessionManager: GCKSessionManager, willResumeCastSession session: GCKCastSession) { + print("SessionListener: willResumeCastSession") + channel.invokeMethod(MethodNames.onSessionResuming.rawValue, arguments: nil) + + castSession = session + } + + // onSessionEnding + public func sessionManager(_ sessionManager: GCKSessionManager, willEnd session: GCKCastSession) { + print("SessionListener: willEnd") + channel.invokeMethod(MethodNames.onSessionEnding.rawValue, arguments: nil) + } + + // onSessionStartFailed + public func sessionManager(_ sessionManager: GCKSessionManager, didFailToStart session: GCKCastSession, withError error: Error) { + print("SessionListener: didFailToStart") + channel.invokeMethod(MethodNames.onSessionStartFailed.rawValue, arguments: nil) + } + + // onSessionResumeFailed - Can't find this on iOS + + // onSessionStarted + public func sessionManager(_ sessionManager: GCKSessionManager, didStart session: GCKCastSession) { + print("SessionListener: didStart") + channel.invokeMethod(MethodNames.onSessionStarted.rawValue, arguments: nil) + + castSession = session + } + + // onSessionResumed + public func sessionManager(_ sessionManager: GCKSessionManager, didResumeCastSession session: GCKCastSession) { + print("SessionListener: didResumeCastSession") + channel.invokeMethod(MethodNames.onSessionResumed.rawValue, arguments: nil) + + castSession = session + } + + // onSessionEnded + public func sessionManager(_ sessionManager: GCKSessionManager, didEnd session: GCKCastSession, withError error: Error?) { + print("SessionListener: didEnd") + channel.invokeMethod(MethodNames.onSessionEnded.rawValue, arguments: nil) } }