From c8c0c0e5b2c00808a38451922b678a20f63d0ce2 Mon Sep 17 00:00:00 2001 From: Sharad Binjola Date: Tue, 30 Apr 2024 12:42:05 -0700 Subject: [PATCH] iOS tv-casting-app: deprecating old casting impl, replacing with shim --- examples/tv-casting-app/APIs.md | 4 +- .../project.pbxproj | 112 +- .../CastingServerBridge.h | 1263 ---------------- .../CommissionableDataProviderImpl.hpp | 62 - .../CommissionableDataProviderImpl.mm | 209 --- ...viceAttestationCredentialsProviderImpl.hpp | 48 - ...eviceAttestationCredentialsProviderImpl.mm | 164 --- .../MatterTvCastingBridge/MCAttribute.h | 2 - .../MatterTvCastingBridge/MCCastingPlayer.h | 2 + .../MatterTvCastingBridge/MCCastingPlayer.mm | 24 + .../MCCastingPlayerDiscovery.mm | 2 +- .../MCCastingPlayer_Internal.h | 2 + .../MCDeviceAttestationCredentialsProvider.h | 3 +- .../MCDeviceAttestationCredentialsProvider.mm | 56 +- .../MatterTvCastingBridge/MCEndpoint.h | 2 +- .../MatterTvCastingBridge/MCEndpoint.mm | 28 +- .../MCEndpoint_Internal.h | 2 + .../MatterTvCastingBridge/MCErrorUtils.h | 2 + .../MatterTvCastingBridge/MCErrorUtils.mm | 4 + .../MatterTvCastingBridge/MatterError.mm | 2 +- .../MatterTvCastingBridge.h | 6 +- .../{ => compat-shim}/AppParameters.h | 1 + .../{ => compat-shim}/AppParameters.mm | 0 .../CastingPlayerDiscoveryListenerCompat.h | 34 + .../CastingPlayerDiscoveryListenerCompat.mm | 134 ++ .../compat-shim/CastingServerBridge.h | 739 ++++++++++ .../compat-shim/CastingServerBridge.mm | 1290 +++++++++++++++++ .../CommissioningCallbackHandlers.h | 14 +- .../CommissioningCallbackHandlers.m | 6 +- .../{ => compat-shim}/ContentApp.h | 5 + .../{ => compat-shim}/ContentApp.mm | 11 + .../{ => compat-shim}/ContentLauncherTypes.h | 0 .../{ => compat-shim}/ContentLauncherTypes.mm | 0 .../DataSourceCompat.h} | 19 +- .../compat-shim/DataSourceCompat.mm | 124 ++ .../DeviceAttestationCredentialsHolder.h | 1 + .../DeviceAttestationCredentialsHolder.m | 0 .../{ => compat-shim}/DiscoveredNodeData.h | 6 + .../{ => compat-shim}/DiscoveredNodeData.mm | 39 +- .../{ => compat-shim}/MediaPlaybackTypes.h | 0 .../{ => compat-shim}/MediaPlaybackTypes.mm | 0 .../{ => compat-shim}/OnboardingPayload.h | 0 .../{ => compat-shim}/OnboardingPayload.m | 0 .../{ => compat-shim}/TargetNavigatorTypes.h | 0 .../{ => compat-shim}/TargetNavigatorTypes.mm | 0 .../{ => compat-shim}/VideoPlayer.h | 7 + .../{ => compat-shim}/VideoPlayer.m | 32 + .../MCEndpointClusterType.h | 6 +- .../TvCasting.xcodeproj/project.pbxproj | 50 +- .../TvCasting/CommissioningViewModel.swift | 118 -- .../TvCasting/TvCasting/ConnectionView.swift | 78 - .../TvCasting/ConnectionViewModel.swift | 63 - .../TvCasting/TvCasting/ContentView.swift | 2 +- ...scribeToCurrentStateExampleViewModel.swift | 5 +- .../TvCasting/StartFromCacheView.swift | 83 -- .../TvCasting/StartFromCacheViewModel.swift | 50 - .../TvCasting/TvCasting/TvCastingApp.swift | 2 +- .../TvCasting/{ => compat}/CertTestView.swift | 0 .../{ => compat}/CertTestViewModel.swift | 14 +- .../{ => compat}/ClusterSelectorView.swift | 1 + .../CommissionerDiscoveryView.swift | 14 +- .../CommissionerDiscoveryViewModel.swift | 38 +- .../{ => compat}/CommissioningView.swift | 25 +- .../compat/CommissioningViewModel.swift | 118 ++ .../{ => compat}/ContentLauncherView.swift | 1 + .../ContentLauncherViewModel.swift | 8 +- .../TvCasting/{ => compat}/ExampleDAC.swift | 0 .../{ => compat}/MediaPlaybackView.swift | 1 + .../{ => compat}/MediaPlaybackViewModel.swift | 0 .../tv-casting-common/core/CastingPlayer.cpp | 1 + .../support/CastingStore.cpp | 8 +- .../support/ChipDeviceEventHandler.cpp | 18 +- 72 files changed, 2782 insertions(+), 2383 deletions(-) delete mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.h delete mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionableDataProviderImpl.hpp delete mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionableDataProviderImpl.mm delete mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsProviderImpl.hpp delete mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsProviderImpl.mm rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/AppParameters.h (91%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/AppParameters.mm (100%) create mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingPlayerDiscoveryListenerCompat.h create mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingPlayerDiscoveryListenerCompat.mm create mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.h create mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.mm rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/CommissioningCallbackHandlers.h (83%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/CommissioningCallbackHandlers.m (85%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/ContentApp.h (87%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/ContentApp.mm (87%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/ContentLauncherTypes.h (100%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/ContentLauncherTypes.mm (100%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{MCObserver.h => compat-shim/DataSourceCompat.h} (54%) create mode 100644 examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.mm rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/DeviceAttestationCredentialsHolder.h (94%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/DeviceAttestationCredentialsHolder.m (100%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/DiscoveredNodeData.h (86%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/DiscoveredNodeData.mm (62%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/MediaPlaybackTypes.h (100%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/MediaPlaybackTypes.mm (100%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/OnboardingPayload.h (100%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/OnboardingPayload.m (100%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/TargetNavigatorTypes.h (100%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/TargetNavigatorTypes.mm (100%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/VideoPlayer.h (89%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => compat-shim}/VideoPlayer.m (70%) rename examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/{ => zap-generated}/MCEndpointClusterType.h (82%) delete mode 100644 examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissioningViewModel.swift delete mode 100644 examples/tv-casting-app/darwin/TvCasting/TvCasting/ConnectionView.swift delete mode 100644 examples/tv-casting-app/darwin/TvCasting/TvCasting/ConnectionViewModel.swift delete mode 100644 examples/tv-casting-app/darwin/TvCasting/TvCasting/StartFromCacheView.swift delete mode 100644 examples/tv-casting-app/darwin/TvCasting/TvCasting/StartFromCacheViewModel.swift rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/CertTestView.swift (100%) rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/CertTestViewModel.swift (98%) rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/ClusterSelectorView.swift (97%) rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/CommissionerDiscoveryView.swift (82%) rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/CommissionerDiscoveryViewModel.swift (57%) rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/CommissioningView.swift (78%) create mode 100644 examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningViewModel.swift rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/ContentLauncherView.swift (97%) rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/ContentLauncherViewModel.swift (89%) rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/ExampleDAC.swift (100%) rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/MediaPlaybackView.swift (97%) rename examples/tv-casting-app/darwin/TvCasting/TvCasting/{ => compat}/MediaPlaybackViewModel.swift (100%) diff --git a/examples/tv-casting-app/APIs.md b/examples/tv-casting-app/APIs.md index 1bbb189e7179d7..76af45a2d326d4 100644 --- a/examples/tv-casting-app/APIs.md +++ b/examples/tv-casting-app/APIs.md @@ -1362,7 +1362,7 @@ if(currentStateAttribute == nil) } // call read on currentStateAttribute and pass in a completion block -currentStateAttribute!.read(nil) { context, before, after, err in +currentStateAttribute!.subscribe(nil, completion: { context, before, after, err in let dateFormatter = DateFormatter() dateFormatter.dateFormat = "HH:mm:ss" @@ -1386,7 +1386,7 @@ currentStateAttribute!.read(nil) { context, before, after, err in self.status = "Read CurrentState value: \(String(describing: after)) at \(currentTime)" } } -} +}, minInterval: 0, maxInterval: 1) ``` The Casting client can Shutdown all running Subscriptions by calling the diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge.xcodeproj/project.pbxproj b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge.xcodeproj/project.pbxproj index 5b1a37207b10b0..5df8ce26bf4019 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge.xcodeproj/project.pbxproj +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge.xcodeproj/project.pbxproj @@ -26,8 +26,6 @@ 3C2346232B362B9500FA276E /* MCCastingPlayerDiscovery.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C2346222B362B9500FA276E /* MCCastingPlayerDiscovery.h */; }; 3C2346252B362BBB00FA276E /* MCCastingPlayerDiscovery.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C2346242B362BBB00FA276E /* MCCastingPlayerDiscovery.mm */; }; 3C2696FB2B4A5FC50026E771 /* MCEndpointFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C2696FA2B4A5FC50026E771 /* MCEndpointFilter.m */; }; - 3C26AC8C2926FE0C00BA6881 /* DeviceAttestationCredentialsProviderImpl.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3C26AC8B2926FE0C00BA6881 /* DeviceAttestationCredentialsProviderImpl.hpp */; }; - 3C26AC902927008900BA6881 /* DeviceAttestationCredentialsProviderImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C26AC8F2927008900BA6881 /* DeviceAttestationCredentialsProviderImpl.mm */; }; 3C26AC9329282B8100BA6881 /* DeviceAttestationCredentialsHolder.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C26AC9229282B8100BA6881 /* DeviceAttestationCredentialsHolder.m */; }; 3C4AE650286A7D4D005B52A4 /* OnboardingPayload.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C4AE64F286A7D4D005B52A4 /* OnboardingPayload.m */; }; 3C4E53B028E4F28100F293E8 /* MediaPlaybackTypes.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C4E53AF28E4F28100F293E8 /* MediaPlaybackTypes.mm */; }; @@ -47,7 +45,6 @@ 3C4F522A2B51DFAE00BB8A10 /* MCCommand_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C4F52292B51DFAE00BB8A10 /* MCCommand_Internal.h */; }; 3C4F522C2B51E02800BB8A10 /* MCCommand.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C4F522B2B51E02800BB8A10 /* MCCommand.mm */; }; 3C621CA52B605A6A005CDBA3 /* MCAttribute.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C621CA42B605A6A005CDBA3 /* MCAttribute.h */; }; - 3C621CA72B605AA1005CDBA3 /* MCObserver.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C621CA62B605AA1005CDBA3 /* MCObserver.h */; }; 3C621CA92B605C52005CDBA3 /* MCAttribute_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C621CA82B605C52005CDBA3 /* MCAttribute_Internal.h */; }; 3C621CAB2B605C6E005CDBA3 /* MCAttribute.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C621CAA2B605C6E005CDBA3 /* MCAttribute.mm */; }; 3C66FBFC290327BB00B63FE7 /* AppParameters.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C66FBFB290327BB00B63FE7 /* AppParameters.mm */; }; @@ -58,15 +55,15 @@ 3C81C75028F7A7D3001CB9D1 /* VideoPlayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C81C74F28F7A7D3001CB9D1 /* VideoPlayer.m */; }; 3C9437922B3B478E0096E5F4 /* MCErrorUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 3C9437912B3B478E0096E5F4 /* MCErrorUtils.h */; }; 3C9437942B3B47A10096E5F4 /* MCErrorUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C9437932B3B47A10096E5F4 /* MCErrorUtils.mm */; }; + 3C996C272BD31FEA0027BD8A /* DataSourceCompat.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C996C262BD31FEA0027BD8A /* DataSourceCompat.mm */; }; + 3C996C2B2BD6F4960027BD8A /* CastingPlayerDiscoveryListenerCompat.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C996C2A2BD6F4950027BD8A /* CastingPlayerDiscoveryListenerCompat.mm */; }; + 3CC3979E2BE9857C00465462 /* MCCastingPlayer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3C9437882B364F5E0096E5F4 /* MCCastingPlayer.mm */; }; 3CCB87212869085400771BAD /* MatterTvCastingBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CCB87202869085400771BAD /* MatterTvCastingBridge.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3CCB8737286A555500771BAD /* libTvCastingCommon.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CCB8735286A555500771BAD /* libTvCastingCommon.a */; }; 3CCB873F286A593700771BAD /* DiscoveredNodeData.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3CCB8739286A593700771BAD /* DiscoveredNodeData.mm */; }; 3CCB8740286A593700771BAD /* CastingServerBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CCB873A286A593700771BAD /* CastingServerBridge.h */; }; 3CCB8741286A593700771BAD /* DiscoveredNodeData.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CCB873B286A593700771BAD /* DiscoveredNodeData.h */; }; - 3CCB8742286A593700771BAD /* ConversionUtils.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3CCB873C286A593700771BAD /* ConversionUtils.hpp */; }; 3CCB8743286A593700771BAD /* CastingServerBridge.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3CCB873D286A593700771BAD /* CastingServerBridge.mm */; }; - 3CCB8744286A593700771BAD /* ConversionUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3CCB873E286A593700771BAD /* ConversionUtils.mm */; }; - 3CD6D01A298CDA2100D7569A /* CommissionerDiscoveryDelegateImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CD6D019298CDA2100D7569A /* CommissionerDiscoveryDelegateImpl.h */; }; 3CD73F172A9E6884009D82D1 /* MCRotatingDeviceIdUniqueIdProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CD73F162A9E6884009D82D1 /* MCRotatingDeviceIdUniqueIdProvider.h */; }; 3CD73F192A9E68A7009D82D1 /* MCRotatingDeviceIdUniqueIdProvider.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3CD73F182A9E68A7009D82D1 /* MCRotatingDeviceIdUniqueIdProvider.mm */; }; 3CD73F1C2A9E8396009D82D1 /* MCCommissionableDataProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CD73F1B2A9E8396009D82D1 /* MCCommissionableDataProvider.h */; }; @@ -75,7 +72,6 @@ 3CD73F222A9EA078009D82D1 /* MCDeviceAttestationCredentials.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3CD73F212A9EA077009D82D1 /* MCDeviceAttestationCredentials.mm */; }; 3CE5ECCE2A673B30007CF331 /* CommissioningCallbackHandlers.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CE5ECCD2A673B30007CF331 /* CommissioningCallbackHandlers.h */; }; 3CE5ECD02A673E2C007CF331 /* CommissioningCallbackHandlers.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CE5ECCF2A673E2C007CF331 /* CommissioningCallbackHandlers.m */; }; - 3CE868F42946D76200FCB92B /* CommissionableDataProviderImpl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3CE868F32946D76200FCB92B /* CommissionableDataProviderImpl.mm */; }; 3CF71C0A2A992D0D003A5CE5 /* MCCastingApp.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CF71C092A992D0D003A5CE5 /* MCCastingApp.h */; }; 3CF71C0C2A992D25003A5CE5 /* MCCastingApp.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3CF71C0B2A992D25003A5CE5 /* MCCastingApp.mm */; }; 3CF71C0E2A992DA2003A5CE5 /* MCDataSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 3CF71C0D2A992DA2003A5CE5 /* MCDataSource.h */; }; @@ -101,13 +97,10 @@ 3C0474052B3F7E5F0012AE95 /* MCEndpointFilter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCEndpointFilter.h; sourceTree = ""; }; 3C04740B2B4604CF0012AE95 /* MCCryptoUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCCryptoUtils.h; sourceTree = ""; }; 3C04740D2B4605B40012AE95 /* MCCryptoUtils.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCCryptoUtils.mm; sourceTree = ""; }; - 3C0D9CDF2920A30C00D3332B /* CommissionableDataProviderImpl.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CommissionableDataProviderImpl.hpp; sourceTree = ""; }; 3C2346202B362B4F00FA276E /* MCCastingPlayer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCCastingPlayer.h; sourceTree = ""; }; 3C2346222B362B9500FA276E /* MCCastingPlayerDiscovery.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCCastingPlayerDiscovery.h; sourceTree = ""; }; 3C2346242B362BBB00FA276E /* MCCastingPlayerDiscovery.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCCastingPlayerDiscovery.mm; sourceTree = ""; }; 3C2696FA2B4A5FC50026E771 /* MCEndpointFilter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MCEndpointFilter.m; sourceTree = ""; }; - 3C26AC8B2926FE0C00BA6881 /* DeviceAttestationCredentialsProviderImpl.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = DeviceAttestationCredentialsProviderImpl.hpp; sourceTree = ""; }; - 3C26AC8F2927008900BA6881 /* DeviceAttestationCredentialsProviderImpl.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceAttestationCredentialsProviderImpl.mm; sourceTree = ""; }; 3C26AC91292700AD00BA6881 /* DeviceAttestationCredentialsHolder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeviceAttestationCredentialsHolder.h; sourceTree = ""; }; 3C26AC9229282B8100BA6881 /* DeviceAttestationCredentialsHolder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceAttestationCredentialsHolder.m; sourceTree = ""; }; 3C4AE64E286A7D40005B52A4 /* OnboardingPayload.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OnboardingPayload.h; sourceTree = ""; }; @@ -131,7 +124,6 @@ 3C4F52292B51DFAE00BB8A10 /* MCCommand_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCCommand_Internal.h; sourceTree = ""; }; 3C4F522B2B51E02800BB8A10 /* MCCommand.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCCommand.mm; sourceTree = ""; }; 3C621CA42B605A6A005CDBA3 /* MCAttribute.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCAttribute.h; sourceTree = ""; }; - 3C621CA62B605AA1005CDBA3 /* MCObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCObserver.h; sourceTree = ""; }; 3C621CA82B605C52005CDBA3 /* MCAttribute_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCAttribute_Internal.h; sourceTree = ""; }; 3C621CAA2B605C6E005CDBA3 /* MCAttribute.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCAttribute.mm; sourceTree = ""; }; 3C66FBFA2903279A00B63FE7 /* AppParameters.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppParameters.h; sourceTree = ""; }; @@ -146,6 +138,10 @@ 3C9437882B364F5E0096E5F4 /* MCCastingPlayer.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCCastingPlayer.mm; sourceTree = ""; }; 3C9437912B3B478E0096E5F4 /* MCErrorUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCErrorUtils.h; sourceTree = ""; }; 3C9437932B3B47A10096E5F4 /* MCErrorUtils.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCErrorUtils.mm; sourceTree = ""; }; + 3C996C252BD31FD60027BD8A /* DataSourceCompat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DataSourceCompat.h; sourceTree = ""; }; + 3C996C262BD31FEA0027BD8A /* DataSourceCompat.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DataSourceCompat.mm; sourceTree = ""; }; + 3C996C292BD6F4800027BD8A /* CastingPlayerDiscoveryListenerCompat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CastingPlayerDiscoveryListenerCompat.h; sourceTree = ""; }; + 3C996C2A2BD6F4950027BD8A /* CastingPlayerDiscoveryListenerCompat.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CastingPlayerDiscoveryListenerCompat.mm; sourceTree = ""; }; 3CA1CA7728E243750023ED44 /* MediaPlaybackTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaPlaybackTypes.h; sourceTree = ""; }; 3CCB871D2869085400771BAD /* MatterTvCastingBridge.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MatterTvCastingBridge.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3CCB87202869085400771BAD /* MatterTvCastingBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MatterTvCastingBridge.h; sourceTree = ""; }; @@ -153,10 +149,7 @@ 3CCB8739286A593700771BAD /* DiscoveredNodeData.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DiscoveredNodeData.mm; sourceTree = ""; }; 3CCB873A286A593700771BAD /* CastingServerBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CastingServerBridge.h; sourceTree = ""; }; 3CCB873B286A593700771BAD /* DiscoveredNodeData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiscoveredNodeData.h; sourceTree = ""; }; - 3CCB873C286A593700771BAD /* ConversionUtils.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = ConversionUtils.hpp; sourceTree = ""; }; 3CCB873D286A593700771BAD /* CastingServerBridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CastingServerBridge.mm; sourceTree = ""; }; - 3CCB873E286A593700771BAD /* ConversionUtils.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ConversionUtils.mm; sourceTree = ""; }; - 3CD6D019298CDA2100D7569A /* CommissionerDiscoveryDelegateImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommissionerDiscoveryDelegateImpl.h; sourceTree = ""; }; 3CD73F162A9E6884009D82D1 /* MCRotatingDeviceIdUniqueIdProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCRotatingDeviceIdUniqueIdProvider.h; sourceTree = ""; }; 3CD73F182A9E68A7009D82D1 /* MCRotatingDeviceIdUniqueIdProvider.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCRotatingDeviceIdUniqueIdProvider.mm; sourceTree = ""; }; 3CD73F1B2A9E8396009D82D1 /* MCCommissionableDataProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCCommissionableDataProvider.h; sourceTree = ""; }; @@ -165,7 +158,6 @@ 3CD73F212A9EA077009D82D1 /* MCDeviceAttestationCredentials.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCDeviceAttestationCredentials.mm; sourceTree = ""; }; 3CE5ECCD2A673B30007CF331 /* CommissioningCallbackHandlers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CommissioningCallbackHandlers.h; sourceTree = ""; }; 3CE5ECCF2A673E2C007CF331 /* CommissioningCallbackHandlers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CommissioningCallbackHandlers.m; sourceTree = ""; }; - 3CE868F32946D76200FCB92B /* CommissionableDataProviderImpl.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CommissionableDataProviderImpl.mm; sourceTree = ""; }; 3CF71C092A992D0D003A5CE5 /* MCCastingApp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCCastingApp.h; sourceTree = ""; }; 3CF71C0B2A992D25003A5CE5 /* MCCastingApp.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MCCastingApp.mm; sourceTree = ""; }; 3CF71C0D2A992DA2003A5CE5 /* MCDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MCDataSource.h; sourceTree = ""; }; @@ -201,29 +193,42 @@ 39DB29E82B9A3B1D0071334A /* MCCommandPayloads.h */, 39DB29EA2B9A3B2D0071334A /* MCCommandPayloads.mm */, 399049A62B9FC4ED000C91F0 /* MCCommandPayloads_Internal.h */, + 3C4F521F2B507C4A00BB8A10 /* MCEndpointClusterType.h */, ); path = "zap-generated"; sourceTree = ""; }; - 3C94378A2B3654720096E5F4 /* Core */ = { - isa = PBXGroup; - children = ( - ); - path = Core; - sourceTree = ""; - }; - 3C94378B2B36547A0096E5F4 /* Support */ = { - isa = PBXGroup; - children = ( - ); - path = Support; - sourceTree = ""; - }; - 3C94378C2B3654960096E5F4 /* Clusters */ = { + 3C996C282BD3287D0027BD8A /* compat-shim */ = { isa = PBXGroup; children = ( + 3CCB873A286A593700771BAD /* CastingServerBridge.h */, + 3CCB873D286A593700771BAD /* CastingServerBridge.mm */, + 3C996C252BD31FD60027BD8A /* DataSourceCompat.h */, + 3C996C262BD31FEA0027BD8A /* DataSourceCompat.mm */, + 3C996C292BD6F4800027BD8A /* CastingPlayerDiscoveryListenerCompat.h */, + 3C996C2A2BD6F4950027BD8A /* CastingPlayerDiscoveryListenerCompat.mm */, + 3C66FBFA2903279A00B63FE7 /* AppParameters.h */, + 3C66FBFB290327BB00B63FE7 /* AppParameters.mm */, + 3CCB873B286A593700771BAD /* DiscoveredNodeData.h */, + 3CCB8739286A593700771BAD /* DiscoveredNodeData.mm */, + 3C4AE64E286A7D40005B52A4 /* OnboardingPayload.h */, + 3C4AE64F286A7D4D005B52A4 /* OnboardingPayload.m */, + 3C81C74E28F7A7AE001CB9D1 /* ContentApp.h */, + 3C81C74B28F7A777001CB9D1 /* ContentApp.mm */, + 3C81C75128F7A7DF001CB9D1 /* VideoPlayer.h */, + 3C81C74F28F7A7D3001CB9D1 /* VideoPlayer.m */, + 3C4E53B428E5593700F293E8 /* ContentLauncherTypes.h */, + 3C4E53B528E5595A00F293E8 /* ContentLauncherTypes.mm */, + 3CA1CA7728E243750023ED44 /* MediaPlaybackTypes.h */, + 3C4E53AF28E4F28100F293E8 /* MediaPlaybackTypes.mm */, + 3C4E53B328E5185F00F293E8 /* TargetNavigatorTypes.h */, + 3C4E53B128E5184C00F293E8 /* TargetNavigatorTypes.mm */, + 3C26AC91292700AD00BA6881 /* DeviceAttestationCredentialsHolder.h */, + 3C26AC9229282B8100BA6881 /* DeviceAttestationCredentialsHolder.m */, + 3CE5ECCD2A673B30007CF331 /* CommissioningCallbackHandlers.h */, + 3CE5ECCF2A673E2C007CF331 /* CommissioningCallbackHandlers.m */, ); - path = Clusters; + path = "compat-shim"; sourceTree = ""; }; 3CCB87132869085400771BAD = { @@ -246,10 +251,8 @@ 3CCB871F2869085400771BAD /* MatterTvCastingBridge */ = { isa = PBXGroup; children = ( + 3C996C282BD3287D0027BD8A /* compat-shim */, 395241F42B854EA700F7DB91 /* zap-generated */, - 3C94378A2B3654720096E5F4 /* Core */, - 3C94378B2B36547A0096E5F4 /* Support */, - 3C94378C2B3654960096E5F4 /* Clusters */, 3CCB87202869085400771BAD /* MatterTvCastingBridge.h */, 3CF71C092A992D0D003A5CE5 /* MCCastingApp.h */, 3CF71C0B2A992D25003A5CE5 /* MCCastingApp.mm */, @@ -267,11 +270,9 @@ 3C4F52272B51DB3000BB8A10 /* MCCommand.h */, 3C4F52292B51DFAE00BB8A10 /* MCCommand_Internal.h */, 3C4F522B2B51E02800BB8A10 /* MCCommand.mm */, - 3C621CA62B605AA1005CDBA3 /* MCObserver.h */, 3C621CA42B605A6A005CDBA3 /* MCAttribute.h */, 3C621CA82B605C52005CDBA3 /* MCAttribute_Internal.h */, 3C621CAA2B605C6E005CDBA3 /* MCAttribute.mm */, - 3C4F521F2B507C4A00BB8A10 /* MCEndpointClusterType.h */, 3C4F52132B4F31DC00BB8A10 /* MCDeviceTypeStruct.h */, 3C4F52152B4F31FA00BB8A10 /* MCDeviceTypeStruct.m */, 3C0474052B3F7E5F0012AE95 /* MCEndpointFilter.h */, @@ -296,35 +297,6 @@ 3C04740D2B4605B40012AE95 /* MCCryptoUtils.mm */, 39BF57CA2B8E54F80081653C /* NSDataSpanConversion.h */, 39BF57C82B8D66540081653C /* NSStringSpanConversion.h */, - 3CCB873A286A593700771BAD /* CastingServerBridge.h */, - 3CCB873D286A593700771BAD /* CastingServerBridge.mm */, - 3C66FBFA2903279A00B63FE7 /* AppParameters.h */, - 3C66FBFB290327BB00B63FE7 /* AppParameters.mm */, - 3CCB873B286A593700771BAD /* DiscoveredNodeData.h */, - 3CCB8739286A593700771BAD /* DiscoveredNodeData.mm */, - 3CCB873C286A593700771BAD /* ConversionUtils.hpp */, - 3CCB873E286A593700771BAD /* ConversionUtils.mm */, - 3C4AE64E286A7D40005B52A4 /* OnboardingPayload.h */, - 3C4AE64F286A7D4D005B52A4 /* OnboardingPayload.m */, - 3C81C74E28F7A7AE001CB9D1 /* ContentApp.h */, - 3C81C74B28F7A777001CB9D1 /* ContentApp.mm */, - 3C81C75128F7A7DF001CB9D1 /* VideoPlayer.h */, - 3C81C74F28F7A7D3001CB9D1 /* VideoPlayer.m */, - 3C4E53B428E5593700F293E8 /* ContentLauncherTypes.h */, - 3C4E53B528E5595A00F293E8 /* ContentLauncherTypes.mm */, - 3CA1CA7728E243750023ED44 /* MediaPlaybackTypes.h */, - 3C4E53AF28E4F28100F293E8 /* MediaPlaybackTypes.mm */, - 3C4E53B328E5185F00F293E8 /* TargetNavigatorTypes.h */, - 3C4E53B128E5184C00F293E8 /* TargetNavigatorTypes.mm */, - 3C26AC91292700AD00BA6881 /* DeviceAttestationCredentialsHolder.h */, - 3C26AC9229282B8100BA6881 /* DeviceAttestationCredentialsHolder.m */, - 3C26AC8B2926FE0C00BA6881 /* DeviceAttestationCredentialsProviderImpl.hpp */, - 3C26AC8F2927008900BA6881 /* DeviceAttestationCredentialsProviderImpl.mm */, - 3C0D9CDF2920A30C00D3332B /* CommissionableDataProviderImpl.hpp */, - 3CE868F32946D76200FCB92B /* CommissionableDataProviderImpl.mm */, - 3CD6D019298CDA2100D7569A /* CommissionerDiscoveryDelegateImpl.h */, - 3CE5ECCD2A673B30007CF331 /* CommissioningCallbackHandlers.h */, - 3CE5ECCF2A673E2C007CF331 /* CommissioningCallbackHandlers.m */, ); path = MatterTvCastingBridge; sourceTree = ""; @@ -339,12 +311,10 @@ 3C69204C2AA136BA00D0F613 /* MCCommonCaseDeviceServerInitParamsProvider.h in Headers */, 3C2346212B362B4F00FA276E /* MCCastingPlayer.h in Headers */, 3C2346232B362B9500FA276E /* MCCastingPlayerDiscovery.h in Headers */, - 3CD6D01A298CDA2100D7569A /* CommissionerDiscoveryDelegateImpl.h in Headers */, 3CF71C0E2A992DA2003A5CE5 /* MCDataSource.h in Headers */, 3C4F52142B4F31DC00BB8A10 /* MCDeviceTypeStruct.h in Headers */, 39BF57CD2B8FC0EF0081653C /* MCClusterObjects.h in Headers */, 39D4D2502B97942D00BF3CFE /* MCCommandObjects.h in Headers */, - 3C26AC8C2926FE0C00BA6881 /* DeviceAttestationCredentialsProviderImpl.hpp in Headers */, 3C621CA52B605A6A005CDBA3 /* MCAttribute.h in Headers */, 3CD73F1C2A9E8396009D82D1 /* MCCommissionableDataProvider.h in Headers */, 3C4F521E2B4F4B3B00BB8A10 /* MCEndpoint_Internal.h in Headers */, @@ -364,8 +334,6 @@ 3CCB8740286A593700771BAD /* CastingServerBridge.h in Headers */, 3CE5ECCE2A673B30007CF331 /* CommissioningCallbackHandlers.h in Headers */, 39589F162B91556B00BE040C /* MCInteractionModelStructs.h in Headers */, - 3CCB8742286A593700771BAD /* ConversionUtils.hpp in Headers */, - 3C621CA72B605AA1005CDBA3 /* MCObserver.h in Headers */, 3C9437922B3B478E0096E5F4 /* MCErrorUtils.h in Headers */, 3C4F52222B507C9300BB8A10 /* MCCluster.h in Headers */, 3CCB8741286A593700771BAD /* DiscoveredNodeData.h in Headers */, @@ -486,8 +454,8 @@ 3C4F522C2B51E02800BB8A10 /* MCCommand.mm in Sources */, 3C4E53B628E5595A00F293E8 /* ContentLauncherTypes.mm in Sources */, 3C81C75028F7A7D3001CB9D1 /* VideoPlayer.m in Sources */, - 3CCB8744286A593700771BAD /* ConversionUtils.mm in Sources */, 3CF71C0C2A992D25003A5CE5 /* MCCastingApp.mm in Sources */, + 3CC3979E2BE9857C00465462 /* MCCastingPlayer.mm in Sources */, 3C621CAB2B605C6E005CDBA3 /* MCAttribute.mm in Sources */, 3C4F52122B4E18ED00BB8A10 /* MCEndpoint.mm in Sources */, 3C4E53B028E4F28100F293E8 /* MediaPlaybackTypes.mm in Sources */, @@ -499,14 +467,14 @@ 3C4F52242B507CA800BB8A10 /* MCCluster.mm in Sources */, 3C66FBFC290327BB00B63FE7 /* AppParameters.mm in Sources */, 3C9437942B3B47A10096E5F4 /* MCErrorUtils.mm in Sources */, - 3CE868F42946D76200FCB92B /* CommissionableDataProviderImpl.mm in Sources */, 3C26AC9329282B8100BA6881 /* DeviceAttestationCredentialsHolder.m in Sources */, - 3C26AC902927008900BA6881 /* DeviceAttestationCredentialsProviderImpl.mm in Sources */, + 3C996C272BD31FEA0027BD8A /* DataSourceCompat.mm in Sources */, 3CCB873F286A593700771BAD /* DiscoveredNodeData.mm in Sources */, 39D4D2522B97943D00BF3CFE /* MCCommandObjects.mm in Sources */, 3C4F52162B4F31FA00BB8A10 /* MCDeviceTypeStruct.m in Sources */, 3C2696FB2B4A5FC50026E771 /* MCEndpointFilter.m in Sources */, 3C81C74C28F7A777001CB9D1 /* ContentApp.mm in Sources */, + 3C996C2B2BD6F4960027BD8A /* CastingPlayerDiscoveryListenerCompat.mm in Sources */, 3CF71C122A993298003A5CE5 /* MCCommissionableData.mm in Sources */, 3C4AE650286A7D4D005B52A4 /* OnboardingPayload.m in Sources */, ); diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.h deleted file mode 100644 index 2489f982fb0645..00000000000000 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.h +++ /dev/null @@ -1,1263 +0,0 @@ -/** - * - * Copyright (c) 2020-2023 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "AppParameters.h" -#import "CommissioningCallbackHandlers.h" -#import "ContentApp.h" -#import "ContentLauncherTypes.h" -#import "DiscoveredNodeData.h" -#import "MatterError.h" -#import "MediaPlaybackTypes.h" -#import "OnboardingPayload.h" -#import "TargetNavigatorTypes.h" -#import "VideoPlayer.h" -#import - -#ifndef CastingServerBridge_h -#define CastingServerBridge_h - -@interface CastingServerBridge : NSObject - -+ (CastingServerBridge * _Nullable)getSharedInstance; - -- (MatterError * _Nonnull)initializeApp:(AppParameters * _Nullable)appParameters - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - initAppStatusHandler:(nullable void (^)(bool))initAppStatusHandler; - -- (void)setDacHolder:(DeviceAttestationCredentialsHolder * _Nonnull)deviceAttestationCredentials - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - setDacHolderStatus:(void (^_Nonnull)(MatterError * _Nonnull))setDacHolderStatus; - -/*! - @brief Browse for on-network commissioner TVs - - @param clientQueue Queue to dispatch the call to the discoveryRequestSentHandler on - - @param discoveryRequestSentHandler Handler to call after the Commissioner discovery request has been sent - */ -- (void)discoverCommissioners:(dispatch_queue_t _Nonnull)clientQueue - discoveryRequestSentHandler:(nullable void (^)(bool))discoveryRequestSentHandler - discoveredCommissionerHandler:(nullable void (^)(DiscoveredNodeData * _Nonnull))discoveredCommissionerHandler; - -/*! - @brief Retrieve a discovered commissioner TV - - @param index Index in the list of discovered commissioners - - @param clientQueue Queue to dispatch the call to the discoveredCommissionerHandler on - - @param discoveredCommissionerHandler Handler called synchronously after a discovered commissioner has been retrieved - */ -- (void)getDiscoveredCommissioner:(int)index - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - discoveredCommissionerHandler:(nullable void (^)(DiscoveredNodeData * _Nullable))discoveredCommissionerHandler; - -/*! - @brief Send a User Directed Commissioning request to a commissioner TV - - @param commissionerIpAddress IP address of the commissioner - - @param commissionerPort Port number at which the commissioner is listening for User Directed Commissioning requests - - @param platformInterface Platform representation of the commissioner's IP address's interface - - @param clientQueue Queue to dispatch the call to the udcRequestSentHandler on - - @param udcRequestSentHandler Handler to call on sending the User Directed Commissioning request - */ -- (void)sendUserDirectedCommissioningRequest:(NSString * _Nonnull)commissionerIpAddress - commissionerPort:(uint16_t)commissionerPort - platformInterface:(unsigned int)platformInterface - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - udcRequestSentHandler:(nullable void (^)(bool))udcRequestSentHandler; - -/*! - @brief Send a User Directed Commissioning request to a commissioner TV - - @param commissioner Commissioner to request commissioning from - - @param clientQueue Queue to dispatch the call to the udcRequestSentHandler on - - @param udcRequestSentHandler Handler to call on sending the User Directed Commissioning request - */ -- (void)sendUserDirectedCommissioningRequest:(DiscoveredNodeData * _Nonnull)commissioner - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - udcRequestSentHandler:(nullable void (^)(bool))udcRequestSentHandler; - -/*! - @brief Return the onboarding payload for this app (setup passcode, discriminator) - - @return Onboarding payload - */ -- (OnboardingPayload * _Nonnull)getOnboardingPayload; - -/*! - @brief Request opening of a basic commissioning window - - @param clientQueue Queue to dispatch the call to the commissioningWindowRequestedHandler on - - @param commissioningCallbackHandlers Optional parameter to specific handlers for callbacks during commissioning - - @param onConnectionSuccessCallback Handles a VideoPlayer * once connection is successfully established - - @param onConnectionFailureCallback Handles MatterError if there is a failure in establishing connection - - @param onNewOrUpdatedEndpointCallback Handles a ContentApp * for each new ContentApp is found. May be called multiple times based - on the number of ContentApp - */ -- (void)openBasicCommissioningWindow:(dispatch_queue_t _Nonnull)clientQueue - commissioningCallbackHandlers:(CommissioningCallbackHandlers * _Nullable)commissioningCallbackHandlers - onConnectionSuccessCallback:(void (^_Nonnull)(VideoPlayer * _Nonnull))onConnectionSuccessCallback - onConnectionFailureCallback:(void (^_Nonnull)(MatterError * _Nonnull))onConnectionFailureCallback - onNewOrUpdatedEndpointCallback:(void (^_Nonnull)(ContentApp * _Nonnull))onNewOrUpdatedEndpointCallback; - -/*! - @brief Gets the list of VideoPlayers currently connected - - @param clientQueue Queue to invoke callbacks on - - @param activeTargetVideoPlayersHandler Handles NSMutableArray of active/currently connected VideoPlayers. Nil, if no such - VideoPlayers are found. - */ -- (void)getActiveTargetVideoPlayers:(dispatch_queue_t _Nonnull)clientQueue - activeTargetVideoPlayersHandler:(nullable void (^)(NSMutableArray * _Nullable))activeTargetVideoPlayersHandler; - -/*! - @brief Reads all previously connected video players from cache. These are not connected. - - @param clientQueue Queue to invoke callbacks on - - @param readCachedVideoPlayersHandler Handles NSMutableArray of VideoPlayers from the cache. Empty, if no such VideoPlayers are - found. - */ -- (void)readCachedVideoPlayers:(dispatch_queue_t _Nonnull)clientQueue - readCachedVideoPlayersHandler:(nullable void (^)(NSMutableArray * _Nullable))readCachedVideoPlayersHandler; - -/*! - @brief Verify if a connection exists or connect to the VideoPlayer passed in as parameter. - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handles MatterError and called after the request has been sent - - @param onConnectionSuccessCallback Handles a VideoPlayer * once connection is successfully established - - @param onConnectionFailureCallback Handles MatterError if there is a failure in establishing connection - - @param onNewOrUpdatedEndpointCallback Handles a ContentApp * for each new ContentApp is found. May be called multiple times based - on the number of ContentApp - */ -- (void)verifyOrEstablishConnection:(VideoPlayer * _Nonnull)videoPlayer - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(nullable void (^)(MatterError * _Nonnull))requestSentHandler - onConnectionSuccessCallback:(void (^_Nonnull)(VideoPlayer * _Nonnull))onConnectionSuccessCallback - onConnectionFailureCallback:(void (^_Nonnull)(MatterError * _Nonnull))onConnectionFailureCallback - onNewOrUpdatedEndpointCallback:(void (^_Nonnull)(ContentApp * _Nonnull))onNewOrUpdatedEndpointCallback; - -/*! - @brief Tears down all active subscriptions. - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Called after the request has been sent - */ -- (void)shutdownAllSubscriptions:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nullable void (^)())requestSentHandler; - -/*! - @brief Mark any open session with the currently connected Video player as expired. - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Called after the request has been sent - */ -- (void)disconnect:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nullable void (^)())requestSentHandler; - -/*! - @brief Purge data cached by the Matter casting library - - @param clientQueue Queue to invoke callbacks on - - @param responseHandler Called when purgeCache completes - */ -- (void)purgeCache:(dispatch_queue_t _Nonnull)clientQueue responseHandler:(void (^_Nonnull)(MatterError * _Nonnull))responseHandler; - -/*! - @brief Start the Matter server and reconnect to a previously connected Video Player (if any). This API is async - - @param clientQueue Queue to invoke callbacks on - - @param startMatterServerCompletionCallback Called after the Matter server has started and connected (or failed to connect) to a - previously connected video player (if any) are complete - */ -- (void)startMatterServer:(dispatch_queue_t _Nonnull)clientQueue - startMatterServerCompletionCallback:(nullable void (^)(MatterError * _Nonnull))startMatterServerCompletionCallback; - -/** - @brief Stop the Matter server - */ -- (void)stopMatterServer; - -/*! - @brief Send a ContentLauncher:LaunchURL request to a TV - - @param contentApp Content app endpoint to target - - @param contentUrl URL of the content to launch on the TV - - @param contentDisplayStr Display string value corresponding to the content - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)contentLauncher_launchUrl:(ContentApp * _Nonnull)contentApp - contentUrl:(NSString * _Nonnull)contentUrl - contentDisplayStr:(NSString * _Nonnull)contentDisplayStr - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a ContentLauncher:LaunchContent request to a TV - - @param contentApp Content app endpoint to target - - @param contentSearch Indicates the content to launch - - @param autoPlay Play Best match automatically if true, otherwise display matches - - @param data App specific data to be passed to the TV - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)contentLauncher_launchContent:(ContentApp * _Nonnull)contentApp - contentSearch:(ContentLauncher_ContentSearch * _Nonnull)contentSearch - autoPlay:(bool)autoPlay - data:(NSString * _Nullable)data - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Subscribe to ContentLauncher:SupportedStreamingProtocols - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)contentLauncher_subscribeSupportedStreamingProtocols:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(uint32_t))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Send a LevelControl:Step request to a TV - - @param contentApp Content app endpoint to target - - @param stepMode Increase (0x00) or Decrease (0x01) the device’s level - - @param stepSize Number of units to step the device's level by - - @param transitionTime Time that SHALL be taken to perform the step, in tenths of a second - - @param optionMask Used to create a temporary Options bitmap to construct the Options attribute - - @param optionOverride Used to create a temporary Options bitmap to construct the Options attribute - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)levelControl_step:(ContentApp * _Nonnull)contentApp - stepMode:(uint8_t)stepMode - stepSize:(uint8_t)stepSize - transitionTime:(uint16_t)transitionTime - optionMask:(uint8_t)optionMask - optionOverride:(uint8_t)optionOverride - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a LevelControl:MoveToLevel request to a TV - - @param contentApp Content app endpoint to target - - @param level the level to which the device should move - - @param transitionTime Time that SHALL be taken to perform the step, in tenths of a second - - @param optionMask Used to create a temporary Options bitmap to construct the Options attribute - - @param optionOverride Used to create a temporary Options bitmap to construct the Options attribute - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)levelControl_moveToLevel:(ContentApp * _Nonnull)contentApp - level:(uint8_t)level - transitionTime:(uint16_t)transitionTime - optionMask:(uint8_t)optionMask - optionOverride:(uint8_t)optionOverride - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Subscribe to LevelControl:CurrentLevel - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)levelControl_subscribeCurrentLevel:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSNumber * _Nullable))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to LevelControl:MinLevel - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)levelControl_subscribeMinLevel:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(uint8_t))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to LevelControl:MaxLevel - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)levelControl_subscribeMaxLevel:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(uint8_t))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Send a MediaPlayback:Play request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_play:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:Pause request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_pause:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:StopPlayback request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_stopPlayback:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:Next request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_next:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:Previous request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_previous:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:FastForward request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_fastForward:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:Rewind request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_rewind:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:StartOver request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_startOver:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:Seek request to a TV - - @param contentApp Content app endpoint to target - - @param position the position (in milliseconds) in the media to seek to - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_seek:(ContentApp * _Nonnull)contentApp - position:(uint64_t)position - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:SkipForward request to a TV - - @param contentApp Content app endpoint to target - - @param deltaPositionMilliseconds the duration of the time span to skip forward in the media, in milliseconds - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_skipForward:(ContentApp * _Nonnull)contentApp - deltaPositionMilliseconds:(uint64_t)deltaPositionMilliseconds - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a MediaPlayback:SkipBackward request to a TV - - @param contentApp Content app endpoint to target - - @param deltaPositionMilliseconds the duration of the time span to skip backward in the media, in milliseconds - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)mediaPlayback_skipBackward:(ContentApp * _Nonnull)contentApp - deltaPositionMilliseconds:(uint64_t)deltaPositionMilliseconds - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Subscribe to MediaPlayback:CurrentState - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)mediaPlayback_subscribeCurrentState:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(MediaPlayback_PlaybackState))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to MediaPlayback:StartTime - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)mediaPlayback_subscribeStartTime:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSNumber * _Nullable))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to MediaPlayback:Duration - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)mediaPlayback_subscribeDuration:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSNumber * _Nullable))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to MediaPlayback:SampledPosition - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)mediaPlayback_subscribeSampledPosition:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(MediaPlayback_PlaybackPosition * _Nullable))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to MediaPlayback:PlaybackSpeed - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)mediaPlayback_subscribePlaybackSpeed:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(float))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to MediaPlayback:SeekRangeEnd - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)mediaPlayback_subscribeSeekRangeEnd:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSNumber * _Nullable))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to MediaPlayback:SeekRangeStart - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)mediaPlayback_subscribeSeekRangeStart:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSNumber * _Nullable))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; -/*! - @brief Send a ApplicationLauncher:LaunchApp request to a TV - - @param contentApp Content app endpoint to target - - @param catalogVendorId CSA-issued vendor ID for the catalog - - @param applicationId application identifier, unique within a catalog, expressed as a string, such as "PruneVideo" or "Company X" - - @param data optional app-specific data to be sent to the app - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)applicationLauncher_launchApp:(ContentApp * _Nonnull)contentApp - catalogVendorId:(uint16_t)catalogVendorId - applicationId:(NSString * _Nonnull)applicationId - data:(NSData * _Nullable)data - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a ApplicationLauncher:StopApp request to a TV - - @param contentApp Content app endpoint to target - - @param catalogVendorId CSA-issued vendor ID for the catalog - - @param applicationId application identifier, unique within a catalog, expressed as a string, such as "PruneVideo" or "Company X" - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)applicationLauncher_stopApp:(ContentApp * _Nonnull)contentApp - catalogVendorId:(uint16_t)catalogVendorId - applicationId:(NSString * _Nonnull)applicationId - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a ApplicationLauncher:HideApp request to a TV - - @param contentApp Content app endpoint to target - - @param catalogVendorId CSA-issued vendor ID for the catalog - - @param applicationId application identifier, unique within a catalog, expressed as a string, such as "PruneVideo" or "Company X" - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)applicationLauncher_hideApp:(ContentApp * _Nonnull)contentApp - catalogVendorId:(uint16_t)catalogVendorId - applicationId:(NSString * _Nonnull)applicationId - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a TargetNavigator:NavigateTarget request to a TV - - @param contentApp Content app endpoint to target - - @param target Identifier for the target for UX navigation, contained within one of the TargetInfo objects in the TargetList - attribute list. - - @param data Optional app-specific data - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)targetNavigator_navigateTarget:(ContentApp * _Nonnull)contentApp - target:(uint8_t)target - data:(NSString * _Nullable)data - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Subscribe to TargetNavigator:TargetList - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)targetNavigator_subscribeTargetList:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSMutableArray * _Nullable))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to TargetNavigator:CurrentTarget - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)targetNavigator_subscribeCurrentTarget:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(uint8_t))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Send a KeypadInput:SendKey request to a TV - - @param contentApp Content app endpoint to target - - @param keyCode Key Code to process. If a second SendKey request with the same KeyCode value is received within 200ms, then the - endpoint will consider the first key press to be a press and hold. When such a repeat KeyCode value is not received within 200ms, - then the endpoint will consider the last key press to be a release. - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)keypadInput_sendKey:(ContentApp * _Nonnull)contentApp - keyCode:(uint8_t)keyCode - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Subscribe to ApplicationBasic:VendorName - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)applicationBasic_subscribeVendorName:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to ApplicationBasic:VendorID - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)applicationBasic_subscribeVendorID:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSNumber * _Nonnull))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to ApplicationBasic:ApplicationName - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)applicationBasic_subscribeApplicationName:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to ApplicationBasic:ProductID - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)applicationBasic_subscribeProductID:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(uint16_t))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Subscribe to ApplicationBasic:ApplicationVersion - - @param contentApp Content app endpoint to target - - @param minInterval Minimum interval between attribute read reports - - @param maxInterval Maximum interval between attribute read reports - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - - @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully - */ -- (void)applicationBasic_subscribeApplicationVersion:(ContentApp * _Nonnull)contentApp - minInterval:(uint16_t)minInterval - maxInterval:(uint16_t)maxInterval - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback - subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; - -/*! - @brief Read ApplicationBasic:VendorName - - @param contentApp Content app endpoint to target - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - */ -- (void)applicationBasic_readVendorName:(ContentApp * _Nonnull)contentApp - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; - -/*! - @brief Read ApplicationBasic:VendorID - - @param contentApp Content app endpoint to target - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - */ -- (void)applicationBasic_readVendorID:(ContentApp * _Nonnull)contentApp - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSNumber * _Nonnull))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; - -/*! - @brief Read ApplicationBasic:ApplicationName - - @param contentApp Content app endpoint to target - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - */ -- (void)applicationBasic_readApplicationName:(ContentApp * _Nonnull)contentApp - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; - -/*! - @brief Read ApplicationBasic:ProductID - - @param contentApp Content app endpoint to target - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - */ -- (void)applicationBasic_readProductID:(ContentApp * _Nonnull)contentApp - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(uint16_t))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; - -/*! - @brief Read ApplicationBasic:ApplicationVersion - - @param contentApp Content app endpoint to target - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - - @param successCallback Callback for when a read report is successfully received - - @param failureCallback Callback for when there is a failure in receiving a read report - */ -- (void)applicationBasic_readApplicationVersion:(ContentApp * _Nonnull)contentApp - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler - successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback - failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; -/*! - @brief Send a OnOff:On request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)onOff_on:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a OnOff:Off request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)onOff_off:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; - -/*! - @brief Send a OnOff:Toggle request to a TV - - @param contentApp Content app endpoint to target - - @param responseCallback Callback for when the response has been received - - @param clientQueue Queue to invoke callbacks on - - @param requestSentHandler Handler to call on sending the request - */ -- (void)onOff_toggle:(ContentApp * _Nonnull)contentApp - responseCallback:(void (^_Nonnull)(bool))responseCallback - clientQueue:(dispatch_queue_t _Nonnull)clientQueue - requestSentHandler:(void (^_Nonnull)(bool))requestSentHandler; -@end -#endif /* CastingServerBridge_h */ diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionableDataProviderImpl.hpp b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionableDataProviderImpl.hpp deleted file mode 100644 index 979c7c72f5e057..00000000000000 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionableDataProviderImpl.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include -#include - -class CommissionableDataProviderImpl : public chip::DeviceLayer::CommissionableDataProvider -{ -public: - CHIP_ERROR Initialize(chip::ByteSpan * spake2pVerifierBase64, chip::ByteSpan * spake2pSaltBase64, - uint32_t spake2pIterationCount, uint32_t setupPasscode, uint16_t discriminator); - CHIP_ERROR GetSetupDiscriminator(uint16_t & setupDiscriminator) override; - CHIP_ERROR SetSetupDiscriminator(uint16_t setupDiscriminator) override - { - // We don't support overriding the discriminator post-init (it is deprecated!) - return CHIP_ERROR_NOT_IMPLEMENTED; - } - CHIP_ERROR GetSpake2pIterationCount(uint32_t & iterationCount) override; - CHIP_ERROR GetSpake2pSalt(chip::MutableByteSpan & saltBuf) override; - CHIP_ERROR GetSpake2pVerifier(chip::MutableByteSpan & verifierBuf, size_t & outVerifierLen) override; - CHIP_ERROR GetSetupPasscode(uint32_t & setupPasscode) override; - CHIP_ERROR SetSetupPasscode(uint32_t setupPasscode) override - { - // We don't support overriding the passcode post-init (it is deprecated!) - return CHIP_ERROR_NOT_IMPLEMENTED; - } - -private: - friend CommissionableDataProviderImpl & CommissionableDataProviderMgrImpl(); - static CommissionableDataProviderImpl sInstance; - bool mFirstUpdated = false; - std::vector mSerializedPaseVerifier; - std::vector mPaseSalt; - uint32_t mPaseIterationCount = 0; - chip::Optional mSetupPasscode; - uint16_t mDiscriminator = 0; -}; - -inline CommissionableDataProviderImpl & CommissionableDataProviderMgrImpl() -{ - return CommissionableDataProviderImpl::sInstance; -} diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionableDataProviderImpl.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionableDataProviderImpl.mm deleted file mode 100644 index 40c2efcd99cb65..00000000000000 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissionableDataProviderImpl.mm +++ /dev/null @@ -1,209 +0,0 @@ -/* - * - * Copyright (c) 2022 Project CHIP Authors - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CommissionableDataProviderImpl.hpp" - -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace chip; -using namespace chip::Crypto; - -namespace { - -#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT -#define CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT 1000 -#endif - -CHIP_ERROR GeneratePaseSalt(std::vector & spake2pSaltVector) -{ - constexpr size_t kSaltLen = kSpake2p_Max_PBKDF_Salt_Length; - spake2pSaltVector.resize(kSaltLen); - return DRBG_get_bytes(spake2pSaltVector.data(), spake2pSaltVector.size()); -} - -} // namespace - -CommissionableDataProviderImpl CommissionableDataProviderImpl::sInstance; - -CHIP_ERROR CommissionableDataProviderImpl::Initialize(chip::ByteSpan * spake2pVerifierBase64, chip::ByteSpan * spake2pSaltBase64, - uint32_t spake2pIterationCount, uint32_t setupPasscode, uint16_t discriminator) -{ - VerifyOrReturnLogError(discriminator <= chip::kMaxDiscriminatorValue, CHIP_ERROR_INVALID_ARGUMENT); - - if (spake2pIterationCount == 0) { - spake2pIterationCount = CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT; - } - VerifyOrReturnLogError( - static_cast(spake2pIterationCount) >= kSpake2p_Min_PBKDF_Iterations, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnLogError( - static_cast(spake2pIterationCount) <= kSpake2p_Max_PBKDF_Iterations, CHIP_ERROR_INVALID_ARGUMENT); - - const bool havePaseVerifier = (spake2pVerifierBase64 != nullptr); - const bool havePaseSalt = (spake2pSaltBase64 != nullptr); - VerifyOrReturnLogError(!havePaseVerifier || (havePaseVerifier && havePaseSalt), CHIP_ERROR_INVALID_ARGUMENT); - - CHIP_ERROR err; - // read verifier from paramter if provided - Spake2pVerifier providedVerifier; - std::vector serializedSpake2pVerifier(kSpake2p_VerifierSerialized_Length); - if (havePaseVerifier) { - size_t maxBase64Size = BASE64_ENCODED_LEN(chip::Crypto::kSpake2p_VerifierSerialized_Length); - VerifyOrReturnLogError(static_cast(spake2pVerifierBase64->size()) <= maxBase64Size, CHIP_ERROR_INVALID_ARGUMENT); - - size_t decodedLen = chip::Base64Decode32(reinterpret_cast(spake2pVerifierBase64->data()), - static_cast(spake2pVerifierBase64->size()), reinterpret_cast(serializedSpake2pVerifier.data())); - VerifyOrReturnLogError(decodedLen == chip::Crypto::kSpake2p_VerifierSerialized_Length, CHIP_ERROR_INVALID_ARGUMENT); - - chip::MutableByteSpan verifierSpan { serializedSpake2pVerifier.data(), decodedLen }; - err = providedVerifier.Deserialize(verifierSpan); - VerifyOrReturnLogError(err == CHIP_NO_ERROR, err); - - ChipLogProgress(Support, "Got externally provided verifier, using it."); - } - - // read salt from paramter if provided or generate one - std::vector spake2pSalt(chip::Crypto::kSpake2p_Max_PBKDF_Salt_Length); - if (!havePaseSalt) { - ChipLogProgress(Support, "CommissionableDataProviderImpl didn't get a PASE salt, generating one."); - err = GeneratePaseSalt(spake2pSalt); - VerifyOrReturnLogError(err == CHIP_NO_ERROR, err); - } else { - size_t maxBase64Size = BASE64_ENCODED_LEN(chip::Crypto::kSpake2p_Max_PBKDF_Salt_Length); - VerifyOrReturnLogError(static_cast(spake2pSaltBase64->size()) <= maxBase64Size, CHIP_ERROR_INVALID_ARGUMENT); - - size_t decodedLen = chip::Base64Decode32(reinterpret_cast(spake2pSaltBase64->data()), - static_cast(spake2pSaltBase64->size()), reinterpret_cast(spake2pSalt.data())); - VerifyOrReturnLogError(decodedLen >= chip::Crypto::kSpake2p_Min_PBKDF_Salt_Length - && decodedLen <= chip::Crypto::kSpake2p_Max_PBKDF_Salt_Length, - CHIP_ERROR_INVALID_ARGUMENT); - spake2pSalt.resize(decodedLen); - } - - // generate verifier from passcode if provided - const bool havePasscode = (setupPasscode > kMinSetupPasscode && setupPasscode < kMaxSetupPasscode); - Spake2pVerifier passcodeVerifier; - std::vector serializedPasscodeVerifier(kSpake2p_VerifierSerialized_Length); - chip::MutableByteSpan saltSpan { spake2pSalt.data(), spake2pSalt.size() }; - if (havePasscode) { - uint32_t u32SetupPasscode = static_cast(setupPasscode); - err = passcodeVerifier.Generate(spake2pIterationCount, saltSpan, u32SetupPasscode); - VerifyOrReturnLogError(err == CHIP_NO_ERROR, err); - - chip::MutableByteSpan verifierSpan { serializedPasscodeVerifier.data(), serializedPasscodeVerifier.size() }; - err = passcodeVerifier.Serialize(verifierSpan); - VerifyOrReturnLogError(err == CHIP_NO_ERROR, err); - } - - // Make sure we actually have a verifier - VerifyOrReturnLogError(havePasscode || havePaseVerifier, CHIP_ERROR_INVALID_ARGUMENT); - - // If both passcode and external verifier were provided, validate they match, otherwise - // it's ambiguous. - if (havePasscode && havePaseVerifier) { - VerifyOrReturnLogError(serializedPasscodeVerifier == serializedSpake2pVerifier, CHIP_ERROR_INVALID_ARGUMENT); - ChipLogProgress(Support, "Validated externally provided passcode matches the one generated from provided passcode."); - } - - // External PASE verifier takes precedence when present (even though it is identical to passcode-based - // one when the latter is present). - if (havePaseVerifier) { - mSerializedPaseVerifier = std::move(serializedSpake2pVerifier); - } else { - mSerializedPaseVerifier = std::move(serializedPasscodeVerifier); - } - mDiscriminator = discriminator; - mPaseSalt = std::move(spake2pSalt); - mPaseIterationCount = spake2pIterationCount; - if (havePasscode) { - mSetupPasscode.SetValue(setupPasscode); - } - - // Set to global CommissionableDataProvider once success first time - if (!mFirstUpdated) { - DeviceLayer::SetCommissionableDataProvider(this); - } - mFirstUpdated = true; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR CommissionableDataProviderImpl::GetSetupDiscriminator(uint16_t & setupDiscriminator) -{ - VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); - setupDiscriminator = mDiscriminator; - return CHIP_NO_ERROR; -} - -CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pIterationCount(uint32_t & iterationCount) -{ - ChipLogProgress(AppServer, "CommissionableDataProviderImpl::GetSpake2pIterationCount called"); - VerifyOrReturnLogError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); - iterationCount = mPaseIterationCount; - return CHIP_NO_ERROR; -} - -CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pSalt(chip::MutableByteSpan & saltBuf) -{ - ChipLogProgress(AppServer, "CommissionableDataProviderImpl::GetSpake2pSalt called"); - VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); - - VerifyOrReturnError(saltBuf.size() >= kSpake2p_Max_PBKDF_Salt_Length, CHIP_ERROR_BUFFER_TOO_SMALL); - memcpy(saltBuf.data(), mPaseSalt.data(), mPaseSalt.size()); - saltBuf.reduce_size(mPaseSalt.size()); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR CommissionableDataProviderImpl::GetSpake2pVerifier(chip::MutableByteSpan & verifierBuf, size_t & outVerifierLen) -{ - ChipLogProgress(AppServer, "CommissionableDataProviderImpl::GetSpake2pVerifier called"); - VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); - - // By now, serialized verifier from Init should be correct size - VerifyOrReturnError(mSerializedPaseVerifier.size() == kSpake2p_VerifierSerialized_Length, CHIP_ERROR_INTERNAL); - - outVerifierLen = mSerializedPaseVerifier.size(); - VerifyOrReturnError(verifierBuf.size() >= outVerifierLen, CHIP_ERROR_BUFFER_TOO_SMALL); - memcpy(verifierBuf.data(), mSerializedPaseVerifier.data(), mSerializedPaseVerifier.size()); - verifierBuf.reduce_size(mSerializedPaseVerifier.size()); - - return CHIP_NO_ERROR; -} - -CHIP_ERROR CommissionableDataProviderImpl::GetSetupPasscode(uint32_t & setupPasscode) -{ - ChipLogProgress(AppServer, "CommissionableDataProviderImpl::GetSetupPasscode called"); - VerifyOrReturnError(mFirstUpdated, CHIP_ERROR_INCORRECT_STATE); - - // Pretend not implemented if we don't have a passcode value externally set - if (!mSetupPasscode.HasValue()) { - return CHIP_ERROR_NOT_IMPLEMENTED; - } - - setupPasscode = mSetupPasscode.Value(); - ChipLogProgress(AppServer, "CommissionableDataProviderImpl::GetSetupPasscode returning value %d", setupPasscode); - return CHIP_NO_ERROR; -} diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsProviderImpl.hpp b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsProviderImpl.hpp deleted file mode 100644 index 21d63ba88d2d05..00000000000000 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsProviderImpl.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/** - * - * Copyright (c) 2020-2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -#include - -class DeviceAttestationCredentialsProviderImpl : public chip::Credentials::DeviceAttestationCredentialsProvider -{ -public: - DeviceAttestationCredentialsProviderImpl(chip::MutableByteSpan * certificationDeclaration, - chip::MutableByteSpan * firmwareInformation, - chip::MutableByteSpan * deviceAttestationCert, - chip::MutableByteSpan * productAttestationIntermediateCert, - SecKeyRef deviceAttestationCertPrivateKeyRef); - - CHIP_ERROR GetCertificationDeclaration(chip::MutableByteSpan & outCertificationDeclaration) override; - CHIP_ERROR GetFirmwareInformation(chip::MutableByteSpan & outFirmwareInformation) override; - CHIP_ERROR GetDeviceAttestationCert(chip::MutableByteSpan & outDeviceAttestationCert) override; - CHIP_ERROR GetProductAttestationIntermediateCert(chip::MutableByteSpan & outProductAttestationIntermediateCert) override; - CHIP_ERROR SignWithDeviceAttestationKey(const chip::ByteSpan & messageToSign, - chip::MutableByteSpan & outSignatureBuffer) override; - -private: - chip::MutableByteSpan mCertificationDeclaration; - chip::MutableByteSpan mFirmwareInformation; - chip::MutableByteSpan mDeviceAttestationCert; - chip::MutableByteSpan mProductAttestationIntermediateCert; - SecKeyRef mDeviceAttestationCertPrivateKeyRef; -}; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsProviderImpl.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsProviderImpl.mm deleted file mode 100644 index 7008ffba969e72..00000000000000 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsProviderImpl.mm +++ /dev/null @@ -1,164 +0,0 @@ -/** - * - * Copyright (c) 2020-2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "DeviceAttestationCredentialsProviderImpl.hpp" - -#import -#import - -DeviceAttestationCredentialsProviderImpl::DeviceAttestationCredentialsProviderImpl(chip::MutableByteSpan * certificationDeclaration, - chip::MutableByteSpan * firmwareInformation, chip::MutableByteSpan * deviceAttestationCert, - chip::MutableByteSpan * productAttestationIntermediateCert, SecKeyRef deviceAttestationCertPrivateKeyRef) -{ - if (certificationDeclaration != nullptr) { - mCertificationDeclaration - = chip::MutableByteSpan(new uint8_t[certificationDeclaration->size()], certificationDeclaration->size()); - memcpy(mCertificationDeclaration.data(), certificationDeclaration->data(), certificationDeclaration->size()); - } - - if (firmwareInformation != nullptr) { - mFirmwareInformation = chip::MutableByteSpan(new uint8_t[firmwareInformation->size()], firmwareInformation->size()); - memcpy(mFirmwareInformation.data(), firmwareInformation->data(), firmwareInformation->size()); - } - - if (deviceAttestationCert != nullptr) { - mDeviceAttestationCert = chip::MutableByteSpan(new uint8_t[deviceAttestationCert->size()], deviceAttestationCert->size()); - memcpy(mDeviceAttestationCert.data(), deviceAttestationCert->data(), deviceAttestationCert->size()); - } - - if (productAttestationIntermediateCert != nullptr) { - mProductAttestationIntermediateCert = chip::MutableByteSpan( - new uint8_t[productAttestationIntermediateCert->size()], productAttestationIntermediateCert->size()); - memcpy(mProductAttestationIntermediateCert.data(), productAttestationIntermediateCert->data(), - productAttestationIntermediateCert->size()); - } - - mDeviceAttestationCertPrivateKeyRef = deviceAttestationCertPrivateKeyRef; -} - -CHIP_ERROR DeviceAttestationCredentialsProviderImpl::GetCertificationDeclaration( - chip::MutableByteSpan & outCertificationDeclaration) -{ - if (mCertificationDeclaration.size() > 0) { - if (outCertificationDeclaration.size() >= mCertificationDeclaration.size()) { - memcpy(outCertificationDeclaration.data(), mCertificationDeclaration.data(), mCertificationDeclaration.size()); - outCertificationDeclaration.reduce_size(mCertificationDeclaration.size()); - } else { - return CHIP_ERROR_BUFFER_TOO_SMALL; - } - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR DeviceAttestationCredentialsProviderImpl::GetFirmwareInformation(chip::MutableByteSpan & outFirmwareInformation) -{ - if (mFirmwareInformation.size() > 0) { - if (outFirmwareInformation.size() >= mFirmwareInformation.size()) { - memcpy(outFirmwareInformation.data(), mFirmwareInformation.data(), mFirmwareInformation.size()); - outFirmwareInformation.reduce_size(mFirmwareInformation.size()); - } else { - return CHIP_ERROR_BUFFER_TOO_SMALL; - } - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR DeviceAttestationCredentialsProviderImpl::GetDeviceAttestationCert(chip::MutableByteSpan & outDeviceAttestationCert) -{ - if (mDeviceAttestationCert.size() > 0) { - if (outDeviceAttestationCert.size() >= mDeviceAttestationCert.size()) { - memcpy(outDeviceAttestationCert.data(), mDeviceAttestationCert.data(), mDeviceAttestationCert.size()); - outDeviceAttestationCert.reduce_size(mDeviceAttestationCert.size()); - } else { - return CHIP_ERROR_BUFFER_TOO_SMALL; - } - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR DeviceAttestationCredentialsProviderImpl::GetProductAttestationIntermediateCert( - chip::MutableByteSpan & outProductAttestationIntermediateCert) -{ - if (mProductAttestationIntermediateCert.size() > 0) { - if (outProductAttestationIntermediateCert.size() >= mProductAttestationIntermediateCert.size()) { - memcpy(outProductAttestationIntermediateCert.data(), mProductAttestationIntermediateCert.data(), - mProductAttestationIntermediateCert.size()); - outProductAttestationIntermediateCert.reduce_size(mProductAttestationIntermediateCert.size()); - } else { - return CHIP_ERROR_BUFFER_TOO_SMALL; - } - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR DeviceAttestationCredentialsProviderImpl::SignWithDeviceAttestationKey( - const chip::ByteSpan & messageToSign, chip::MutableByteSpan & outSignatureBuffer) -{ - ChipLogProgress(AppServer, "DeviceAttestationCredentialsProviderImpl::SignWithDeviceAttestationKey called"); - - CHIP_ERROR result = CHIP_NO_ERROR; - CFDataRef dataToSign = nil; - CFDataRef asn1SignatureData = nil; - uint8_t mAsn1SignatureBytes[256]; - chip::MutableByteSpan asn1SignatureByteSpan = chip::MutableByteSpan(mAsn1SignatureBytes, sizeof(mAsn1SignatureBytes)); - CFErrorRef error = nil; - size_t signatureLen = 0; - - do { - dataToSign = CFDataCreate(CFAllocatorGetDefault(), messageToSign.data(), messageToSign.size()); - if (nil == dataToSign) { - ChipLogError( - AppServer, "DeviceAttestationCredentialsProviderImpl::SignWithDeviceAttestationKey failed to create buffer"); - result = CHIP_ERROR_NO_MEMORY; - break; - } - - asn1SignatureData = SecKeyCreateSignature( - mDeviceAttestationCertPrivateKeyRef, kSecKeyAlgorithmECDSASignatureMessageX962SHA256, dataToSign, &error); - if (nil != error || nil == asn1SignatureData) { - ChipLogError(AppServer, - "DeviceAttestationCredentialsProviderImpl::SignWithDeviceAttestationKey failed to sign the message. error = %lu", - CFErrorGetCode(error)); - result = CHIP_ERROR_INVALID_ARGUMENT; - break; - } - - signatureLen = CFDataGetLength(asn1SignatureData); - - CFDataGetBytes(asn1SignatureData, CFRangeMake(0, signatureLen), asn1SignatureByteSpan.data()); - asn1SignatureByteSpan.reduce_size(signatureLen); - - CHIP_ERROR conversionError = chip::Crypto::EcdsaAsn1SignatureToRaw( - 32, chip::ByteSpan(asn1SignatureByteSpan.data(), asn1SignatureByteSpan.size()), outSignatureBuffer); - if (CHIP_NO_ERROR != conversionError) { - ChipLogError(AppServer, - "DeviceAttestationCredentialsProviderImpl::SignWithDeviceAttestationKey failed to convert to raw signature."); - result = conversionError; - break; - } - } while (0); - - if (dataToSign != nil) { - CFRelease(dataToSign); - } - - if (asn1SignatureData != nil) { - CFRelease(asn1SignatureData); - } - - return result; -} diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCAttribute.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCAttribute.h index ba9f40c24c519c..c5b791a05080d9 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCAttribute.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCAttribute.h @@ -15,8 +15,6 @@ * limitations under the License. */ -#import "MCObserver.h" - #import #ifndef MCAttribute_h diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.h index d01ce207519c4c..e796f25da609a0 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.h @@ -72,6 +72,8 @@ - (uint32_t)deviceType; - (bool)supportsCommissionerGeneratedPasscode; - (NSArray * _Nonnull)ipAddresses; +- (NSString * _Nonnull)hostName; +- (NSString * _Nonnull)instanceName; /** * @brief Returns the NSArray of MCEndpoints associated with this MCCastingPlayer diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm index 3bc72235a86c72..1e94b77090e4c7 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm @@ -97,6 +97,20 @@ - (instancetype _Nonnull)initWithCppCastingPlayer:(matter::casting::memory::Stro return self; } ++ (MCCastingPlayer * _Nullable)getTargetCastingPlayer +{ + ChipLogProgress(AppServer, "MCCastingPlayer.getTargetCastingPlayer called"); + VerifyOrReturnValue([[MCCastingApp getSharedInstance] isRunning], nil, ChipLogError(AppServer, "MCCastingApp NOT running")); + __block MCCastingPlayer * castingPlayer = nil; + dispatch_sync([[MCCastingApp getSharedInstance] getWorkQueue], ^{ + matter::casting::core::CastingPlayer * cppCastingPlayer = matter::casting::core::CastingPlayer::GetTargetCastingPlayer(); + if (cppCastingPlayer != nullptr) { + castingPlayer = [[MCCastingPlayer alloc] initWithCppCastingPlayer:std::make_shared(*cppCastingPlayer)]; + } + }); + return castingPlayer; +} + - (NSString * _Nonnull)description { return [NSString stringWithFormat:@"%@ with Product ID: %hu and Vendor ID: %hu. Resolved IPAddr?: %@. Supports Commissioner Generated Passcode?: %@.", @@ -133,6 +147,16 @@ - (bool)supportsCommissionerGeneratedPasscode return _cppCastingPlayer->GetSupportsCommissionerGeneratedPasscode(); } +- (NSString * _Nonnull)hostName +{ + return [NSString stringWithCString:_cppCastingPlayer->GetHostName() encoding:NSUTF8StringEncoding]; +} + +- (NSString * _Nonnull)instanceName +{ + return [NSString stringWithCString:_cppCastingPlayer->GetInstanceName() encoding:NSUTF8StringEncoding]; +} + - (NSArray * _Nonnull)ipAddresses { NSMutableArray * ipAddresses = [NSMutableArray new]; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayerDiscovery.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayerDiscovery.mm index b69817266c6edc..51379b77b56776 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayerDiscovery.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayerDiscovery.mm @@ -19,7 +19,7 @@ #import "MCCastingApp.h" -#import "MCCastingPlayer.mm" +#import "MCCastingPlayer_Internal.h" #import "MCErrorUtils.h" #include "core/CastingPlayer.h" diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer_Internal.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer_Internal.h index 6c52733c3d6909..87f3da455abcd4 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer_Internal.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer_Internal.h @@ -26,6 +26,8 @@ @interface MCCastingPlayer () ++ (MCCastingPlayer * _Nullable)getTargetCastingPlayer; + - (instancetype _Nonnull)initWithCppCastingPlayer:(matter::casting::memory::Strong)cppCastingPlayer; @end diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDeviceAttestationCredentialsProvider.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDeviceAttestationCredentialsProvider.h index 00cbf0628ab9f8..8f2d3efc8aef47 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDeviceAttestationCredentialsProvider.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDeviceAttestationCredentialsProvider.h @@ -44,8 +44,7 @@ class MCDeviceAttestationCredentialsProvider : public chip::Credentials::DeviceA chip::MutableByteSpan & outSignatureBuffer) override; private: - id mDataSource = nullptr; - MCDeviceAttestationCredentials * mDac = nullptr; + id mDataSource = nullptr; }; }; // namespace support diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDeviceAttestationCredentialsProvider.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDeviceAttestationCredentialsProvider.mm index 16a49c76363792..3f1f155d782fa9 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDeviceAttestationCredentialsProvider.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDeviceAttestationCredentialsProvider.mm @@ -33,24 +33,22 @@ { VerifyOrReturnError(dataSource != nullptr, CHIP_ERROR_INVALID_ARGUMENT); VerifyOrReturnError(mDataSource == nullptr, CHIP_ERROR_INCORRECT_STATE); - mDataSource = dataSource; - mDac = [mDataSource - castingAppDidReceiveRequestForDeviceAttestationCredentials:@"MCDeviceAttestationCredentialsProvider.Initialize()"]; - return CHIP_NO_ERROR; } CHIP_ERROR MCDeviceAttestationCredentialsProvider::GetCertificationDeclaration( chip::MutableByteSpan & outCertificationDeclaration) { - VerifyOrReturnError(mDac != nullptr, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mDataSource != nullptr, CHIP_ERROR_INCORRECT_STATE); + MCDeviceAttestationCredentials * dac = [mDataSource + castingAppDidReceiveRequestForDeviceAttestationCredentials:@"MCDeviceAttestationCredentialsProvider.Initialize()"]; - if (mDac.certificationDeclaration != nullptr && mDac.certificationDeclaration.length > 0) { - if (outCertificationDeclaration.size() >= mDac.certificationDeclaration.length) { - memcpy(outCertificationDeclaration.data(), mDac.certificationDeclaration.bytes, - mDac.certificationDeclaration.length); - outCertificationDeclaration.reduce_size(mDac.certificationDeclaration.length); + if (dac.certificationDeclaration != nullptr && dac.certificationDeclaration.length > 0) { + if (outCertificationDeclaration.size() >= dac.certificationDeclaration.length) { + memcpy(outCertificationDeclaration.data(), dac.certificationDeclaration.bytes, + dac.certificationDeclaration.length); + outCertificationDeclaration.reduce_size(dac.certificationDeclaration.length); } else { return CHIP_ERROR_BUFFER_TOO_SMALL; } @@ -60,12 +58,14 @@ CHIP_ERROR MCDeviceAttestationCredentialsProvider::GetFirmwareInformation(chip::MutableByteSpan & outFirmwareInformation) { - VerifyOrReturnError(mDac != nullptr, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mDataSource != nullptr, CHIP_ERROR_INCORRECT_STATE); + MCDeviceAttestationCredentials * dac = [mDataSource + castingAppDidReceiveRequestForDeviceAttestationCredentials:@"MCDeviceAttestationCredentialsProvider.Initialize()"]; - if (mDac.firmwareInformation != nullptr && mDac.firmwareInformation.length > 0) { - if (outFirmwareInformation.size() >= mDac.firmwareInformation.length) { - memcpy(outFirmwareInformation.data(), mDac.firmwareInformation.bytes, mDac.firmwareInformation.length); - outFirmwareInformation.reduce_size(mDac.firmwareInformation.length); + if (dac.firmwareInformation != nullptr && dac.firmwareInformation.length > 0) { + if (outFirmwareInformation.size() >= dac.firmwareInformation.length) { + memcpy(outFirmwareInformation.data(), dac.firmwareInformation.bytes, dac.firmwareInformation.length); + outFirmwareInformation.reduce_size(dac.firmwareInformation.length); } else { return CHIP_ERROR_BUFFER_TOO_SMALL; } @@ -76,12 +76,14 @@ CHIP_ERROR MCDeviceAttestationCredentialsProvider::GetDeviceAttestationCert( chip::MutableByteSpan & outDeviceAttestationCert) { - VerifyOrReturnError(mDac != nullptr, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mDataSource != nullptr, CHIP_ERROR_INCORRECT_STATE); + MCDeviceAttestationCredentials * dac = [mDataSource + castingAppDidReceiveRequestForDeviceAttestationCredentials:@"MCDeviceAttestationCredentialsProvider.Initialize()"]; - if (mDac.deviceAttestationCert != nullptr && mDac.deviceAttestationCert.length > 0) { - if (outDeviceAttestationCert.size() >= mDac.deviceAttestationCert.length) { - memcpy(outDeviceAttestationCert.data(), mDac.deviceAttestationCert.bytes, mDac.deviceAttestationCert.length); - outDeviceAttestationCert.reduce_size(mDac.deviceAttestationCert.length); + if (dac.deviceAttestationCert != nullptr && dac.deviceAttestationCert.length > 0) { + if (outDeviceAttestationCert.size() >= dac.deviceAttestationCert.length) { + memcpy(outDeviceAttestationCert.data(), dac.deviceAttestationCert.bytes, dac.deviceAttestationCert.length); + outDeviceAttestationCert.reduce_size(dac.deviceAttestationCert.length); } else { return CHIP_ERROR_BUFFER_TOO_SMALL; } @@ -92,13 +94,15 @@ CHIP_ERROR MCDeviceAttestationCredentialsProvider::GetProductAttestationIntermediateCert( chip::MutableByteSpan & outProductAttestationIntermediateCert) { - VerifyOrReturnError(mDac != nullptr, CHIP_ERROR_INCORRECT_STATE); + VerifyOrReturnError(mDataSource != nullptr, CHIP_ERROR_INCORRECT_STATE); + MCDeviceAttestationCredentials * dac = [mDataSource + castingAppDidReceiveRequestForDeviceAttestationCredentials:@"MCDeviceAttestationCredentialsProvider.Initialize()"]; - if (mDac.productAttestationIntermediateCert != nullptr && mDac.productAttestationIntermediateCert.length > 0) { - if (outProductAttestationIntermediateCert.size() >= mDac.productAttestationIntermediateCert.length) { - memcpy(outProductAttestationIntermediateCert.data(), mDac.productAttestationIntermediateCert.bytes, - mDac.productAttestationIntermediateCert.length); - outProductAttestationIntermediateCert.reduce_size(mDac.productAttestationIntermediateCert.length); + if (dac.productAttestationIntermediateCert != nullptr && dac.productAttestationIntermediateCert.length > 0) { + if (outProductAttestationIntermediateCert.size() >= dac.productAttestationIntermediateCert.length) { + memcpy(outProductAttestationIntermediateCert.data(), dac.productAttestationIntermediateCert.bytes, + dac.productAttestationIntermediateCert.length); + outProductAttestationIntermediateCert.reduce_size(dac.productAttestationIntermediateCert.length); } else { return CHIP_ERROR_BUFFER_TOO_SMALL; } diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.h index d252bd3c92f3e1..db340f097764f4 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.h @@ -17,7 +17,7 @@ #import "MCCastingPlayer.h" #import "MCCluster.h" -#import "MCEndpointClusterType.h" +#import "zap-generated/MCEndpointClusterType.h" #import diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.mm index f5e5aac89abb69..76d1eaf70724f9 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.mm @@ -44,6 +44,18 @@ - (instancetype _Nonnull)initWithCppEndpoint:(matter::casting::memory::Strong cppServerList = _cppEndpoint->GetServerList(); + for (chip::ClusterId clusterId : cppServerList) { + [serverList addObject:@(clusterId)]; + } + } + return serverList; +} + - (NSNumber * _Nonnull)identifier { return [NSNumber numberWithUnsignedShort:_cppEndpoint->GetId()]; @@ -78,15 +90,27 @@ - (MCCastingPlayer * _Nonnull)castingPlayer - (MCCluster * _Nullable)clusterForType:(MCEndpointClusterType)type { switch (type) { + case MCEndpointClusterTypeApplicationBasic: + return [[MCApplicationBasicCluster alloc] initWithCppCluster:_cppEndpoint->GetCluster()]; + + case MCEndpointClusterTypeApplicationLauncher: + return [[MCApplicationLauncherCluster alloc] initWithCppCluster:_cppEndpoint->GetCluster()]; + case MCEndpointClusterTypeContentLauncher: return [[MCContentLauncherCluster alloc] initWithCppCluster:_cppEndpoint->GetCluster()]; - case MCEndpointClusterTypeApplicationBasic: - return [[MCApplicationBasicCluster alloc] initWithCppCluster:_cppEndpoint->GetCluster()]; + case MCEndpointClusterTypeKeypadInput: + return [[MCKeypadInputCluster alloc] initWithCppCluster:_cppEndpoint->GetCluster()]; case MCEndpointClusterTypeMediaPlayback: return [[MCMediaPlaybackCluster alloc] initWithCppCluster:_cppEndpoint->GetCluster()]; + case MCEndpointClusterTypeOnOff: + return [[MCOnOffCluster alloc] initWithCppCluster:_cppEndpoint->GetCluster()]; + + case MCEndpointClusterTypeTargetNavigator: + return [[MCTargetNavigatorCluster alloc] initWithCppCluster:_cppEndpoint->GetCluster()]; + default: ChipLogError(AppServer, "MCEndpointClusterType not found"); break; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint_Internal.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint_Internal.h index 53b1d6bf22218e..ac40932c8a170c 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint_Internal.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint_Internal.h @@ -28,6 +28,8 @@ - (instancetype _Nonnull)initWithCppEndpoint:(matter::casting::memory::Strong)cppEndpoint; +- (NSMutableArray *)getServerList; + @end #endif /* MCEndpoint_Internal_h */ diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCErrorUtils.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCErrorUtils.h index 56606e96b7a7d9..4887fac865ddba 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCErrorUtils.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCErrorUtils.h @@ -34,6 +34,8 @@ + (NSError * _Nonnull)NSErrorFromMatterError:(MatterError * _Nonnull)matterError; ++ (MatterError * _Nonnull)MatterErrorFromNsError:(NSError * _Nonnull)nsError; + @end #endif /* MCErrorUtils_h */ diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCErrorUtils.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCErrorUtils.mm index 66fc7544aad226..e4616853fc76a2 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCErrorUtils.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCErrorUtils.mm @@ -38,4 +38,8 @@ + (NSError * _Nonnull)NSErrorFromMatterError:(MatterError * _Nonnull)matterError return matterError == MATTER_NO_ERROR ? nil : [NSError errorWithDomain:@"com.matter.casting" code:matterError.code userInfo:@{ NSUnderlyingErrorKey : matterError.message }]; } ++ (MatterError * _Nonnull)MatterErrorFromNsError:(NSError * _Nonnull)nsError +{ + return nsError == nil ? MATTER_NO_ERROR : [[MatterError alloc] initWithCode:static_cast(nsError.code) message:nsError.userInfo[NSUnderlyingErrorKey]]; +} @end diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MatterError.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MatterError.mm index cbee1a455a51ca..6d4a84c043a24e 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MatterError.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MatterError.mm @@ -23,7 +23,7 @@ @implementation MatterError -MatterError * MATTER_NO_ERROR = [[MatterError alloc] initWithCode:0 message:nil]; +MatterError * MATTER_NO_ERROR = [[MatterError alloc] initWithCode:0 message:@"No error"]; MatterError * MATTER_ERROR_INCORRECT_STATE = [[MatterError alloc] initWithCode:CHIP_ERROR_INCORRECT_STATE.AsInteger() diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MatterTvCastingBridge.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MatterTvCastingBridge.h index 851b94606d628a..5e83cea90b0728 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MatterTvCastingBridge.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MatterTvCastingBridge.h @@ -23,7 +23,7 @@ FOUNDATION_EXPORT double MatterTvCastingBridgeVersionNumber; //! Project version string for MatterTvCastingBridge. FOUNDATION_EXPORT const unsigned char MatterTvCastingBridgeVersionString[]; -#import "CastingServerBridge.h" +#import "compat-shim/CastingServerBridge.h" // Add simplified casting API headers here #import "MCAttribute.h" @@ -36,9 +36,9 @@ FOUNDATION_EXPORT const unsigned char MatterTvCastingBridgeVersionString[]; #import "MCCryptoUtils.h" #import "MCDataSource.h" #import "MCDeviceAttestationCredentials.h" -#import "MCEndpointClusterType.h" +#import "MCEndpoint.h" #import "MCEndpointFilter.h" -#import "MCObserver.h" #import "zap-generated/MCAttributeObjects.h" #import "zap-generated/MCClusterObjects.h" #import "zap-generated/MCCommandObjects.h" +#import "zap-generated/MCEndpointClusterType.h" diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/AppParameters.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/AppParameters.h similarity index 91% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/AppParameters.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/AppParameters.h index 34585289fb6d5c..e49b17c5dcf1ef 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/AppParameters.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/AppParameters.h @@ -23,6 +23,7 @@ #ifndef AppParameters_h #define AppParameters_h +__attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) @interface AppParameters : NSObject @property NSData * rotatingDeviceIdUniqueId; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/AppParameters.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/AppParameters.mm similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/AppParameters.mm rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/AppParameters.mm diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingPlayerDiscoveryListenerCompat.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingPlayerDiscoveryListenerCompat.h new file mode 100644 index 00000000000000..dda77fa585f612 --- /dev/null +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingPlayerDiscoveryListenerCompat.h @@ -0,0 +1,34 @@ +/** + * + * Copyright (c) 2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "DiscoveredNodeData.h" + +#import + +#ifndef CastingPlayerDiscoveryListenerCompat_h +#define CastingPlayerDiscoveryListenerCompat_h + +__attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) +@interface CastingPlayerDiscoveryListenerCompat : NSObject + ++ (void)addObservers:(dispatch_queue_t _Nonnull)clientQueue discoveredCommissionerHandler:(nullable void (^)(DiscoveredNodeData * _Nonnull))discoveredCommissionerHandler; + ++ (void)removeObservers; + +@end + +#endif /* CastingPlayerDiscoveryListenerCompat_h */ diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingPlayerDiscoveryListenerCompat.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingPlayerDiscoveryListenerCompat.mm new file mode 100644 index 00000000000000..35216fd87cc248 --- /dev/null +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingPlayerDiscoveryListenerCompat.mm @@ -0,0 +1,134 @@ +/** + * + * Copyright (c) 2020-2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "CastingPlayerDiscoveryListenerCompat.h" + +#import "DiscoveredNodeData.h" +#import "MCCastingPlayer.h" +#import "MCCastingPlayerDiscovery.h" +#import "MCErrorUtils.h" + +#include + +@interface CastingPlayerDiscoveryListenerCompat () + +@property (class, nonatomic, strong) dispatch_queue_t clientQueue; +@property (class, nonatomic, copy, nullable) void (^discoveredCommissionerHandler)(DiscoveredNodeData * _Nullable); + ++ (void)didAddDiscoveredCastingPlayers:(NSNotification * _Nonnull)notification; ++ (void)didUpdateDiscoveredCastingPlayers:(NSNotification * _Nonnull)notification; + +@end + +@implementation CastingPlayerDiscoveryListenerCompat + +static dispatch_queue_t _clientQueue; +static void (^_discoveredCommissionerHandler)(DiscoveredNodeData * _Nullable); + ++ (dispatch_queue_t)clientQueue +{ + return _clientQueue; +} + ++ (void)setClientQueue:(dispatch_queue_t)clientQueue +{ + _clientQueue = clientQueue; +} + ++ (void (^)(DiscoveredNodeData * _Nullable))discoveredCommissionerHandler +{ + return _discoveredCommissionerHandler; +} + ++ (void)setDiscoveredCommissionerHandler:(void (^)(DiscoveredNodeData * _Nullable))discoveredCommissionerHandler +{ + _discoveredCommissionerHandler = discoveredCommissionerHandler; +} + ++ (void)addObservers:(dispatch_queue_t _Nonnull)clientQueue discoveredCommissionerHandler:(nullable void (^)(DiscoveredNodeData * _Nonnull __strong))discoveredCommissionerHandler +{ + ChipLogProgress(AppServer, "CastingPlayerDiscoveryListenerCompat.addObservers() called"); + [self setClientQueue:clientQueue]; + [self setDiscoveredCommissionerHandler:discoveredCommissionerHandler]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(didAddDiscoveredCastingPlayers:) + name:ADD_CASTING_PLAYER_NOTIFICATION_NAME + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(didUpdateDiscoveredCastingPlayers:) + name:UPDATE_CASTING_PLAYER_NOTIFICATION_NAME + object:nil]; +} + ++ (void)removeObservers +{ + ChipLogProgress(AppServer, "CastingPlayerDiscoveryListenerCompat.removeObservers() called"); + [[NSNotificationCenter defaultCenter] removeObserver:self + name:ADD_CASTING_PLAYER_NOTIFICATION_NAME + object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:UPDATE_CASTING_PLAYER_NOTIFICATION_NAME + object:nil]; +} + ++ (void)didAddDiscoveredCastingPlayers:(NSNotification *)notification +{ + ChipLogProgress(AppServer, "CastingPlayerDiscoveryListenerCompat.didAddDiscoveredCastingPlayers() called"); + VerifyOrReturn(CastingPlayerDiscoveryListenerCompat.clientQueue != nil); + VerifyOrReturn(CastingPlayerDiscoveryListenerCompat.discoveredCommissionerHandler != nil); + + NSDictionary * userInfo = notification.userInfo; + MCCastingPlayer * castingPlayer = userInfo[CASTING_PLAYER_KEY]; + + if (![castingPlayer isKindOfClass:[MCCastingPlayer class]]) { + ChipLogError(AppServer, "CastingPlayerDiscoveryListenerCompat.didAddDiscoveredCastingPlayers called with no MCCastingPlayer"); + return; + } + + ChipLogProgress(AppServer, "CastingPlayerDiscoveryListenerCompat.didAddDiscoveredCastingPlayers notified of a MCCastingPlayer with ID: %@", [castingPlayer identifier]); + + DiscoveredNodeData * discoveredNodeData = [[DiscoveredNodeData alloc] initWithCastingPlayer:castingPlayer]; + dispatch_async(CastingPlayerDiscoveryListenerCompat.clientQueue, ^{ + CastingPlayerDiscoveryListenerCompat.discoveredCommissionerHandler(discoveredNodeData); + }); +} + ++ (void)didUpdateDiscoveredCastingPlayers:(NSNotification *)notification +{ + ChipLogProgress(AppServer, "CastingPlayerDiscoveryListenerCompat.didUpdateDiscoveredCastingPlayers() called"); + VerifyOrReturn(CastingPlayerDiscoveryListenerCompat.clientQueue != nil); + VerifyOrReturn(CastingPlayerDiscoveryListenerCompat.discoveredCommissionerHandler != nil); + + NSDictionary * userInfo = notification.userInfo; + MCCastingPlayer * castingPlayer = userInfo[CASTING_PLAYER_KEY]; + + if (![castingPlayer isKindOfClass:[MCCastingPlayer class]]) { + ChipLogError(AppServer, "CastingPlayerDiscoveryListenerCompat.didUpdateDiscoveredCastingPlayers called with no MCCastingPlayer"); + return; + } + + ChipLogProgress(AppServer, "CastingPlayerDiscoveryListenerCompat.didUpdateDiscoveredCastingPlayers notified of a MCCastingPlayer with ID: %@", [castingPlayer identifier]); + + DiscoveredNodeData * discoveredNodeData = [[DiscoveredNodeData alloc] initWithCastingPlayer:castingPlayer]; + dispatch_async(CastingPlayerDiscoveryListenerCompat.clientQueue, ^{ + CastingPlayerDiscoveryListenerCompat.discoveredCommissionerHandler(discoveredNodeData); + }); +} + +@end diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.h new file mode 100644 index 00000000000000..01682cd89e3d98 --- /dev/null +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.h @@ -0,0 +1,739 @@ +/** + * + * Copyright (c) 2020-2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "../MatterError.h" +#import "AppParameters.h" +#import "CommissioningCallbackHandlers.h" +#import "ContentApp.h" +#import "ContentLauncherTypes.h" +#import "DiscoveredNodeData.h" +#import "MediaPlaybackTypes.h" +#import "OnboardingPayload.h" +#import "TargetNavigatorTypes.h" +#import "VideoPlayer.h" +#import + +#ifndef CastingServerBridge_h +#define CastingServerBridge_h + +__attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) +@interface CastingServerBridge : NSObject + ++ (CastingServerBridge * _Nullable)getSharedInstance; + +- (MatterError * _Nonnull)initializeApp:(AppParameters * _Nullable)appParameters + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + initAppStatusHandler:(nullable void (^)(MatterError * _Nonnull))initAppStatusHandler; + +- (void)setDacHolder:(DeviceAttestationCredentialsHolder * _Nonnull)deviceAttestationCredentials + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + setDacHolderStatus:(void (^_Nonnull)(MatterError * _Nonnull))setDacHolderStatus; + +/*! + @brief Browse for on-network commissioner TVs + + @param clientQueue Queue to dispatch the call to the discoveryRequestSentHandler on + + @param timeoutInSeconds time after which this discovery request should be auto-canceled + + @param discoveryRequestSentHandler Handler to call after the Commissioner discovery request has been sent + */ +- (void)discoverCommissioners:(dispatch_queue_t _Nonnull)clientQueue + timeoutInSeconds:(NSUInteger)timeoutInSeconds + discoveryRequestSentHandler:(nullable void (^)(MatterError * _Nonnull))discoveryRequestSentHandler + discoveredCommissionerHandler:(nullable void (^)(DiscoveredNodeData * _Nonnull))discoveredCommissionerHandler; + +- (void)discoverCommissioners:(dispatch_queue_t _Nonnull)clientQueue + discoveryRequestSentHandler:(nullable void (^)(MatterError * _Nonnull))discoveryRequestSentHandler + discoveredCommissionerHandler:(nullable void (^)(DiscoveredNodeData * _Nonnull))discoveredCommissionerHandler; + +/*! + @brief Send a User Directed Commissioning request to a commissioner TV + + @param commissioner Commissioner to request commissioning from + + @param clientQueue Queue to dispatch the call to the udcRequestSentHandler on + + @param udcRequestSentHandler Handler to call on sending the User Directed Commissioning request + */ +- (void)sendUserDirectedCommissioningRequest:(DiscoveredNodeData * _Nonnull)commissioner + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + udcRequestSentHandler:(nullable void (^)(MatterError * _Nonnull))udcRequestSentHandler; + +/*! + @brief Send a User Directed Commissioning request to a commissioner TV + + @param commissioner Commissioner to request commissioning from + + @param clientQueue Queue to dispatch the call to the udcRequestSentHandler on + + @param udcRequestSentHandler Handler to call on sending the User Directed Commissioning request + + @param desiredContentAppVendorId VendorId of the ContentApp that the client wants to interact with / cast to. If this value is passed in, the CastingServerBridge will force User Directed + * Commissioning, in case the desired ContentApp is not found in the on-device cached information + */ +- (void)sendUserDirectedCommissioningRequest:(DiscoveredNodeData * _Nonnull)commissioner + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + udcRequestSentHandler:(nullable void (^)(MatterError * _Nonnull))udcRequestSentHandler + desiredContentAppVendorId:(uint16_t)desiredContentAppVendorId; + +/*! + @brief Return the onboarding payload for this app (setup passcode, discriminator) + + @return Onboarding payload + */ +- (OnboardingPayload * _Nonnull)getOnboardingPayload; + +/*! + @brief Request opening of a basic commissioning window + + @param clientQueue Queue to dispatch the call to the commissioningWindowRequestedHandler on + + @param commissioningCallbackHandlers Optional parameter to specific handlers for callbacks during commissioning + + @param onConnectionSuccessCallback Handles a VideoPlayer * once connection is successfully established + + @param onConnectionFailureCallback Handles MatterError if there is a failure in establishing connection + + @param onNewOrUpdatedEndpointCallback Handles a ContentApp * for each new ContentApp is found. May be called multiple times based + on the number of ContentApp + */ +- (void)openBasicCommissioningWindow:(dispatch_queue_t _Nonnull)clientQueue + commissioningCallbackHandlers:(CommissioningCallbackHandlers * _Nullable)commissioningCallbackHandlers + onConnectionSuccessCallback:(void (^_Nonnull)(VideoPlayer * _Nonnull))onConnectionSuccessCallback + onConnectionFailureCallback:(void (^_Nonnull)(MatterError * _Nonnull))onConnectionFailureCallback + onNewOrUpdatedEndpointCallback:(void (^_Nonnull)(ContentApp * _Nonnull))onNewOrUpdatedEndpointCallback; + +/*! + @brief Gets the list of VideoPlayers currently connected + + @param clientQueue Queue to invoke callbacks on + + @param activeTargetVideoPlayersHandler Handles NSMutableArray of active/currently connected VideoPlayers. Nil, if no such + VideoPlayers are found. + */ +- (void)getActiveTargetVideoPlayers:(dispatch_queue_t _Nonnull)clientQueue + activeTargetVideoPlayersHandler:(nullable void (^)(NSMutableArray * _Nullable))activeTargetVideoPlayersHandler; + +/*! + @brief Verify if a connection exists or connect to the VideoPlayer passed in as parameter. + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handles MatterError and called after the request has been sent + + @param onConnectionSuccessCallback Handles a VideoPlayer * once connection is successfully established + + @param onConnectionFailureCallback Handles MatterError if there is a failure in establishing connection + + @param onNewOrUpdatedEndpointCallback Handles a ContentApp * for each new ContentApp is found. May be called multiple times based + on the number of ContentApp + */ +- (void)verifyOrEstablishConnection:(VideoPlayer * _Nonnull)videoPlayer + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(nullable void (^)(MatterError * _Nonnull))requestSentHandler + onConnectionSuccessCallback:(void (^_Nonnull)(VideoPlayer * _Nonnull))onConnectionSuccessCallback + onConnectionFailureCallback:(void (^_Nonnull)(MatterError * _Nonnull))onConnectionFailureCallback + onNewOrUpdatedEndpointCallback:(void (^_Nonnull)(ContentApp * _Nonnull))onNewOrUpdatedEndpointCallback; + +/*! + @brief Tears down all active subscriptions. + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Called after the request has been sent + */ +- (void)shutdownAllSubscriptions:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nullable void (^)())requestSentHandler; + +/*! + @brief Mark any open session with the currently connected Video player as expired. + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Called after the request has been sent + */ +- (void)disconnect:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nullable void (^)())requestSentHandler; + +/*! + @brief Purge data cached by the Matter casting library + + @param clientQueue Queue to invoke callbacks on + + @param responseHandler Called when purgeCache completes + */ +- (void)purgeCache:(dispatch_queue_t _Nonnull)clientQueue responseHandler:(void (^_Nonnull)(MatterError * _Nonnull))responseHandler; + +/*! + @brief Start the Matter server and reconnect to a previously connected Video Player (if any). This API is async + + @param clientQueue Queue to invoke callbacks on + + @param startMatterServerCompletionCallback Called after the Matter server has started and connected (or failed to connect) to a + previously connected video player (if any) are complete + */ +- (void)startMatterServer:(dispatch_queue_t _Nonnull)clientQueue + startMatterServerCompletionCallback:(nullable void (^)(MatterError * _Nonnull))startMatterServerCompletionCallback; + +/** + @brief Stop the Matter server + */ +- (void)stopMatterServer; + +/*! + @brief Send a ContentLauncher:LaunchURL request to a TV + + @param contentApp Content app endpoint to target + + @param contentUrl URL of the content to launch on the TV + + @param contentDisplayStr Display string value corresponding to the content + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)contentLauncher_launchUrl:(ContentApp * _Nonnull)contentApp + contentUrl:(NSString * _Nonnull)contentUrl + contentDisplayStr:(NSString * _Nonnull)contentDisplayStr + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a ContentLauncher:LaunchContent request to a TV + + @param contentApp Content app endpoint to target + + @param contentSearch Indicates the content to launch + + @param autoPlay Play Best match automatically if true, otherwise display matches + + @param data App specific data to be passed to the TV + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)contentLauncher_launchContent:(ContentApp * _Nonnull)contentApp + contentSearch:(ContentLauncher_ContentSearch * _Nonnull)contentSearch + autoPlay:(bool)autoPlay + data:(NSString * _Nullable)data + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:Play request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_play:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:Pause request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_pause:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:StopPlayback request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_stopPlayback:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:Next request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_next:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:Previous request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_previous:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:FastForward request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_fastForward:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:Rewind request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_rewind:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:StartOver request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_startOver:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:Seek request to a TV + + @param contentApp Content app endpoint to target + + @param position the position (in milliseconds) in the media to seek to + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_seek:(ContentApp * _Nonnull)contentApp + position:(uint64_t)position + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:SkipForward request to a TV + + @param contentApp Content app endpoint to target + + @param deltaPositionMilliseconds the duration of the time span to skip forward in the media, in milliseconds + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_skipForward:(ContentApp * _Nonnull)contentApp + deltaPositionMilliseconds:(uint64_t)deltaPositionMilliseconds + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a MediaPlayback:SkipBackward request to a TV + + @param contentApp Content app endpoint to target + + @param deltaPositionMilliseconds the duration of the time span to skip backward in the media, in milliseconds + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)mediaPlayback_skipBackward:(ContentApp * _Nonnull)contentApp + deltaPositionMilliseconds:(uint64_t)deltaPositionMilliseconds + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Subscribe to MediaPlayback:CurrentState + + @param contentApp Content app endpoint to target + + @param minInterval Minimum interval between attribute read reports + + @param maxInterval Maximum interval between attribute read reports + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + + @param successCallback Callback for when a read report is successfully received + + @param failureCallback Callback for when there is a failure in receiving a read report + + @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully + */ +- (void)mediaPlayback_subscribeCurrentState:(ContentApp * _Nonnull)contentApp + minInterval:(uint16_t)minInterval + maxInterval:(uint16_t)maxInterval + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(MediaPlayback_PlaybackState))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback + subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; + +/*! + @brief Send a ApplicationLauncher:LaunchApp request to a TV + + @param contentApp Content app endpoint to target + + @param catalogVendorId CSA-issued vendor ID for the catalog + + @param applicationId application identifier, unique within a catalog, expressed as a string, such as "PruneVideo" or "Company X" + + @param data optional app-specific data to be sent to the app + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)applicationLauncher_launchApp:(ContentApp * _Nonnull)contentApp + catalogVendorId:(uint16_t)catalogVendorId + applicationId:(NSString * _Nonnull)applicationId + data:(NSData * _Nullable)data + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a ApplicationLauncher:StopApp request to a TV + + @param contentApp Content app endpoint to target + + @param catalogVendorId CSA-issued vendor ID for the catalog + + @param applicationId application identifier, unique within a catalog, expressed as a string, such as "PruneVideo" or "Company X" + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)applicationLauncher_stopApp:(ContentApp * _Nonnull)contentApp + catalogVendorId:(uint16_t)catalogVendorId + applicationId:(NSString * _Nonnull)applicationId + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a ApplicationLauncher:HideApp request to a TV + + @param contentApp Content app endpoint to target + + @param catalogVendorId CSA-issued vendor ID for the catalog + + @param applicationId application identifier, unique within a catalog, expressed as a string, such as "PruneVideo" or "Company X" + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)applicationLauncher_hideApp:(ContentApp * _Nonnull)contentApp + catalogVendorId:(uint16_t)catalogVendorId + applicationId:(NSString * _Nonnull)applicationId + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a TargetNavigator:NavigateTarget request to a TV + + @param contentApp Content app endpoint to target + + @param target Identifier for the target for UX navigation, contained within one of the TargetInfo objects in the TargetList + attribute list. + + @param data Optional app-specific data + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)targetNavigator_navigateTarget:(ContentApp * _Nonnull)contentApp + target:(uint8_t)target + data:(NSString * _Nullable)data + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Subscribe to TargetNavigator:TargetList + + @param contentApp Content app endpoint to target + + @param minInterval Minimum interval between attribute read reports + + @param maxInterval Maximum interval between attribute read reports + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + + @param successCallback Callback for when a read report is successfully received + + @param failureCallback Callback for when there is a failure in receiving a read report + + @param subscriptionEstablishedCallback Callback for when the requested subscription has been established successfully + */ +- (void)targetNavigator_subscribeTargetList:(ContentApp * _Nonnull)contentApp + minInterval:(uint16_t)minInterval + maxInterval:(uint16_t)maxInterval + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSMutableArray * _Nullable))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback + subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback; + +/*! + @brief Send a KeypadInput:SendKey request to a TV + + @param contentApp Content app endpoint to target + + @param keyCode Key Code to process. If a second SendKey request with the same KeyCode value is received within 200ms, then the + endpoint will consider the first key press to be a press and hold. When such a repeat KeyCode value is not received within 200ms, + then the endpoint will consider the last key press to be a release. + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)keypadInput_sendKey:(ContentApp * _Nonnull)contentApp + keyCode:(uint8_t)keyCode + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Read ApplicationBasic:VendorName + + @param contentApp Content app endpoint to target + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + + @param successCallback Callback for when a read report is successfully received + + @param failureCallback Callback for when there is a failure in receiving a read report + */ +- (void)applicationBasic_readVendorName:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; + +/*! + @brief Read ApplicationBasic:VendorID + + @param contentApp Content app endpoint to target + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + + @param successCallback Callback for when a read report is successfully received + + @param failureCallback Callback for when there is a failure in receiving a read report + */ +- (void)applicationBasic_readVendorID:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSNumber * _Nonnull))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; + +/*! + @brief Read ApplicationBasic:ApplicationName + + @param contentApp Content app endpoint to target + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + + @param successCallback Callback for when a read report is successfully received + + @param failureCallback Callback for when there is a failure in receiving a read report + */ +- (void)applicationBasic_readApplicationName:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; + +/*! + @brief Read ApplicationBasic:ProductID + + @param contentApp Content app endpoint to target + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + + @param successCallback Callback for when a read report is successfully received + + @param failureCallback Callback for when there is a failure in receiving a read report + */ +- (void)applicationBasic_readProductID:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(uint16_t))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; + +/*! + @brief Read ApplicationBasic:ApplicationVersion + + @param contentApp Content app endpoint to target + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + + @param successCallback Callback for when a read report is successfully received + + @param failureCallback Callback for when there is a failure in receiving a read report + */ +- (void)applicationBasic_readApplicationVersion:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback; +/*! + @brief Send a OnOff:On request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)onOff_on:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a OnOff:Off request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)onOff_off:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; + +/*! + @brief Send a OnOff:Toggle request to a TV + + @param contentApp Content app endpoint to target + + @param responseCallback Callback for when the response has been received + + @param clientQueue Queue to invoke callbacks on + + @param requestSentHandler Handler to call on sending the request + */ +- (void)onOff_toggle:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler; +@end +#endif /* CastingServerBridge_h */ diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.mm new file mode 100644 index 00000000000000..ca7ccb3162fa8c --- /dev/null +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.mm @@ -0,0 +1,1290 @@ +/** + * + * Copyright (c) 2020-2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "CastingServerBridge.h" + +#import "../zap-generated/MCClusterObjects.h" +#import "../zap-generated/MCEndpointClusterType.h" +#import "CastingPlayerDiscoveryListenerCompat.h" +#import "DataSourceCompat.h" +#import "MCCastingApp.h" +#import "MCCastingPlayerDiscovery.h" +#import "MCCastingPlayer_Internal.h" +#import "MCEndpoint.h" +#import "MCErrorUtils.h" + +#import "MatterCallbacks.h" +#import "OnboardingPayload.h" + +#include +#include +#include +#include +#include +#include + +static const uint32_t kTargetPlayerDeviceType = 0x23; + +@interface CastingServerBridge () + +@property DataSourceCompat * dataSource; +@property dispatch_block_t cancelDiscoveryCommissionersWork; +@property dispatch_queue_t commissioningClientQueue; +@property CommissioningCallbackHandlers * commissioningCallbackHandlers; +@property void (^_Nonnull onConnectionSuccessCallback)(VideoPlayer * _Nonnull); +@property void (^_Nonnull onConnectionFailureCallback)(MatterError * _Nonnull); +@property void (^_Nonnull onNewOrUpdatedEndpointCallback)(ContentApp * _Nonnull); +@property AppParameters * appParameters; ++ (MCCluster * _Nullable)getClusterWith:(MCEndpointClusterType)type contentApp:(ContentApp * _Nonnull)contentApp; + +@end + +@implementation CastingServerBridge + ++ (CastingServerBridge * _Nullable)getSharedInstance +{ + static CastingServerBridge * instance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + instance = [[self alloc] init]; + }); + return instance; +} + ++ (MCCluster * _Nullable)getClusterWith:(MCEndpointClusterType)type contentApp:(ContentApp * _Nonnull)contentApp +{ + MCCastingPlayer * castingPlayer = [MCCastingPlayer getTargetCastingPlayer]; + VerifyOrReturnValue(castingPlayer != nil, nil, ChipLogError(AppServer, "CastingServerBridge.clusterForType no active target CastingPlayer found")); + + MCEndpoint * endpoint = [[castingPlayer endpoints] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(MCEndpoint * evalEndpoint, NSDictionary * bindings) { + return [[evalEndpoint identifier] intValue] == contentApp.endpointId; + }]].firstObject; + + VerifyOrReturnValue(endpoint != nil, nil, ChipLogError(AppServer, "CastingServerBridge.clusterForType endpoint with ID: %d not found", contentApp.endpointId)); + return [endpoint clusterForType:type]; +} + +- (MatterError *)initializeApp:(AppParameters * _Nullable)appParameters + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + initAppStatusHandler:(nullable void (^)(MatterError * _Nonnull))initAppStatusHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().initializeApp() called"); + + _appParameters = appParameters; + _dataSource = [[DataSourceCompat alloc] initWithClientQueue:clientQueue]; + [_dataSource setAppParameters:appParameters]; + + NSError * err = [MCCastingApp.getSharedInstance initializeWithDataSource:_dataSource]; + VerifyOrReturnValue(err == nil, [MCErrorUtils MatterErrorFromNsError:err]); + + [MCCastingApp.getSharedInstance startWithCompletionBlock:^(NSError * _Nullable e) { + dispatch_async(clientQueue, ^{ + initAppStatusHandler([MCErrorUtils MatterErrorFromNsError:e]); + }); + }]; + + return MATTER_NO_ERROR; +} + +- (void)setDacHolder:(DeviceAttestationCredentialsHolder * _Nonnull)deviceAttestationCredentials + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + setDacHolderStatus:(void (^_Nonnull)(MatterError * _Nonnull))setDacHolderStatus +{ + ChipLogProgress(AppServer, "CastingServerBridge().setDacHolder() called"); + + dispatch_sync([MCCastingApp.getSharedInstance getWorkQueue], ^{ + [self.dataSource setDacHolder:deviceAttestationCredentials]; + dispatch_async(clientQueue, ^{ + setDacHolderStatus(MATTER_NO_ERROR); + }); + }); +} + +- (void)discoverCommissioners:(dispatch_queue_t _Nonnull)clientQueue + discoveryRequestSentHandler:(nullable void (^)(MatterError * _Nonnull))discoveryRequestSentHandler + discoveredCommissionerHandler:(nullable void (^)(DiscoveredNodeData *))discoveredCommissionerHandler +{ + [self discoverCommissioners:clientQueue timeoutInSeconds:0 discoveryRequestSentHandler:discoveryRequestSentHandler discoveredCommissionerHandler:discoveredCommissionerHandler]; +} + +- (void)discoverCommissioners:(dispatch_queue_t _Nonnull)clientQueue + timeoutInSeconds:(NSUInteger)timeoutInSeconds + discoveryRequestSentHandler:(nullable void (^)(MatterError * _Nonnull))discoveryRequestSentHandler + discoveredCommissionerHandler:(nullable void (^)(DiscoveredNodeData *))discoveredCommissionerHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().discoverCommissioners() called with timeoutInSeconds: %lu", timeoutInSeconds); + + dispatch_sync([[MCCastingApp getSharedInstance] getWorkQueue], ^{ + // cancel any future dispatches to cancelDiscoveryCommissionersWork + if (self->_cancelDiscoveryCommissionersWork) { + ChipLogProgress(AppServer, "CastingServerBridge().discoverCommissioners() canceling dispatch to cancelDiscoveryCommissionersWork"); + dispatch_block_cancel(self->_cancelDiscoveryCommissionersWork); + self->_cancelDiscoveryCommissionersWork = nil; + } + }); + + // stop previously triggered discovery and remove observers, if any + NSError * e = [MCCastingPlayerDiscovery.sharedInstance stop]; + if (e != nil) { + ChipLogError(AppServer, "CastingServerBridge().discoverCommissioners() MCCastingPlayerDiscovery stop error: %@", e.description); + } + [CastingPlayerDiscoveryListenerCompat removeObservers]; + + // add observers and start discovery + [CastingPlayerDiscoveryListenerCompat addObservers:clientQueue discoveredCommissionerHandler:discoveredCommissionerHandler]; + NSError * err = [MCCastingPlayerDiscovery.sharedInstance start:kTargetPlayerDeviceType]; + if (err == nil) { + // if positive timeoutInSeconds specified, dispatch call to cancel this discovery request AFTER timeoutInSeconds + if (timeoutInSeconds > 0) { + self->_cancelDiscoveryCommissionersWork + = dispatch_block_create(static_cast(0), ^{ + if (dispatch_block_testcancel(self->_cancelDiscoveryCommissionersWork)) { + ChipLogProgress(AppServer, "CastingServerBridge().discoverCommissioners() cancel timer invalidated."); + return; + } + + // stop previously triggered discovery and remove observers, if any + ChipLogProgress(AppServer, "CastingServerBridge().discoverCommissioners() canceling previous discovery request"); + NSError * e = [MCCastingPlayerDiscovery.sharedInstance stop]; + if (e != nil) { + ChipLogError(AppServer, "CastingServerBridge().discoverCommissioners() MCCastingPlayerDiscovery stop error: %@", e.description); + } + [CastingPlayerDiscoveryListenerCompat removeObservers]; + self->_cancelDiscoveryCommissionersWork = nil; + }); + + ChipLogProgress(AppServer, "CastingServerBridge().discoverCommissioners() dispatching cancelDiscoveryCommissionersWork for %lu sec later", timeoutInSeconds); + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, timeoutInSeconds * NSEC_PER_SEC), [[MCCastingApp getSharedInstance] getWorkQueue], self->_cancelDiscoveryCommissionersWork); + } + } else { + ChipLogError(AppServer, "CastingServerBridge().discoverCommissioners() MCCastingPlayerDiscovery start error: %@", err.description); + [CastingPlayerDiscoveryListenerCompat removeObservers]; + } + + dispatch_async(clientQueue, ^{ + discoveryRequestSentHandler([MCErrorUtils MatterErrorFromNsError:err]); + }); +} + +- (OnboardingPayload *)getOnboardingPayload +{ + return _appParameters.onboardingPayload; +} + +- (void)openBasicCommissioningWindow:(dispatch_queue_t _Nonnull)clientQueue + commissioningCallbackHandlers:(CommissioningCallbackHandlers * _Nullable)commissioningCallbackHandlers + onConnectionSuccessCallback:(void (^_Nonnull)(VideoPlayer * _Nonnull))onConnectionSuccessCallback + onConnectionFailureCallback:(void (^_Nonnull)(MatterError * _Nonnull))onConnectionFailureCallback + onNewOrUpdatedEndpointCallback:(void (^_Nonnull)(ContentApp * _Nonnull))onNewOrUpdatedEndpointCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().openBasicCommissioningWindow() called"); + // capture the callbacks + _commissioningClientQueue = clientQueue; + _commissioningCallbackHandlers = commissioningCallbackHandlers; + _onConnectionSuccessCallback = onConnectionSuccessCallback; + _onConnectionFailureCallback = onConnectionFailureCallback; + _onNewOrUpdatedEndpointCallback = onNewOrUpdatedEndpointCallback; + + // no-op: short-circuit commissioningWindow callbacks with MATTER_NO_ERROR + dispatch_async(clientQueue, ^{ + if (commissioningCallbackHandlers != nil) { + if (commissioningCallbackHandlers.commissioningWindowRequestedHandler != nil) { + commissioningCallbackHandlers.commissioningWindowRequestedHandler(MATTER_NO_ERROR); + } + if (commissioningCallbackHandlers.commissioningWindowOpenedCallback != nil) { + commissioningCallbackHandlers.commissioningWindowOpenedCallback(MATTER_NO_ERROR); + } + } + }); +} + +- (void)sendUserDirectedCommissioningRequest:(DiscoveredNodeData * _Nonnull)commissioner + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + udcRequestSentHandler:(nullable void (^)(MatterError * _Nonnull))udcRequestSentHandler +{ + [self sendUserDirectedCommissioningRequest:commissioner clientQueue:clientQueue udcRequestSentHandler:udcRequestSentHandler]; +} + +- (void)sendUserDirectedCommissioningRequest:(DiscoveredNodeData * _Nonnull)commissioner + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + udcRequestSentHandler:(nullable void (^)(MatterError * _Nonnull))udcRequestSentHandler + desiredContentAppVendorId:(uint16_t)desiredContentAppVendorId +{ + ChipLogProgress(AppServer, "CastingServerBridge().sendUserDirectedCommissioningRequest() called with desiredContentAppVendorId: %d", desiredContentAppVendorId); + + MCEndpointFilter * filter = [MCEndpointFilter new]; + filter.vendorId = desiredContentAppVendorId; + + [commissioner.getCastingPlayer verifyOrEstablishConnectionWithCompletionBlock:^(NSError * _Nullable err) { + dispatch_async(clientQueue, ^{ + if (err == nil) { + if (self->_commissioningCallbackHandlers != nil && self->_commissioningCallbackHandlers.commissioningCompleteCallback != nil) { + self->_commissioningCallbackHandlers.commissioningCompleteCallback(MATTER_NO_ERROR); + } + + MCCastingPlayer * castingPlayer = [MCCastingPlayer getTargetCastingPlayer]; + if (self->_onConnectionSuccessCallback != nil) { + self->_onConnectionSuccessCallback([[VideoPlayer alloc] initWithCastingPlayer:castingPlayer]); + } + + if (self->_onNewOrUpdatedEndpointCallback != nil && castingPlayer != nil) { + NSArray * endpoints = castingPlayer.endpoints; + for (MCEndpoint * endpoint in endpoints) { + self->_onNewOrUpdatedEndpointCallback([[ContentApp alloc] initWithEndpoint:endpoint]); + } + } + } + }); + } desiredEndpointFilter:filter]; + + dispatch_async(clientQueue, ^{ + udcRequestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)getActiveTargetVideoPlayers:(dispatch_queue_t _Nonnull)clientQueue + activeTargetVideoPlayersHandler:(nullable void (^)(NSMutableArray * _Nullable))activeTargetVideoPlayersHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().getActiveTargetVideoPlayers() called"); + NSMutableArray * videoPlayers = [NSMutableArray new]; + MCCastingPlayer * castingPlayer = [MCCastingPlayer getTargetCastingPlayer]; + if (castingPlayer != nil) { + VideoPlayer * videoPlayer = [[VideoPlayer alloc] initWithCastingPlayer:castingPlayer]; + videoPlayer.isConnected = true; + videoPlayers[0] = videoPlayer; + } + dispatch_async(clientQueue, ^{ + activeTargetVideoPlayersHandler(videoPlayers); + }); +} + +- (void)verifyOrEstablishConnection:(VideoPlayer * _Nonnull)videoPlayer + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(nullable void (^)(MatterError * _Nonnull))requestSentHandler + onConnectionSuccessCallback:(void (^_Nonnull)(VideoPlayer * _Nonnull))onConnectionSuccessCallback + onConnectionFailureCallback:(void (^_Nonnull)(MatterError * _Nonnull))onConnectionFailureCallback + onNewOrUpdatedEndpointCallback:(void (^_Nonnull)(ContentApp * _Nonnull))onNewOrUpdatedEndpointCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().verifyOrEstablishConnection() is unsupported"); + + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_NOT_IMPLEMENTED]); + }); +} + +- (void)shutdownAllSubscriptions:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nullable void (^)())requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().shutdownAllSubscriptions() called"); + [[MCCastingApp getSharedInstance] ShutdownAllSubscriptions]; + dispatch_async(clientQueue, ^{ + requestSentHandler(); + }); +} + +- (void)startMatterServer:(dispatch_queue_t _Nonnull)clientQueue + startMatterServerCompletionCallback:(nullable void (^)(MatterError * _Nonnull))startMatterServerCompletionCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().startMatterServer() called"); + [[MCCastingApp getSharedInstance] startWithCompletionBlock:^(NSError * _Nullable err) { + ChipLogError(AppServer, "CastingServerBridge() startWithCompletionBlock called"); + startMatterServerCompletionCallback([MCErrorUtils MatterErrorFromNsError:err]); + }]; +} + +- (void)stopMatterServer +{ + ChipLogProgress(AppServer, "CastingServerBridge().stopMatterServer() called"); + [[MCCastingApp getSharedInstance] stopWithCompletionBlock:^(NSError * _Nullable) { + ChipLogError(AppServer, "CastingServerBridge() stopWithCompletionBlock called"); + }]; +} + +- (void)disconnect:(dispatch_queue_t _Nonnull)clientQueue requestSentHandler:(nullable void (^)())requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().disconnect() called"); + MCCastingPlayer * castingPlayer = [MCCastingPlayer getTargetCastingPlayer]; + if (castingPlayer != nil) { + [castingPlayer disconnect]; + } + dispatch_async(clientQueue, ^{ + requestSentHandler(); + }); +} + +- (void)purgeCache:(dispatch_queue_t _Nonnull)clientQueue responseHandler:(void (^)(MatterError * _Nonnull))responseHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().purgeCache() called"); + NSError * err = [[MCCastingApp getSharedInstance] ClearCache]; + dispatch_async(clientQueue, ^{ + responseHandler([MCErrorUtils MatterErrorFromNsError:err]); + }); +} + +- (void)contentLauncher_launchUrl:(ContentApp * _Nonnull)contentApp + contentUrl:(NSString * _Nonnull)contentUrl + contentDisplayStr:(NSString * _Nonnull)contentDisplayStr + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().contentLauncher_launchUrl() called"); + MCContentLauncherCluster * cluster = (MCContentLauncherCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeContentLauncher contentApp:contentApp]; + if (cluster == nil || [cluster launchURLCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCContentLauncherClusterLaunchURLParams * request = [[MCContentLauncherClusterLaunchURLParams alloc] init]; + request.contentURL = contentUrl; + request.displayString = contentDisplayStr; + [[cluster launchURLCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCContentLauncherClusterLauncherResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)contentLauncher_launchContent:(ContentApp * _Nonnull)contentApp + contentSearch:(ContentLauncher_ContentSearch * _Nonnull)contentSearch + autoPlay:(bool)autoPlay + data:(NSString * _Nullable)data + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().contentLauncher_launchContent() called"); + MCContentLauncherCluster * cluster = (MCContentLauncherCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeContentLauncher contentApp:contentApp]; + if (cluster == nil || [cluster launchContentCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCContentLauncherClusterLaunchContentParams * request = [MCContentLauncherClusterLaunchContentParams new]; + request.autoPlay = @(autoPlay); + request.data = data; + MCContentLauncherClusterContentSearchStruct * search = nil; + if (contentSearch.parameterList != nil) { + NSMutableArray * parameterList = [NSMutableArray new]; + for (ContentLauncher_Parameter * srcParameter in contentSearch.parameterList) { + MCContentLauncherClusterParameterStruct * parameter = [MCContentLauncherClusterParameterStruct new]; + parameter.type = @(srcParameter.type); + parameter.value = srcParameter.value; + if (srcParameter.externalIDList != nil) { + NSMutableArray * externalIdList = [NSMutableArray new]; + for (ContentLauncher_AdditionalInfo * srcExternalId in srcParameter.externalIDList) { + MCContentLauncherClusterAdditionalInfoStruct * externalId = [MCContentLauncherClusterAdditionalInfoStruct new]; + externalId.name = srcExternalId.name; + externalId.value = srcExternalId.value; + [externalIdList addObject:externalId]; + } + parameter.externalIDList = externalIdList; + } + [parameterList addObject:parameter]; + } + + search = [MCContentLauncherClusterContentSearchStruct new]; + search.parameterList = parameterList; + } + request.search = search; + + [[cluster launchContentCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCContentLauncherClusterLauncherResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_play:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_play() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster playCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterPlayParams * request = [MCMediaPlaybackClusterPlayParams new]; + [[cluster playCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_pause:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_pause() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster pauseCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterPauseParams * request = [MCMediaPlaybackClusterPauseParams new]; + [[cluster pauseCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_stopPlayback:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_stopPlayback() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster stopCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterStopParams * request = [MCMediaPlaybackClusterStopParams new]; + [[cluster stopCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_next:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_next() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster nextCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterNextParams * request = [MCMediaPlaybackClusterNextParams new]; + [[cluster nextCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_seek:(ContentApp * _Nonnull)contentApp + position:(uint64_t)position + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_seek() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster seekCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterSeekParams * request = [MCMediaPlaybackClusterSeekParams new]; + request.position = @(position); + [[cluster seekCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_skipForward:(ContentApp * _Nonnull)contentApp + deltaPositionMilliseconds:(uint64_t)deltaPositionMilliseconds + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_skipForward() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster skipForwardCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterSkipForwardParams * request = [MCMediaPlaybackClusterSkipForwardParams new]; + request.deltaPositionMilliseconds = @(deltaPositionMilliseconds); + [[cluster skipForwardCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_skipBackward:(ContentApp * _Nonnull)contentApp + deltaPositionMilliseconds:(uint64_t)deltaPositionMilliseconds + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_skipBackward() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster skipBackwardCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterSkipBackwardParams * request = [MCMediaPlaybackClusterSkipBackwardParams new]; + request.deltaPositionMilliseconds = @(deltaPositionMilliseconds); + [[cluster skipBackwardCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_previous:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_previous() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster previousCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterPreviousParams * request = [MCMediaPlaybackClusterPreviousParams new]; + [[cluster previousCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_rewind:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_rewind() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster rewindCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterRewindParams * request = [MCMediaPlaybackClusterRewindParams new]; + [[cluster rewindCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_fastForward:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_fastForward() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster fastForwardCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterFastForwardParams * request = [MCMediaPlaybackClusterFastForwardParams new]; + [[cluster fastForwardCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_startOver:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_startOver() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster startOverCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCMediaPlaybackClusterStartOverParams * request = [MCMediaPlaybackClusterStartOverParams new]; + [[cluster startOverCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCMediaPlaybackClusterPlaybackResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)mediaPlayback_subscribeCurrentState:(ContentApp * _Nonnull)contentApp + minInterval:(uint16_t)minInterval + maxInterval:(uint16_t)maxInterval + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(MediaPlayback_PlaybackState))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback + subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().mediaPlayback_subscribeCurrentState() called"); + MCMediaPlaybackCluster * cluster = (MCMediaPlaybackCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeMediaPlayback contentApp:contentApp]; + if (cluster == nil || [cluster currentStateAttribute] == nil) { + ChipLogError(AppServer, "Cluster/attribute not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + [[cluster currentStateAttribute] subscribe:nil completion:^(void * _Nullable context, NSNumber * _Nullable before, NSNumber * _Nullable after, NSError * _Nullable err) { + dispatch_async(clientQueue, ^{ + if (err != nil) { + failureCallback([MCErrorUtils MatterErrorFromNsError:err]); + } else { + successCallback((MediaPlayback_PlaybackState)[after unsignedCharValue]); + } + }); + } minInterval:@(minInterval) maxInterval:@(maxInterval)]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + subscriptionEstablishedCallback(); + }); +} + +- (void)applicationLauncher_launchApp:(ContentApp * _Nonnull)contentApp + catalogVendorId:(uint16_t)catalogVendorId + applicationId:(NSString * _Nonnull)applicationId + data:(NSData * _Nullable)data + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().applicationLauncher_launchApp() called"); + MCApplicationLauncherCluster * cluster = (MCApplicationLauncherCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeApplicationLauncher contentApp:contentApp]; + if (cluster == nil || [cluster launchAppCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCApplicationLauncherClusterLaunchAppParams * request = [MCApplicationLauncherClusterLaunchAppParams new]; + request.data = data; + MCApplicationLauncherClusterApplicationStruct * application = [MCApplicationLauncherClusterApplicationStruct new]; + application.catalogVendorID = @(catalogVendorId); + application.applicationID = applicationId; + request.application = application; + + [[cluster launchAppCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCApplicationLauncherClusterLauncherResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)applicationLauncher_stopApp:(ContentApp * _Nonnull)contentApp + catalogVendorId:(uint16_t)catalogVendorId + applicationId:(NSString * _Nonnull)applicationId + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().applicationLauncher_stopApp() called"); + MCApplicationLauncherCluster * cluster = (MCApplicationLauncherCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeApplicationLauncher contentApp:contentApp]; + if (cluster == nil || [cluster stopAppCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCApplicationLauncherClusterStopAppParams * request = [MCApplicationLauncherClusterStopAppParams new]; + MCApplicationLauncherClusterApplicationStruct * application = [MCApplicationLauncherClusterApplicationStruct new]; + application.catalogVendorID = @(catalogVendorId); + application.applicationID = applicationId; + request.application = application; + + [[cluster stopAppCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCApplicationLauncherClusterLauncherResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)applicationLauncher_hideApp:(ContentApp * _Nonnull)contentApp + catalogVendorId:(uint16_t)catalogVendorId + applicationId:(NSString * _Nonnull)applicationId + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().applicationLauncher_hideApp() called"); + MCApplicationLauncherCluster * cluster = (MCApplicationLauncherCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeApplicationLauncher contentApp:contentApp]; + if (cluster == nil || [cluster hideAppCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCApplicationLauncherClusterHideAppParams * request = [MCApplicationLauncherClusterHideAppParams new]; + MCApplicationLauncherClusterApplicationStruct * application = [MCApplicationLauncherClusterApplicationStruct new]; + application.catalogVendorID = @(catalogVendorId); + application.applicationID = applicationId; + request.application = application; + + [[cluster hideAppCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCApplicationLauncherClusterLauncherResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)targetNavigator_navigateTarget:(ContentApp * _Nonnull)contentApp + target:(uint8_t)target + data:(NSString * _Nullable)data + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().targetNavigator_navigateTarget() called"); + MCTargetNavigatorCluster * cluster = (MCTargetNavigatorCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeTargetNavigator contentApp:contentApp]; + if (cluster == nil || [cluster navigateTargetCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCTargetNavigatorClusterNavigateTargetParams * request = [MCTargetNavigatorClusterNavigateTargetParams new]; + request.target = @(target); + request.data = data; + + [[cluster navigateTargetCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCTargetNavigatorClusterNavigateTargetResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)targetNavigator_subscribeTargetList:(ContentApp * _Nonnull)contentApp + minInterval:(uint16_t)minInterval + maxInterval:(uint16_t)maxInterval + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSMutableArray *))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback + subscriptionEstablishedCallback:(void (^_Nonnull)())subscriptionEstablishedCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().targetNavigator_subscribeTargetList() called"); + MCTargetNavigatorCluster * cluster = (MCTargetNavigatorCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeTargetNavigator contentApp:contentApp]; + if (cluster == nil || [cluster targetListAttribute] == nil) { + ChipLogError(AppServer, "Cluster/attribute not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + [[cluster targetListAttribute] subscribe:nil completion:^(void * _Nullable context, NSArray * _Nullable, NSArray * _Nullable newTargetList, NSError * _Nullable err) { + dispatch_async(clientQueue, ^{ + if (err != nil) { + failureCallback([MCErrorUtils MatterErrorFromNsError:err]); + } else { + NSMutableArray * resultTargetList = nil; + if (newTargetList != nil) { + resultTargetList = [NSMutableArray arrayWithCapacity:newTargetList.count]; + for (MCTargetNavigatorClusterTargetInfoStruct * targetInfo in newTargetList) { + [resultTargetList addObject:[[TargetNavigator_TargetInfoStruct alloc] initWithIdentifier:targetInfo.identifier name:targetInfo.name]]; + } + } + successCallback(resultTargetList); + } + }); + } minInterval:@(minInterval) maxInterval:@(maxInterval)]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + subscriptionEstablishedCallback(); + }); +} + +- (void)keypadInput_sendKey:(ContentApp * _Nonnull)contentApp + keyCode:(uint8_t)keyCode + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().keypadInput_sendKey() called"); + MCKeypadInputCluster * cluster = (MCKeypadInputCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeKeypadInput contentApp:contentApp]; + if (cluster == nil || [cluster sendKeyCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCKeypadInputClusterSendKeyParams * request = [MCKeypadInputClusterSendKeyParams new]; + request.keyCode = @(keyCode); + + [[cluster sendKeyCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCKeypadInputClusterSendKeyResponseParams * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)applicationBasic_readVendorName:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().applicationBasic_readVendorName() called"); + MCApplicationBasicCluster * cluster = (MCApplicationBasicCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeApplicationBasic contentApp:contentApp]; + if (cluster == nil || [cluster vendorNameAttribute] == nil) { + ChipLogError(AppServer, "Cluster/attribute not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + [[cluster vendorNameAttribute] read:nil completion:^(void * _Nullable context, NSString * _Nullable before, NSString * _Nullable after, NSError * _Nullable err) { + dispatch_async(clientQueue, ^{ + if (err != nil) { + failureCallback([MCErrorUtils MatterErrorFromNsError:err]); + } else { + successCallback(after); + } + }); + }]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)applicationBasic_readVendorID:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSNumber * _Nonnull))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().applicationBasic_readVendorID() called"); + MCApplicationBasicCluster * cluster = (MCApplicationBasicCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeApplicationBasic contentApp:contentApp]; + if (cluster == nil || [cluster vendorIDAttribute] == nil) { + ChipLogError(AppServer, "Cluster/attribute not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + [[cluster vendorIDAttribute] read:nil completion:^(void * _Nullable context, NSNumber * _Nullable before, NSNumber * _Nullable after, NSError * _Nullable err) { + dispatch_async(clientQueue, ^{ + if (err != nil) { + failureCallback([MCErrorUtils MatterErrorFromNsError:err]); + } else { + successCallback(after); + } + }); + }]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)applicationBasic_readApplicationName:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().applicationBasic_readApplicationName() called"); + MCApplicationBasicCluster * cluster = (MCApplicationBasicCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeApplicationBasic contentApp:contentApp]; + if (cluster == nil || [cluster applicationNameAttribute] == nil) { + ChipLogError(AppServer, "Cluster/attribute not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + [[cluster applicationNameAttribute] read:nil completion:^(void * _Nullable context, NSString * _Nullable before, NSString * _Nullable after, NSError * _Nullable err) { + dispatch_async(clientQueue, ^{ + if (err != nil) { + failureCallback([MCErrorUtils MatterErrorFromNsError:err]); + } else { + successCallback(after); + } + }); + }]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)applicationBasic_readProductID:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(uint16_t))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().applicationBasic_readProductID() called"); + MCApplicationBasicCluster * cluster = (MCApplicationBasicCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeApplicationBasic contentApp:contentApp]; + if (cluster == nil || [cluster productIDAttribute] == nil) { + ChipLogError(AppServer, "Cluster/attribute not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + [[cluster productIDAttribute] read:nil completion:^(void * _Nullable context, NSNumber * _Nullable before, NSNumber * _Nullable after, NSError * _Nullable err) { + dispatch_async(clientQueue, ^{ + if (err != nil) { + failureCallback([MCErrorUtils MatterErrorFromNsError:err]); + } else { + successCallback([after unsignedShortValue]); + } + }); + }]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)applicationBasic_readApplicationVersion:(ContentApp * _Nonnull)contentApp + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler + successCallback:(void (^_Nonnull)(NSString * _Nonnull))successCallback + failureCallback:(void (^_Nonnull)(MatterError * _Nonnull))failureCallback +{ + ChipLogProgress(AppServer, "CastingServerBridge().applicationBasic_readApplicationVersion() called"); + MCApplicationBasicCluster * cluster = (MCApplicationBasicCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeApplicationBasic contentApp:contentApp]; + if (cluster == nil || [cluster applicationVersionAttribute] == nil) { + ChipLogError(AppServer, "Cluster/attribute not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + [[cluster applicationVersionAttribute] read:nil completion:^(void * _Nullable context, NSString * _Nullable before, NSString * _Nullable after, NSError * _Nullable err) { + dispatch_async(clientQueue, ^{ + if (err != nil) { + failureCallback([MCErrorUtils MatterErrorFromNsError:err]); + } else { + successCallback(after); + } + }); + }]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)onOff_on:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().onOff_on() called"); + MCOnOffCluster * cluster = (MCOnOffCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeOnOff contentApp:contentApp]; + if (cluster == nil || [cluster onCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCOnOffClusterOnParams * request = [MCOnOffClusterOnParams new]; + [[cluster onCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCNullObjectType * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)onOff_off:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().onOff_off() called"); + MCOnOffCluster * cluster = (MCOnOffCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeOnOff contentApp:contentApp]; + if (cluster == nil || [cluster offCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCOnOffClusterOffParams * request = [MCOnOffClusterOffParams new]; + [[cluster offCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCNullObjectType * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} + +- (void)onOff_toggle:(ContentApp * _Nonnull)contentApp + responseCallback:(void (^_Nonnull)(MatterError * _Nonnull))responseCallback + clientQueue:(dispatch_queue_t _Nonnull)clientQueue + requestSentHandler:(void (^_Nonnull)(MatterError * _Nonnull))requestSentHandler +{ + ChipLogProgress(AppServer, "CastingServerBridge().onOff_toggle() called"); + MCOnOffCluster * cluster = (MCOnOffCluster *) [CastingServerBridge getClusterWith:MCEndpointClusterTypeOnOff contentApp:contentApp]; + if (cluster == nil || [cluster toggleCommand] == nil) { + ChipLogError(AppServer, "Cluster/command not found"); + dispatch_async(clientQueue, ^{ + requestSentHandler([MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]); + }); + return; + } + + // create request + MCOnOffClusterToggleParams * request = [MCOnOffClusterToggleParams new]; + [[cluster toggleCommand] invoke:request + context:nil + completion:^(void * _Nullable, NSError * _Nullable err, MCNullObjectType * _Nullable response) { + dispatch_async(clientQueue, ^{ + responseCallback([MCErrorUtils MatterErrorFromNsError:err]); + }); + } + timedInvokeTimeoutMs:@5000]; + + dispatch_async(clientQueue, ^{ + requestSentHandler(MATTER_NO_ERROR); + }); +} +@end diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissioningCallbackHandlers.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CommissioningCallbackHandlers.h similarity index 83% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissioningCallbackHandlers.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CommissioningCallbackHandlers.h index 14288d7ffd6234..0b8abce46c2d61 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissioningCallbackHandlers.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CommissioningCallbackHandlers.h @@ -15,17 +15,19 @@ * limitations under the License. */ -#import "MatterError.h" +#import "../MatterError.h" #import #ifndef CommissioningCallbacksHandlers_h #define CommissioningCallbacksHandlers_h +__attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) @interface CommissioningCallbackHandlers : NSObject - (CommissioningCallbackHandlers * _Nonnull) - initWithCommissioningWindowRequestedHandler:(void (^_Nonnull)(bool))commissioningWindowRequestedHandler - commissioningCompleteCallback:(void (^_Nonnull)(bool))commissioningCompleteCallback + initWithCommissioningWindowRequestedHandler:(void (^_Nonnull)(MatterError * _Nonnull))commissioningWindowRequestedHandler + commissioningWindowOpenedCallback:(void (^_Nonnull)(MatterError * _Nonnull))commissioningWindowOpenedCallback + commissioningCompleteCallback:(void (^_Nonnull)(MatterError * _Nonnull))commissioningCompleteCallback sessionEstablishmentStartedCallback:(void (^_Nullable)(void))sessionEstablishmentStartedCallback sessionEstablishedCallback:(void (^_Nullable)(void))sessionEstablishedCallback sessionEstablishmentErrorCallback:(void (^_Nullable)(MatterError * _Nonnull))sessionEstablishmentErrorCallback @@ -34,12 +36,14 @@ /** * This is called when request to open the commissioning window has been made. */ -@property void (^_Nullable commissioningWindowRequestedHandler)(bool); +@property void (^_Nullable commissioningWindowRequestedHandler)(MatterError * _Nonnull); + +@property void (^_Nullable commissioningWindowOpenedCallback)(MatterError * _Nonnull); /** * This is called when the commissioning has been completed */ -@property void (^_Nullable commissioningCompleteCallback)(bool); +@property void (^_Nullable commissioningCompleteCallback)(MatterError * _Nonnull); /** * This is called when the PBKDFParamRequest is received and indicates the start of the session establishment process diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissioningCallbackHandlers.m b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CommissioningCallbackHandlers.m similarity index 85% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissioningCallbackHandlers.m rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CommissioningCallbackHandlers.m index be79d40793c4c2..c05661fab54e75 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CommissioningCallbackHandlers.m +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CommissioningCallbackHandlers.m @@ -20,8 +20,9 @@ @implementation CommissioningCallbackHandlers - (CommissioningCallbackHandlers * _Nonnull) - initWithCommissioningWindowRequestedHandler:(void (^_Nonnull)(bool))commissioningWindowRequestedHandler - commissioningCompleteCallback:(void (^_Nonnull)(bool))commissioningCompleteCallback + initWithCommissioningWindowRequestedHandler:(void (^_Nonnull)(MatterError * _Nonnull))commissioningWindowRequestedHandler + commissioningWindowOpenedCallback:(void (^_Nonnull)(MatterError * _Nonnull))commissioningWindowOpenedCallback + commissioningCompleteCallback:(void (^_Nonnull)(MatterError * _Nonnull))commissioningCompleteCallback sessionEstablishmentStartedCallback:(void (^_Nullable)(void))sessionEstablishmentStartedCallback sessionEstablishedCallback:(void (^_Nullable)(void))sessionEstablishedCallback sessionEstablishmentErrorCallback:(void (^_Nullable)(MatterError * _Nonnull))sessionEstablishmentErrorCallback @@ -30,6 +31,7 @@ @implementation CommissioningCallbackHandlers self = [super init]; if (self) { _commissioningWindowRequestedHandler = commissioningWindowRequestedHandler; + _commissioningWindowOpenedCallback = commissioningWindowOpenedCallback; _commissioningCompleteCallback = commissioningCompleteCallback; _sessionEstablishmentStartedCallback = sessionEstablishmentStartedCallback; _sessionEstablishedCallback = sessionEstablishedCallback; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentApp.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.h similarity index 87% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentApp.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.h index b9a7384b0a3f7e..d31530e0274da0 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentApp.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.h @@ -17,9 +17,12 @@ #import +#import "../MCEndpoint.h" + #ifndef ContentApp_h #define ContentApp_h +__attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) @interface ContentApp : NSObject @property uint16_t endpointId; @@ -33,6 +36,8 @@ - (instancetype)initWithEndpointId:(uint16_t)endpointId clusterIds:(NSMutableArray *)clusterIds; +- (instancetype)initWithEndpoint:(MCEndpoint *)endpoint; + - (BOOL)supportsClusterWithId:(uint32_t)clusterId; - (BOOL)supportsApplicationLauncher; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentApp.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.mm similarity index 87% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentApp.mm rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.mm index ac4649867bdb2a..fe0e92a1fab98a 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentApp.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.mm @@ -17,6 +17,7 @@ #import +#import "../MCEndpoint_Internal.h" #import "ContentApp.h" #include @@ -41,6 +42,16 @@ - (instancetype)initWithEndpointId:(uint16_t)endpointId clusterIds:(NSMutableArr return self; } +- (instancetype)initWithEndpoint:(MCEndpoint *)endpoint +{ + if (self = [super init]) { + _endpointId = [endpoint.identifier unsignedShortValue]; + _clusterIds = [endpoint getServerList]; + _isInitialized = true; + } + return self; +} + - (BOOL)supportsClusterWithId:(uint32_t)clusterId { if (_clusterIds != nil) { diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentLauncherTypes.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentLauncherTypes.h similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentLauncherTypes.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentLauncherTypes.h diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentLauncherTypes.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentLauncherTypes.mm similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/ContentLauncherTypes.mm rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentLauncherTypes.mm diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCObserver.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.h similarity index 54% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCObserver.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.h index a1ca48f8b87616..560e777bab814f 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCObserver.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.h @@ -1,6 +1,6 @@ /** * - * Copyright (c) 2020-2024 Project CHIP Authors + * Copyright (c) 2024 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,15 +15,22 @@ * limitations under the License. */ +#import "MCDataSource.h" + +#import "AppParameters.h" + #import -#ifndef MCObserver_h -#define MCObserver_h +#ifndef DataSourceCompat_h +#define DataSourceCompat_h -@protocol MCObserver +__attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) +@interface DataSourceCompat : NSObject -- (void)attribute:(NSObject * _Nonnull)sender valueDidChange:(NSValue * _Nullable)value oldValue:(NSValue * _Nullable)oldValue; +- (instancetype)initWithClientQueue:(dispatch_queue_t)clientQueue; +- (void)setAppParameters:(AppParameters *)appParameters; +- (void)setDacHolder:(DeviceAttestationCredentialsHolder *)dacHolder; @end -#endif /* MCObserver_h */ +#endif /* DataSourceCompat_h */ diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.mm new file mode 100644 index 00000000000000..6f23d13c0c62e9 --- /dev/null +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.mm @@ -0,0 +1,124 @@ +/** + * + * Copyright (c) 2020-2024 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import "DataSourceCompat.h" + +#import "MCCastingApp.h" +#import "MCCommissionableData.h" +#import "MCCryptoUtils.h" +#import "MCDeviceAttestationCredentials.h" +#import "MCErrorUtils.h" + +#include +#include +#include +#include +#include +#include + +@interface DataSourceCompat () + +@property (nonatomic, strong) dispatch_queue_t clientQueue; +@property (nonatomic, strong) AppParameters * appParameters; +@property (nonatomic, strong) DeviceAttestationCredentialsHolder * dacHolder; + +@end + +@implementation DataSourceCompat + +- (instancetype)initWithClientQueue:(dispatch_queue_t)clientQueue +{ + self = [super init]; + if (self) { + _clientQueue = clientQueue; + } + return self; +} + +- (dispatch_queue_t _Nonnull)clientQueue +{ + return _clientQueue; +} + +- (void)setAppParameters:(AppParameters *)appParameters +{ + _appParameters = appParameters; +} + +- (void)setDacHolder:(DeviceAttestationCredentialsHolder *)dacHolder +{ + _dacHolder = dacHolder; +} + +- (NSData *)castingAppDidReceiveRequestForRotatingDeviceIdUniqueId:(id)sender +{ + ChipLogProgress(AppServer, "DataSourceCompat::castingAppDidReceiveRequestForRotatingDeviceIdUniqueId called"); + if (self.appParameters != nil) { + return self.appParameters.rotatingDeviceIdUniqueId; + } + return nil; +} + +- (MCCommissionableData *)castingAppDidReceiveRequestForCommissionableData:(id)sender +{ + ChipLogProgress(AppServer, "DataSourceCompat::castingAppDidReceiveRequestForCommissionableData called"); + if (self.appParameters != nil) { + return [[MCCommissionableData alloc] initWithPasscode:self.appParameters.onboardingPayload.setupPasscode discriminator:self.appParameters.onboardingPayload.setupDiscriminator spake2pIterationCount:self.appParameters.spake2pIterationCount spake2pVerifier:self.appParameters.spake2pVerifierBase64 spake2pSalt:self.appParameters.spake2pSaltBase64]; + } + return nil; +} + +- (MCDeviceAttestationCredentials *)castingAppDidReceiveRequestForDeviceAttestationCredentials:(id)sender +{ + ChipLogProgress(AppServer, "DataSourceCompat::castingAppDidReceiveRequestForDeviceAttestationCredentials called"); + if (self.dacHolder != nil) { + return [[MCDeviceAttestationCredentials alloc] initWithCertificationDeclaration:[self.dacHolder getCertificationDeclaration] firmwareInformation:[self.dacHolder getFirmwareInformation] deviceAttestationCert:[self.dacHolder getDeviceAttestationCert] productAttestationIntermediateCert:[self.dacHolder getProductAttestationIntermediateCert]]; + } + return nil; +} + +- (MatterError *)castingApp:(id)sender didReceiveRequestToSignCertificateRequest:(NSData *)csrData outRawSignature:(NSData * _Nonnull * _Nonnull)outRawSignature +{ + ChipLogProgress(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest called"); + if (self.dacHolder != nil) { + // Get the private SecKey from dacHolder + SecKeyRef privateSecKey = [self.dacHolder getDeviceAttestationCertPrivateKeyRef]; + if (privateSecKey == nil) { + ChipLogError(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest No privateSecKey found"); + return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT]; + } + + // Sign csrData to get asn1SignatureData + CFErrorRef error = nil; + CFDataRef asn1SignatureData = SecKeyCreateSignature(privateSecKey, kSecKeyAlgorithmECDSASignatureMessageX962SHA256, (__bridge CFDataRef) csrData, &error); + if (error != nil) { + ChipLogError(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest failed to sign message, err: %@", error); + return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT]; + } + if (asn1SignatureData == nil) { + ChipLogError(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest failed to sign message, asn1SignatureData is nil"); + return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT]; + } + + // Convert ASN.1 DER signature to SEC1 raw format + return [MCCryptoUtils ecdsaAsn1SignatureToRawWithFeLengthBytes:32 asn1Signature:asn1SignatureData + outRawSignature:outRawSignature]; + } + + return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]; +} +@end diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsHolder.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DeviceAttestationCredentialsHolder.h similarity index 94% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsHolder.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DeviceAttestationCredentialsHolder.h index 44d4dee2169c43..8140d2abeaed42 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsHolder.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DeviceAttestationCredentialsHolder.h @@ -21,6 +21,7 @@ #ifndef DeviceAttestationCredentialsHolder_h #define DeviceAttestationCredentialsHolder_h +__attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) @interface DeviceAttestationCredentialsHolder : NSObject - (DeviceAttestationCredentialsHolder * _Nonnull) diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsHolder.m b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DeviceAttestationCredentialsHolder.m similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DeviceAttestationCredentialsHolder.m rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DeviceAttestationCredentialsHolder.m diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DiscoveredNodeData.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DiscoveredNodeData.h similarity index 86% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DiscoveredNodeData.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DiscoveredNodeData.h index f4cf95f4be7e6a..93687bbfa0d703 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DiscoveredNodeData.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DiscoveredNodeData.h @@ -17,11 +17,13 @@ #import +#import "../MCCastingPlayer.h" #import "VideoPlayer.h" #ifndef DiscoveredNodeData_h #define DiscoveredNodeData_h +__attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) @interface DiscoveredNodeData : NSObject @property NSString * deviceName; @@ -56,12 +58,16 @@ - (DiscoveredNodeData *)initWithDeviceName:(NSString *)deviceName vendorId:(uint16_t)vendorId productId:(uint16_t)productId; +- (instancetype)initWithCastingPlayer:(MCCastingPlayer *)castingPlayer; + - (bool)isPreCommissioned; - (VideoPlayer *)getConnectableVideoPlayer; - (void)setConnectableVideoPlayer:(VideoPlayer *)videoPlayer; +- (MCCastingPlayer *)getCastingPlayer; + @end #endif /* DiscoveredNodeData_h */ diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DiscoveredNodeData.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DiscoveredNodeData.mm similarity index 62% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DiscoveredNodeData.mm rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DiscoveredNodeData.mm index f8c85e52269dbb..3d9a4b19498dab 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/DiscoveredNodeData.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DiscoveredNodeData.mm @@ -18,12 +18,16 @@ #import #import "DiscoveredNodeData.h" +#import "VideoPlayer.h" + #include @interface DiscoveredNodeData () @property (nonatomic) VideoPlayer * connectableVideoPlayer; +@property (nonatomic) MCCastingPlayer * castingPlayer; + @end @implementation DiscoveredNodeData @@ -39,14 +43,27 @@ - (DiscoveredNodeData *)initWithDeviceName:(NSString *)deviceName vendorId:(uint return self; } -- (NSString *)description +- (instancetype)initWithCastingPlayer:(MCCastingPlayer *)castingPlayer { - if ([self isPreCommissioned]) { - return [NSString - stringWithFormat:@"%@ with Product ID: %d and Vendor ID: %d [Pre-Commissioned]", _deviceName, _productId, _vendorId]; - } else { - return [NSString stringWithFormat:@"%@ with Product ID: %d and Vendor ID: %d", _deviceName, _productId, _vendorId]; + self = [super init]; + if (self) { + _castingPlayer = castingPlayer; + _deviceType = castingPlayer.deviceType; + _vendorId = castingPlayer.vendorId; + _productId = castingPlayer.productId; + _deviceName = castingPlayer.deviceName; + _instanceName = castingPlayer.instanceName; + _hostName = castingPlayer.hostName; + _numIPs = castingPlayer.ipAddresses.count; + _ipAddresses = [castingPlayer.ipAddresses mutableCopy]; + _connectableVideoPlayer = [[VideoPlayer alloc] initWithCastingPlayer:castingPlayer]; } + return self; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:@"%@ with Product ID: %d and Vendor ID: %d", _deviceName, _productId, _vendorId]; } - (BOOL)isEqualToDiscoveredNodeData:(DiscoveredNodeData *)other @@ -88,7 +105,10 @@ - (void)setConnectableVideoPlayer:(VideoPlayer * _Nonnull)videoPlayer - (bool)isPreCommissioned { - return _connectableVideoPlayer != nil; + // Returning false will make the compat shim call the openBasicCommissioningWindow API every time. + // The shim will internally handle selecting the commissioning path or simply re-establish + // CASE (if the player nodeId/fabricIndex were found in the cache) + return false; } - (VideoPlayer *)getConnectableVideoPlayer @@ -96,4 +116,9 @@ - (VideoPlayer *)getConnectableVideoPlayer return _connectableVideoPlayer; } +- (MCCastingPlayer *)getCastingPlayer +{ + return _castingPlayer; +} + @end diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MediaPlaybackTypes.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/MediaPlaybackTypes.h similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MediaPlaybackTypes.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/MediaPlaybackTypes.h diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MediaPlaybackTypes.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/MediaPlaybackTypes.mm similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MediaPlaybackTypes.mm rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/MediaPlaybackTypes.mm diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/OnboardingPayload.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/OnboardingPayload.h similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/OnboardingPayload.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/OnboardingPayload.h diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/OnboardingPayload.m b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/OnboardingPayload.m similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/OnboardingPayload.m rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/OnboardingPayload.m diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/TargetNavigatorTypes.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/TargetNavigatorTypes.h similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/TargetNavigatorTypes.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/TargetNavigatorTypes.h diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/TargetNavigatorTypes.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/TargetNavigatorTypes.mm similarity index 100% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/TargetNavigatorTypes.mm rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/TargetNavigatorTypes.mm diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/VideoPlayer.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.h similarity index 89% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/VideoPlayer.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.h index 1496ff9b180d1c..fe543809dafd7b 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/VideoPlayer.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.h @@ -15,9 +15,12 @@ * limitations under the License. */ +#import "../MCCastingPlayer.h" + #ifndef VideoPlayer_h #define VideoPlayer_h +__attribute__((deprecated("Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) @interface VideoPlayer : NSObject @property uint64_t nodeId; @@ -73,6 +76,10 @@ MACAddress:(NSString *)MACAddress lastDiscoveredMs:(uint64_t)lastDiscoveredMs; +- (instancetype)initWithCastingPlayer:(MCCastingPlayer *)castingPlayer; + +- (MCCastingPlayer *)getCastingPlayer; + @end #endif /* VideoPlayer_h */ diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/VideoPlayer.m b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.m similarity index 70% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/VideoPlayer.m rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.m index ef3a3d23f76c65..a0470bbf14a8bf 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/VideoPlayer.m +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.m @@ -17,8 +17,15 @@ #import +#import "ContentApp.h" #import "VideoPlayer.h" +@interface VideoPlayer () + +@property (nonatomic) MCCastingPlayer * castingPlayer; + +@end + @implementation VideoPlayer - (instancetype)init @@ -63,8 +70,33 @@ - (instancetype)initWithNodeId:(uint64_t)nodeId return self; } +- (instancetype)initWithCastingPlayer:(MCCastingPlayer *)castingPlayer +{ + if (self = [super init]) { + _castingPlayer = castingPlayer; + _deviceName = castingPlayer.deviceName; + _vendorId = castingPlayer.vendorId; + _productId = castingPlayer.productId; + _deviceType = castingPlayer.deviceType; + _hostName = castingPlayer.hostName; + _instanceName = castingPlayer.instanceName; + _contentApps = [NSMutableArray new]; + NSArray * endpoints = castingPlayer.endpoints; + for (MCEndpoint * endpoint in endpoints) { + [_contentApps addObject:[[ContentApp alloc] initWithEndpoint:endpoint]]; + } + _isInitialized = true; + } + return self; +} + - (NSString *)description { return [NSString stringWithFormat:@"%@ with Product ID: %d, Vendor ID: %d", _deviceName, _productId, _vendorId]; } + +- (MCCastingPlayer *)getCastingPlayer +{ + return _castingPlayer; +} @end diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpointClusterType.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/zap-generated/MCEndpointClusterType.h similarity index 82% rename from examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpointClusterType.h rename to examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/zap-generated/MCEndpointClusterType.h index 7137dd1ed96042..d60f980f66a1c7 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpointClusterType.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/zap-generated/MCEndpointClusterType.h @@ -21,8 +21,12 @@ typedef enum _MCEndpointClusterType { MCEndpointClusterTypeApplicationBasic, + MCEndpointClusterTypeApplicationLauncher, MCEndpointClusterTypeContentLauncher, - MCEndpointClusterTypeMediaPlayback + MCEndpointClusterTypeKeypadInput, + MCEndpointClusterTypeMediaPlayback, + MCEndpointClusterTypeOnOff, + MCEndpointClusterTypeTargetNavigator } MCEndpointClusterType; #endif /* MCEndpointClusterType_h */ diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting.xcodeproj/project.pbxproj b/examples/tv-casting-app/darwin/TvCasting/TvCasting.xcodeproj/project.pbxproj index e48185f4c9d64c..2d4a142cd515a5 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting.xcodeproj/project.pbxproj +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting.xcodeproj/project.pbxproj @@ -15,10 +15,6 @@ 3C621CB32B6078B7005CDBA3 /* MCApplicationBasicReadVendorIDExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C621CB22B6078B7005CDBA3 /* MCApplicationBasicReadVendorIDExampleViewModel.swift */; }; 3C621CB52B607FFD005CDBA3 /* MCActionSelectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C621CB42B607FFD005CDBA3 /* MCActionSelectorView.swift */; }; 3C69204A2AA1368F00D0F613 /* MCInitializationExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C6920492AA1368F00D0F613 /* MCInitializationExample.swift */; }; - 3C81C75328F8C79E001CB9D1 /* StartFromCacheView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C81C75228F8C79E001CB9D1 /* StartFromCacheView.swift */; }; - 3C81C75528F8C7B6001CB9D1 /* StartFromCacheViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C81C75428F8C7B6001CB9D1 /* StartFromCacheViewModel.swift */; }; - 3C81C75728F8E418001CB9D1 /* ConnectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C81C75628F8E418001CB9D1 /* ConnectionView.swift */; }; - 3C81C75928F8E42D001CB9D1 /* ConnectionViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C81C75828F8E42D001CB9D1 /* ConnectionViewModel.swift */; }; 3C94377D2B364D380096E5F4 /* MCDiscoveryExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C94377C2B364D380096E5F4 /* MCDiscoveryExampleViewModel.swift */; }; 3C94377F2B364D510096E5F4 /* MCConnectionExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C94377E2B364D510096E5F4 /* MCConnectionExampleViewModel.swift */; }; 3C94378E2B3B3CB00096E5F4 /* MCDiscoveryExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C94378D2B3B3CB00096E5F4 /* MCDiscoveryExampleView.swift */; }; @@ -71,10 +67,6 @@ 3C7507AE28529A5F00D7DB3A /* CommissioningView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommissioningView.swift; sourceTree = ""; }; 3C7507B62853A3AD00D7DB3A /* CommissionerDiscoveryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommissionerDiscoveryViewModel.swift; sourceTree = ""; }; 3C7507B82853EFF000D7DB3A /* CommissioningViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommissioningViewModel.swift; sourceTree = ""; }; - 3C81C75228F8C79E001CB9D1 /* StartFromCacheView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartFromCacheView.swift; sourceTree = ""; }; - 3C81C75428F8C7B6001CB9D1 /* StartFromCacheViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StartFromCacheViewModel.swift; sourceTree = ""; }; - 3C81C75628F8E418001CB9D1 /* ConnectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionView.swift; sourceTree = ""; }; - 3C81C75828F8E42D001CB9D1 /* ConnectionViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionViewModel.swift; sourceTree = ""; }; 3C94377C2B364D380096E5F4 /* MCDiscoveryExampleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCDiscoveryExampleViewModel.swift; sourceTree = ""; }; 3C94377E2B364D510096E5F4 /* MCConnectionExampleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCConnectionExampleViewModel.swift; sourceTree = ""; }; 3C94378D2B3B3CB00096E5F4 /* MCDiscoveryExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCDiscoveryExampleView.swift; sourceTree = ""; }; @@ -108,6 +100,25 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 3C996C2C2BD9C2B40027BD8A /* compat */ = { + isa = PBXGroup; + children = ( + 3C7507AC285299DF00D7DB3A /* CommissionerDiscoveryView.swift */, + 3C7507B62853A3AD00D7DB3A /* CommissionerDiscoveryViewModel.swift */, + 3C7507AE28529A5F00D7DB3A /* CommissioningView.swift */, + 3C7507B82853EFF000D7DB3A /* CommissioningViewModel.swift */, + 3CA1CA7928E281080023ED44 /* ClusterSelectorView.swift */, + 3CA19434285BA780004768D5 /* ContentLauncherView.swift */, + 3CA19436285BA877004768D5 /* ContentLauncherViewModel.swift */, + 3CA1CA7B28E282150023ED44 /* MediaPlaybackView.swift */, + 3CA1CA7D28E284950023ED44 /* MediaPlaybackViewModel.swift */, + EAF14298296D561900E17793 /* CertTestView.swift */, + EAF1429A296D57DF00E17793 /* CertTestViewModel.swift */, + 3CAC955A29BA948700BEA5C3 /* ExampleDAC.swift */, + ); + path = compat; + sourceTree = ""; + }; 3C9ACC02284ABBD600718B2D /* Frameworks */ = { isa = PBXGroup; children = ( @@ -137,9 +148,11 @@ 3CC0E8F82841DD3400EC6A18 /* TvCasting */ = { isa = PBXGroup; children = ( + 3C996C2C2BD9C2B40027BD8A /* compat */, 3CC0E8FD2841DD3500EC6A18 /* Assets.xcassets */, 3C75075E284C1DF800D7DB3A /* TvCasting.entitlements */, 3CC0E8F92841DD3400EC6A18 /* TvCastingApp.swift */, + 3CC0E8FB2841DD3400EC6A18 /* ContentView.swift */, 3C6920492AA1368F00D0F613 /* MCInitializationExample.swift */, 3C94378D2B3B3CB00096E5F4 /* MCDiscoveryExampleView.swift */, 3C94377C2B364D380096E5F4 /* MCDiscoveryExampleViewModel.swift */, @@ -152,23 +165,6 @@ 3C621CB22B6078B7005CDBA3 /* MCApplicationBasicReadVendorIDExampleViewModel.swift */, 3C40586D2B632DC500C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleView.swift */, 3C40586F2B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift */, - EAF14298296D561900E17793 /* CertTestView.swift */, - EAF1429A296D57DF00E17793 /* CertTestViewModel.swift */, - 3CC0E8FB2841DD3400EC6A18 /* ContentView.swift */, - 3C81C75228F8C79E001CB9D1 /* StartFromCacheView.swift */, - 3C81C75428F8C7B6001CB9D1 /* StartFromCacheViewModel.swift */, - 3C81C75628F8E418001CB9D1 /* ConnectionView.swift */, - 3C81C75828F8E42D001CB9D1 /* ConnectionViewModel.swift */, - 3C7507AC285299DF00D7DB3A /* CommissionerDiscoveryView.swift */, - 3C7507B62853A3AD00D7DB3A /* CommissionerDiscoveryViewModel.swift */, - 3C7507AE28529A5F00D7DB3A /* CommissioningView.swift */, - 3C7507B82853EFF000D7DB3A /* CommissioningViewModel.swift */, - 3CAC955A29BA948700BEA5C3 /* ExampleDAC.swift */, - 3CA1CA7928E281080023ED44 /* ClusterSelectorView.swift */, - 3CA19434285BA780004768D5 /* ContentLauncherView.swift */, - 3CA19436285BA877004768D5 /* ContentLauncherViewModel.swift */, - 3CA1CA7B28E282150023ED44 /* MediaPlaybackView.swift */, - 3CA1CA7D28E284950023ED44 /* MediaPlaybackViewModel.swift */, 3CC0E8FF2841DD3500EC6A18 /* Preview Content */, ); path = TvCasting; @@ -267,17 +263,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 3C81C75328F8C79E001CB9D1 /* StartFromCacheView.swift in Sources */, 3C94377F2B364D510096E5F4 /* MCConnectionExampleViewModel.swift in Sources */, 3C4058702B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift in Sources */, - 3C81C75528F8C7B6001CB9D1 /* StartFromCacheViewModel.swift in Sources */, 3CCB8745286A5D0F00771BAD /* CommissionerDiscoveryView.swift in Sources */, 3C621CB12B6078A9005CDBA3 /* MCApplicationBasicReadVendorIDExampleView.swift in Sources */, 3CCB8746286A5D0F00771BAD /* CommissionerDiscoveryViewModel.swift in Sources */, 3C4F52302B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift in Sources */, 3C621CB32B6078B7005CDBA3 /* MCApplicationBasicReadVendorIDExampleViewModel.swift in Sources */, 3C621CB52B607FFD005CDBA3 /* MCActionSelectorView.swift in Sources */, - 3C81C75928F8E42D001CB9D1 /* ConnectionViewModel.swift in Sources */, 3CA1CA7A28E281080023ED44 /* ClusterSelectorView.swift in Sources */, 3C94378E2B3B3CB00096E5F4 /* MCDiscoveryExampleView.swift in Sources */, EAF14299296D561900E17793 /* CertTestView.swift in Sources */, @@ -291,7 +284,6 @@ 3CCB8749286A5D0F00771BAD /* ContentLauncherView.swift in Sources */, 3CCB874A286A5D0F00771BAD /* ContentLauncherViewModel.swift in Sources */, EAF1429B296D57DF00E17793 /* CertTestViewModel.swift in Sources */, - 3C81C75728F8E418001CB9D1 /* ConnectionView.swift in Sources */, 3CC0E8FC2841DD3400EC6A18 /* ContentView.swift in Sources */, 3CA1CA7C28E282150023ED44 /* MediaPlaybackView.swift in Sources */, 3CC0E8FA2841DD3400EC6A18 /* TvCastingApp.swift in Sources */, diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissioningViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissioningViewModel.swift deleted file mode 100644 index ec0c542d942e38..00000000000000 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissioningViewModel.swift +++ /dev/null @@ -1,118 +0,0 @@ -/** - * - * Copyright (c) 2020-2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import Foundation -import os.log - -class CommissioningViewModel: ObservableObject { - let Log = Logger(subsystem: "com.matter.casting", - category: "CommissioningViewModel") - - @Published var udcRequestSent: Bool?; - - @Published var commisisoningWindowOpened: Bool?; - - @Published var commisisoningComplete: Bool?; - - @Published var connectionSuccess: Bool?; - - @Published var connectionStatus: String?; - - func prepareForCommissioning(selectedCommissioner: DiscoveredNodeData?) { - if let castingServerBridge = CastingServerBridge.getSharedInstance() - { - castingServerBridge.setDacHolder(ExampleDAC(), clientQueue: DispatchQueue.main, setDacHolderStatus: { (error: MatterError) -> () in - DispatchQueue.main.async { - self.Log.info("CommissioningViewModel.setDacHolder status was \(error)") - if(error.code == 0) - { - self.openBasicCommissioningWindow() - } - } - }) - } - - // Send User directed commissioning request if a commissioner with a known IP addr was selected - if(selectedCommissioner != nil && selectedCommissioner!.numIPs > 0) - { - sendUserDirectedCommissioningRequest(selectedCommissioner: selectedCommissioner) - } - } - - private func openBasicCommissioningWindow() { - if let castingServerBridge = CastingServerBridge.getSharedInstance() - { - castingServerBridge.openBasicCommissioningWindow(DispatchQueue.main, - commissioningCallbackHandlers: CommissioningCallbackHandlers( - commissioningWindowRequestedHandler: { (result: Bool) -> () in - DispatchQueue.main.async { - self.Log.info("Commissioning Window opening status: \(result)") - self.commisisoningWindowOpened = result - } - }, - commissioningCompleteCallback: { (result: Bool) -> () in - self.Log.info("Commissioning status: \(result)") - DispatchQueue.main.async { - self.commisisoningComplete = result - } - }, - sessionEstablishmentStartedCallback: { - self.Log.info("PASE session establishment started") - }, - sessionEstablishedCallback: { - self.Log.info("PASE session established") - }, - sessionEstablishmentErrorCallback: { (err: MatterError) -> () in - self.Log.info("PASE session establishment error : \(err)") - }, - sessionEstablishmentStoppedCallback: { - self.Log.info("PASE session establishment stopped") - } - ), - onConnectionSuccessCallback: { (videoPlayer: VideoPlayer) -> () in - DispatchQueue.main.async { - self.connectionSuccess = true - self.connectionStatus = "Connected to \(String(describing: videoPlayer))" - self.Log.info("CommissioningViewModel.verifyOrEstablishConnection.onConnectionSuccessCallback called with \(videoPlayer.nodeId)") - } - }, - onConnectionFailureCallback: { (error: MatterError) -> () in - DispatchQueue.main.async { - self.connectionSuccess = false - self.connectionStatus = "Failed to connect to video player!" - self.Log.info("CommissioningViewModel.verifyOrEstablishConnection.onConnectionFailureCallback called with \(error)") - } - }, - onNewOrUpdatedEndpointCallback: { (contentApp: ContentApp) -> () in - DispatchQueue.main.async { - self.Log.info("CommissioningViewModel.openBasicCommissioningWindow.onNewOrUpdatedEndpointCallback called with \(contentApp.endpointId)") - } - }) - } - - } - - private func sendUserDirectedCommissioningRequest(selectedCommissioner: DiscoveredNodeData?) { - if let castingServerBridge = CastingServerBridge.getSharedInstance() - { - castingServerBridge.sendUserDirectedCommissioningRequest(selectedCommissioner!, clientQueue: DispatchQueue.main, udcRequestSentHandler: { (result: Bool) -> () in - self.udcRequestSent = result - }) - } - } -} diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ConnectionView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/ConnectionView.swift deleted file mode 100644 index c7bfacc6cca49e..00000000000000 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ConnectionView.swift +++ /dev/null @@ -1,78 +0,0 @@ -/** - * - * Copyright (c) 2020-2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import SwiftUI - -struct ConnectionView: View { - var selectedVideoPlayer: VideoPlayer? - - @StateObject var viewModel = ConnectionViewModel(); - - init(_selectedVideoPlayer: VideoPlayer?) { - self.selectedVideoPlayer = _selectedVideoPlayer - } - - var body: some View { - VStack(alignment: .leading) { - if let requestSent = viewModel.requestSent { - if(requestSent) - { - Text("Sent request to verify or connect to video player").padding() - } - else - { - Text("Failed in sending request to verify or connect to video player!").foregroundColor(Color.red).padding() - } - - if let connectionSuccess = viewModel.connectionSuccess - { - if let connectionStatus = viewModel.connectionStatus - { - Text(connectionStatus).padding() - } - - if(connectionSuccess) - { - NavigationLink( - destination: ClusterSelectorView(), - label: { - Text("Next") - .frame(width: 100, height: 30, alignment: .center) - .border(Color.black, width: 1) - } - ).background(Color.blue) - .foregroundColor(Color.white) - .frame(maxHeight: .infinity, alignment: .bottom) - .padding() - } - } - } - } - .navigationTitle("Connecting...") - .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .top) - .onAppear(perform: { - viewModel.verifyOrEstablishConnection(selectedVideoPlayer: self.selectedVideoPlayer) - }) - } -} - -struct ConnectionView_Previews: PreviewProvider { - static var previews: some View { - ConnectionView(_selectedVideoPlayer: nil) - } -} diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ConnectionViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/ConnectionViewModel.swift deleted file mode 100644 index 2d97a47ab3966c..00000000000000 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ConnectionViewModel.swift +++ /dev/null @@ -1,63 +0,0 @@ -/** - * - * Copyright (c) 2020-2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -import Foundation -import os.log - -class ConnectionViewModel: ObservableObject { - let Log = Logger(subsystem: "com.matter.casting", - category: "ConnectionViewModel") - - @Published var requestSent: Bool?; - - @Published var connectionSuccess: Bool?; - - @Published var connectionStatus: String?; - - func verifyOrEstablishConnection(selectedVideoPlayer: VideoPlayer?) { - if let castingServerBridge = CastingServerBridge.getSharedInstance() - { - castingServerBridge.verifyOrEstablishConnection(selectedVideoPlayer!, clientQueue: DispatchQueue.main, - requestSentHandler: { (error: MatterError) -> () in - DispatchQueue.main.async { - self.requestSent = (error.code == 0) - self.Log.info("ConnectionViewModel.verifyOrEstablishConnection.requestSentHandler called with \(error)") - } - }, - onConnectionSuccessCallback: { (videoPlayer: VideoPlayer) -> () in - DispatchQueue.main.async { - self.connectionSuccess = true - self.connectionStatus = "Connected to \(String(describing: videoPlayer))" - self.Log.info("ConnectionViewModel.verifyOrEstablishConnection.onConnectionSuccessCallback called with \(videoPlayer.nodeId)") - } - }, - onConnectionFailureCallback: { (error: MatterError) -> () in - DispatchQueue.main.async { - self.connectionSuccess = false - self.connectionStatus = "Failed to connect to video player!" - self.Log.info("ConnectionViewModel.verifyOrEstablishConnection.onConnectionFailureCallback called with \(error)") - } - }, - onNewOrUpdatedEndpointCallback: { (contentApp: ContentApp) -> () in - DispatchQueue.main.async { - self.Log.info("ConnectionViewModel.verifyOrEstablishConnection.onNewOrUpdatedEndpointCallback called with \(contentApp.endpointId)") - } - }) - } - } -} diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentView.swift index 701fada1fe62d9..afc1207e63dd00 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentView.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentView.swift @@ -26,7 +26,7 @@ struct ContentView: View { } else { - StartFromCacheView() + CommissionerDiscoveryView() } } } diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift index 5d30f096052a84..e7d3581dd07350 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift @@ -61,8 +61,7 @@ class MCMediaPlaybackSubscribeToCurrentStateExampleViewModel: ObservableObject { // call read on currentStateAttribute and pass in a completion block - currentStateAttribute!.read(nil) { context, before, after, err in - + currentStateAttribute!.subscribe(nil, completion: { context, before, after, err in let dateFormatter = DateFormatter() dateFormatter.dateFormat = "HH:mm:ss" let currentTime = dateFormatter.string(from: Date()) @@ -85,7 +84,7 @@ class MCMediaPlaybackSubscribeToCurrentStateExampleViewModel: ObservableObject { self.status = "Read CurrentState value: \(String(describing: after)) at \(currentTime)" } } - } + }, minInterval: 0, maxInterval: 1) } else { diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/StartFromCacheView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/StartFromCacheView.swift deleted file mode 100644 index 0d2bad3e29ba1f..00000000000000 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/StartFromCacheView.swift +++ /dev/null @@ -1,83 +0,0 @@ -/** - * - * Copyright (c) 2020-2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import SwiftUI - -extension VideoPlayer : Identifiable { - public var id: String { - deviceName - } -} - -struct StartFromCacheView: View { - @StateObject var viewModel = StartFromCacheViewModel() - - var body: some View { - VStack(alignment: .leading) { - Button("Purge cache", action: { - viewModel.purgeAndReReadCache() - }) - .frame(width: 200, height: 30, alignment: .center) - .border(Color.black, width: 1) - .background(Color.blue) - .foregroundColor(Color.white) - .padding() - - NavigationLink( - destination: CommissionerDiscoveryView(), - label: { - Text("Skip to commissioner discovery >>") - .frame(width: 300, height: 30, alignment: .center) - .border(Color.black, width: 1) - } - ).background(Color.blue) - .foregroundColor(Color.white) - .padding() - - if(viewModel.videoPlayers.isEmpty) - { - Text("No cached video players.") - } - else - { - Text("Pick a Video player") - ForEach(viewModel.videoPlayers) { videoPlayer in - NavigationLink( - destination: ConnectionView(_selectedVideoPlayer: videoPlayer), - label: { - Text(videoPlayer.description) - } - ) - .frame(width: 350, height: 50, alignment: .center) - .border(Color.black, width: 1) - .background(Color.blue) - .foregroundColor(Color.white) - .padding(1) - } - } - } - .navigationTitle("Starting from Cache") - .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .top) - .onAppear(perform: {viewModel.readFromCache()}) - } -} - -struct StartFromCacheView_Previews: PreviewProvider { - static var previews: some View { - StartFromCacheView() - } -} diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/StartFromCacheViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/StartFromCacheViewModel.swift deleted file mode 100644 index 3b12b5fa3c867f..00000000000000 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/StartFromCacheViewModel.swift +++ /dev/null @@ -1,50 +0,0 @@ -/** - * - * Copyright (c) 2020-2022 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import Foundation -import os.log - -class StartFromCacheViewModel: ObservableObject { - let Log = Logger(subsystem: "com.matter.casting", - category: "StartFromCacheViewModel") - - @Published var videoPlayers: [VideoPlayer] = [] - - func readFromCache() { - if let castingServerBridge = CastingServerBridge.getSharedInstance() - { - castingServerBridge.readCachedVideoPlayers(DispatchQueue.main, readCachedVideoPlayersHandler: { (cachedVideoPlayers: NSMutableArray?) -> () in - if(cachedVideoPlayers != nil) - { - self.videoPlayers = cachedVideoPlayers! as! [VideoPlayer] - } - }) - } - } - - func purgeAndReReadCache() { - if let castingServerBridge = CastingServerBridge.getSharedInstance() - { - castingServerBridge.purgeCache(DispatchQueue.main, responseHandler: { (error: MatterError) -> () in - DispatchQueue.main.async { - self.Log.info("purgeCache returned \(error)") - self.readFromCache() - } - }) - } - } -} diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/TvCastingApp.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/TvCastingApp.swift index d6949900f43202..ce31f4f79446ce 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/TvCastingApp.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/TvCastingApp.swift @@ -61,7 +61,7 @@ struct TvCastingApp: App { appParameters.onboardingPayload = onboardingParameters - let err = castingServerBridge.initializeApp(appParameters, clientQueue: DispatchQueue.main, initAppStatusHandler: { (result: Bool) -> () in + let err = castingServerBridge.initializeApp(appParameters, clientQueue: DispatchQueue.main, initAppStatusHandler: { (result: MatterError) -> () in self.Log.info("initializeApp result \(result)") }) self.Log.info("initializeApp return value \(err)") diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CertTestView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CertTestView.swift similarity index 100% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/CertTestView.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CertTestView.swift diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CertTestViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CertTestViewModel.swift similarity index 98% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/CertTestViewModel.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CertTestViewModel.swift index 7975f80604ac50..cb7f6b2f7bc489 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CertTestViewModel.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CertTestViewModel.swift @@ -28,20 +28,20 @@ private class CallbackHelper { self.certTestViewModel = certTestViewModel } - func responseCallback(succeeded: Bool) + func responseCallback(err: MatterError) { - logger.info("CertTestViewModel.responseCallback.\(self.testCaseName) succeeded? \(succeeded)") - if (succeeded) { + logger.info("CertTestViewModel.responseCallback.\(self.testCaseName) err? \(err)") + if (err == MATTER_NO_ERROR) { certTestViewModel.onTestPassed(testCaseName) } else { certTestViewModel.onTestFailed(testCaseName) } } - func requestSentHandler(succeeded: Bool) + func requestSentHandler(err: MatterError) { - logger.info("CertTestViewModel.requestSentHandler.\(self.testCaseName) succeeded? \(succeeded)") - if (!succeeded) { + logger.info("CertTestViewModel.requestSentHandler.\(self.testCaseName) err? \(err)") + if (err != MATTER_NO_ERROR) { certTestViewModel.onTestFailed(testCaseName) } } @@ -49,7 +49,7 @@ private class CallbackHelper { func requestSentHandlerError(result: MatterError) { logger.warning("CertTestViewModel.requestSentHandler.\(self.testCaseName). Code : \(result.code). Message : \(result.message ?? "")") - requestSentHandler(succeeded: result.code == 0) + requestSentHandler(err: result) } func successCallbackString(result: String) diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ClusterSelectorView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ClusterSelectorView.swift similarity index 97% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/ClusterSelectorView.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ClusterSelectorView.swift index 9dbc9f16d84fa6..308f26f03fa433 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ClusterSelectorView.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ClusterSelectorView.swift @@ -17,6 +17,7 @@ import SwiftUI +@available(*, deprecated, message: "Refer to MCActionSelectorView") struct ClusterSelectorView: View { var body: some View { VStack(alignment: .leading) { diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissionerDiscoveryView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissionerDiscoveryView.swift similarity index 82% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissionerDiscoveryView.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissionerDiscoveryView.swift index 7a33fc7b19e271..84928b2aab015a 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissionerDiscoveryView.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissionerDiscoveryView.swift @@ -23,22 +23,12 @@ extension DiscoveredNodeData : Identifiable { } } +@available(*, deprecated, message: "Refer to MCDiscoveryExampleView") struct CommissionerDiscoveryView: View { @StateObject var viewModel = CommissionerDiscoveryViewModel() var body: some View { VStack(alignment: .leading) { - NavigationLink( - destination: CommissioningView(_selectedCommissioner: nil), - label: { - Text("Skip to manual commissioning >>") - .frame(width: 300, height: 30, alignment: .center) - .border(Color.black, width: 1) - } - ).background(Color.blue) - .foregroundColor(Color.white) - .padding() - Button("Discover commissioners", action: viewModel.discoverAndUpdate) .frame(width: 200, height: 30, alignment: .center) .border(Color.black, width: 1) @@ -58,7 +48,7 @@ struct CommissionerDiscoveryView: View { destination: { if(commissioner.isPreCommissioned()) { - ConnectionView(_selectedVideoPlayer: commissioner.getConnectableVideoPlayer()) + Text("Error: unexpected value for commissioner.isPreCommissioned: true") } else { diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissionerDiscoveryViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissionerDiscoveryViewModel.swift similarity index 57% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissionerDiscoveryViewModel.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissionerDiscoveryViewModel.swift index 3bc7492de10dac..02ee32e54a34c9 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissionerDiscoveryViewModel.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissionerDiscoveryViewModel.swift @@ -30,14 +30,14 @@ class CommissionerDiscoveryViewModel: ObservableObject { if let castingServerBridge = CastingServerBridge.getSharedInstance() { castingServerBridge.discoverCommissioners(DispatchQueue.main, - discoveryRequestSentHandler: { (result: Bool) -> () in - self.discoveryRequestStatus = result + discoveryRequestSentHandler: { (result: MatterError) -> () in + self.discoveryRequestStatus = (result == MATTER_NO_ERROR) }, discoveredCommissionerHandler: { (commissioner: DiscoveredNodeData) -> () in self.Log.info("discoveredCommissionerHandler called with \(commissioner)") if(self.commissioners.contains(commissioner)) { - var index = self.commissioners.firstIndex(of: commissioner) + let index = self.commissioners.firstIndex(of: commissioner) self.commissioners[index!] = commissioner self.Log.info("Updating previously discovered commissioner \(commissioner.description)") } @@ -52,37 +52,5 @@ class CommissionerDiscoveryViewModel: ObservableObject { } ) } - - /* Deprecated usage - Task { - try? await Task.sleep(nanoseconds: 5_000_000_000) // Wait for commissioners to respond - updateCommissioners() - }*/ - } - - private func updateCommissioners() { - if let castingServerBridge = CastingServerBridge.getSharedInstance() - { - var i: Int32 = 0 - var commissioner: DiscoveredNodeData?; - repeat { - castingServerBridge.getDiscoveredCommissioner(i, clientQueue: DispatchQueue.main, discoveredCommissionerHandler: { (result: DiscoveredNodeData?) -> () in - commissioner = result; - if(commissioner != nil){ - if(self.commissioners.contains(commissioner!)) - { - var index = self.commissioners.firstIndex(of: commissioner!) - self.commissioners[index!] = commissioner! - self.Log.info("Updating previously discovered commissioner \(commissioner!.description)") - } - else - { - self.commissioners.append(commissioner!) - } - } - }) - i += 1 - } while(commissioner != nil) - } } } diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissioningView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningView.swift similarity index 78% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissioningView.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningView.swift index 923d986ce6d6d5..fc49e3e0bff8dd 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/CommissioningView.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningView.swift @@ -18,6 +18,7 @@ import SwiftUI +@available(*, deprecated, message: "Refer to MCConnectionExampleView") struct CommissioningView: View { var selectedCommissioner: DiscoveredNodeData? @@ -30,30 +31,24 @@ struct CommissioningView: View { var body: some View { VStack(alignment: .leading) { if(viewModel.commisisoningWindowOpened == true) { - Text("Commissioning window opened.").padding() + Text("Onboarding payload for Commissioning if needed:").padding() - Text("Onboarding PIN: " + String((CastingServerBridge.getSharedInstance()?.getOnboardingPayload().setupPasscode)!)) + Text("Passcode: " + String((CastingServerBridge.getSharedInstance()?.getOnboardingPayload().setupPasscode)!)) .border(Color.blue, width: 1) .padding() Text("Discriminator: " + String((CastingServerBridge.getSharedInstance()?.getOnboardingPayload().setupDiscriminator)!)) .border(Color.blue, width: 1) .padding() - if(self.selectedCommissioner != nil) + if(viewModel.udcRequestSent == true) { - if(viewModel.udcRequestSent == true) - { - Text("Complete commissioning on " + (selectedCommissioner?.deviceName)!) - .padding() - } - else if(viewModel.udcRequestSent == false) { - Text("Could not send user directed commissioning request to " + (selectedCommissioner?.deviceName)! + "! Complete commissioning manually!") - .foregroundColor(Color.red) - .padding() - } + Text("Complete commissioning on " + (selectedCommissioner?.deviceName)!) + .padding() } - else{ - Text("Complete commissioning with a commissioner manually!").padding() + else if(viewModel.udcRequestSent == false) { + Text("Could not send user directed commissioning request to " + (selectedCommissioner?.deviceName)!) + .foregroundColor(Color.red) + .padding() } } else if(viewModel.commisisoningWindowOpened == false) { diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningViewModel.swift new file mode 100644 index 00000000000000..af068b6d5ea8db --- /dev/null +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningViewModel.swift @@ -0,0 +1,118 @@ +/** + * + * Copyright (c) 2020-2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +import Foundation +import os.log + +class CommissioningViewModel: ObservableObject { + let Log = Logger(subsystem: "com.matter.casting", + category: "CommissioningViewModel") + + @Published var udcRequestSent: Bool?; + + @Published var commisisoningWindowOpened: Bool?; + + @Published var commisisoningComplete: Bool?; + + @Published var connectionSuccess: Bool?; + + @Published var connectionStatus: String?; + + // content app that the tv-casting-app wants to cast to + let kTargetContentAppVendorId:UInt16 = 65521; + + func prepareForCommissioning(selectedCommissioner: DiscoveredNodeData?) { + if let castingServerBridge = CastingServerBridge.getSharedInstance() + { + castingServerBridge.setDacHolder(ExampleDAC(), clientQueue: DispatchQueue.main, setDacHolderStatus: { (error: MatterError) -> () in + DispatchQueue.main.async { + self.Log.info("CommissioningViewModel.setDacHolder status was \(error)") + if(error.code == 0) + { + castingServerBridge.openBasicCommissioningWindow(DispatchQueue.main, + commissioningCallbackHandlers: CommissioningCallbackHandlers( + commissioningWindowRequestedHandler: { (result: MatterError) -> () in + DispatchQueue.main.async { + self.Log.info("Commissioning Window Requested status: \(result)") + self.commisisoningWindowOpened = (result.code == 0) + } + }, + commissioningWindowOpenedCallback: { (result: MatterError) -> () in + self.Log.info("Commissioning Window Opened status: \(result)") + DispatchQueue.main.async { + self.commisisoningWindowOpened = (result.code == 0) + // Send User directed commissioning request if a commissioner with a known IP addr was selected + if(selectedCommissioner != nil && selectedCommissioner!.numIPs > 0) + { + self.sendUserDirectedCommissioningRequest(selectedCommissioner: selectedCommissioner) + } + } + }, + commissioningCompleteCallback: { (result: MatterError) -> () in + self.Log.info("Commissioning status: \(result)") + DispatchQueue.main.async { + self.commisisoningComplete = (result.code == 0) + } + }, + sessionEstablishmentStartedCallback: { + self.Log.info("PASE session establishment started") + }, + sessionEstablishedCallback: { + self.Log.info("PASE session established") + }, + sessionEstablishmentErrorCallback: { (err: MatterError) -> () in + self.Log.info("PASE session establishment error : \(err)") + }, + sessionEstablishmentStoppedCallback: { + self.Log.info("PASE session establishment stopped") + } + ), + onConnectionSuccessCallback: { (videoPlayer: VideoPlayer) -> () in + DispatchQueue.main.async { + self.connectionSuccess = true + self.connectionStatus = "Connected to \(String(describing: videoPlayer))" + self.Log.info("CommissioningViewModel.verifyOrEstablishConnection.onConnectionSuccessCallback called with \(videoPlayer.nodeId)") + } + }, + onConnectionFailureCallback: { (error: MatterError) -> () in + DispatchQueue.main.async { + self.connectionSuccess = false + self.connectionStatus = "Failed to connect to video player!" + self.Log.info("CommissioningViewModel.verifyOrEstablishConnection.onConnectionFailureCallback called with \(error)") + } + }, + onNewOrUpdatedEndpointCallback: { (contentApp: ContentApp) -> () in + DispatchQueue.main.async { + self.Log.info("CommissioningViewModel.openBasicCommissioningWindow.onNewOrUpdatedEndpointCallback called with \(contentApp.endpointId)") + } + }) + } + } + }) + } + } + + private func sendUserDirectedCommissioningRequest(selectedCommissioner: DiscoveredNodeData?) { + if let castingServerBridge = CastingServerBridge.getSharedInstance() + { + castingServerBridge.sendUserDirectedCommissioningRequest(selectedCommissioner!, clientQueue: DispatchQueue.main, udcRequestSentHandler: { (result: MatterError) -> () in + self.udcRequestSent = (result.code == 0) + }, desiredContentAppVendorId: kTargetContentAppVendorId) + } + } +} diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentLauncherView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ContentLauncherView.swift similarity index 97% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentLauncherView.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ContentLauncherView.swift index dc15dc66876fa6..1852a4691f437c 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentLauncherView.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ContentLauncherView.swift @@ -23,6 +23,7 @@ extension ContentApp : Identifiable { } } +@available(*, deprecated, message: "Refer to MCContentLauncherLaunchURLExampleView") struct ContentLauncherView: View { @StateObject var viewModel = ContentLauncherViewModel() diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentLauncherViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ContentLauncherViewModel.swift similarity index 89% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentLauncherViewModel.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ContentLauncherViewModel.swift index 7003525e8d3360..3c68d1b5ab6a84 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ContentLauncherViewModel.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ContentLauncherViewModel.swift @@ -48,16 +48,16 @@ class ContentLauncherViewModel: ObservableObject { .contentLauncher_launchUrl(targetContentApp!, contentUrl: contentUrl!, contentDisplayStr: contentDisplayStr!, responseCallback: - { (result: Bool) -> () in + { (result: MatterError) -> () in self.Log.info("ContentLauncherViewModel.launchUrl.launchUrlResponseCallback result \(result)") DispatchQueue.main.async { - self.status = result ? "Launched URL successfully" : "Launch URL failure!" + self.status = (result == MATTER_NO_ERROR) ? "Launched URL successfully" : "Launch URL failure!" } }, clientQueue: DispatchQueue.main, - requestSentHandler: { (result: Bool) -> () in + requestSentHandler: { (result: MatterError) -> () in self.Log.info("ContentLauncherViewModel.launchUrl.launcUrlRequestSentHandler result \(result)") - self.status = result ? "Sent Launch URL request" : "Failed to send Launch URL request!" + self.status = (result == MATTER_NO_ERROR) ? "Sent Launch URL request" : "Failed to send Launch URL request!" }) } } diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/ExampleDAC.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ExampleDAC.swift similarity index 100% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/ExampleDAC.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ExampleDAC.swift diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MediaPlaybackView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/MediaPlaybackView.swift similarity index 97% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/MediaPlaybackView.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/MediaPlaybackView.swift index b41835adb0c139..8d66639cbfba53 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MediaPlaybackView.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/MediaPlaybackView.swift @@ -17,6 +17,7 @@ import SwiftUI +@available(*, deprecated, message: "Refer to MCMediaPlaybackSubscribeToCurrentStateExampleView") struct MediaPlayerView: View { @StateObject var viewModel = MediaPlaybackViewModel() diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MediaPlaybackViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/MediaPlaybackViewModel.swift similarity index 100% rename from examples/tv-casting-app/darwin/TvCasting/TvCasting/MediaPlaybackViewModel.swift rename to examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/MediaPlaybackViewModel.swift diff --git a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp index 0f455d6b4c9a44..a712c1733dc1a8 100644 --- a/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp +++ b/examples/tv-casting-app/tv-casting-common/core/CastingPlayer.cpp @@ -113,6 +113,7 @@ void CastingPlayer::VerifyOrEstablishConnection(ConnectCallback onCompleted, uns ChipLogProgress(AppServer, "CastingPlayer::VerifyOrEstablishConnection() Forcing expiry of armed FailSafe timer"); // ChipDeviceEventHandler will handle the kFailSafeTimerExpired event by Opening the Basic Commissioning Window and Sending // the User Directed Commissioning Request + support::ChipDeviceEventHandler::SetUdcStatus(false); chip::Server::GetInstance().GetFailSafeContext().ForceFailSafeTimerExpiry(); } else diff --git a/examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp b/examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp index 819c0299945ed4..9793b6c5fc6316 100644 --- a/examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp +++ b/examples/tv-casting-app/tv-casting-common/support/CastingStore.cpp @@ -422,14 +422,14 @@ std::vector CastingStore::ReadAll() ChipLogError(AppServer, "TLVReader.ExitContainer failed %" CHIP_ERROR_FORMAT, err.Format())); // create a castingPlayer with Endpoints and add it to the castingPlayers to be returned - core::CastingPlayer castingPlayer(attributes); + core::CastingPlayer * castingPlayer = new core::CastingPlayer(attributes); for (auto & endpointAttributes : endpointAttributesList) { - std::shared_ptr endpoint(new core::Endpoint(&castingPlayer, endpointAttributes)); + std::shared_ptr endpoint(new core::Endpoint(castingPlayer, endpointAttributes)); endpoint->RegisterClusters(endpointServerListMap[endpointAttributes.mId]); - castingPlayer.RegisterEndpoint(endpoint); + castingPlayer->RegisterEndpoint(endpoint); } - castingPlayers.push_back(castingPlayer); + castingPlayers.push_back(*castingPlayer); continue; } } diff --git a/examples/tv-casting-app/tv-casting-common/support/ChipDeviceEventHandler.cpp b/examples/tv-casting-app/tv-casting-common/support/ChipDeviceEventHandler.cpp index b7136b3583884f..bddc64f67fb620 100644 --- a/examples/tv-casting-app/tv-casting-common/support/ChipDeviceEventHandler.cpp +++ b/examples/tv-casting-app/tv-casting-common/support/ChipDeviceEventHandler.cpp @@ -91,7 +91,22 @@ void ChipDeviceEventHandler::Handle(const chip::DeviceLayer::ChipDeviceEvent * e void ChipDeviceEventHandler::HandleFailSafeTimerExpired() { - ChipLogProgress(AppServer, "ChipDeviceEventHandler::HandleFailSafeTimerExpired called"); + // if UDC was in progress (when the Fail-Safe timer expired), reset TargetCastingPlayer commissioning state and return early + if (sUdcInProgress) + { + ChipLogProgress(AppServer, "ChipDeviceEventHandler::HandleFailSafeTimerExpired when sUdcInProgress: %d, returning early", + sUdcInProgress); + sUdcInProgress = false; + CastingPlayer::GetTargetCastingPlayer()->mConnectionState = CASTING_PLAYER_NOT_CONNECTED; + CastingPlayer::GetTargetCastingPlayer()->mOnCompleted(CHIP_ERROR_TIMEOUT, nullptr); + CastingPlayer::GetTargetCastingPlayer()->mOnCompleted = nullptr; + CastingPlayer::GetTargetCastingPlayer()->mTargetCastingPlayer = nullptr; + return; + } + + // if UDC was NOT in progress (when the Fail-Safe timer expired), start UDC + ChipLogProgress(AppServer, "ChipDeviceEventHandler::HandleFailSafeTimerExpired when sUdcInProgress: %d, starting UDC", + sUdcInProgress); chip::DeviceLayer::SystemLayer().StartTimer( chip::System::Clock::Milliseconds32(1), [](chip::System::Layer * aSystemLayer, void * aAppState) { @@ -194,6 +209,7 @@ void ChipDeviceEventHandler::HandleCommissioningComplete(const chip::DeviceLayer CHIP_ERROR ChipDeviceEventHandler::SetUdcStatus(bool udcInProgress) { + ChipLogProgress(AppServer, "ChipDeviceEventHandler::SetUdcStatus called with udcInProgress: %d", udcInProgress); if (sUdcInProgress == udcInProgress) { ChipLogError(AppServer, "UDC in progress state is already %d", sUdcInProgress);