diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm index 2fcd7b0070824a..6f6bac189a6b18 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm @@ -127,6 +127,16 @@ - (uint16_t)vendorId return _cppCastingPlayer->GetVendorId(); } +- (uint64_t)nodeId +{ + return _cppCastingPlayer->GetNodeId(); +} + +- (uint8_t)fabricIndex +{ + return _cppCastingPlayer->GetFabricIndex(); +} + - (uint32_t)deviceType { return _cppCastingPlayer->GetDeviceType(); 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 40cf346e445060..381e296b69b85c 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer_Internal.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer_Internal.h @@ -26,9 +26,12 @@ @interface MCCastingPlayer () ++ (MCCastingPlayer * _Nullable)getTargetCastingPlayer; + - (instancetype _Nonnull)initWithCppCastingPlayer:(matter::casting::memory::Strong)cppCastingPlayer; -+ (MCCastingPlayer * _Nullable)getTargetCastingPlayer; +//- (uint64_t)nodeId; +//- (uint8_t)fabricIndex; @end diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCEndpoint.mm index f5e5aac89abb69..e06ce0394261e7 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()]; 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/compat-shim/CastingServerBridge.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.h index b0885c4b67ebf9..152e49ce81a4a3 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.h @@ -30,7 +30,7 @@ #ifndef CastingServerBridge_h #define CastingServerBridge_h -__attribute__((deprecated("This class is deprecated. Use ../../../../APIs.md instead."))) +__attribute__((deprecated("This class is deprecated. Use the APIs described in /examples/tv-casting-app/APIs.md instead."))) @interface CastingServerBridge : NSObject + (CastingServerBridge * _Nullable)getSharedInstance; 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 index 9d62e0b68963b6..caa161c4635ac1 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/CastingServerBridge.mm @@ -200,7 +200,7 @@ - (void)openBasicCommissioningWindow:(dispatch_queue_t _Nonnull)clientQueue _onConnectionFailureCallback = onConnectionFailureCallback; _onNewOrUpdatedEndpointCallback = onNewOrUpdatedEndpointCallback; - // short-circuit commissioningWindow callbacks with MATTER_NO_ERROR + // no-op: short-circuit commissioningWindow callbacks with MATTER_NO_ERROR dispatch_async(clientQueue, ^{ if (commissioningCallbackHandlers != nil) { if (commissioningCallbackHandlers.commissioningWindowRequestedHandler != nil) { @@ -222,9 +222,27 @@ - (void)sendUserDirectedCommissioningRequest:(DiscoveredNodeData * _Nonnull)comm MCEndpointFilter * filter = [MCEndpointFilter new]; filter.vendorId = kAmazonAppVendorId; - [commissioner.getCastingPlayer verifyOrEstablishConnectionWithCompletionBlock:^(NSError * _Nullable) { - // TODO: callback on _onConnectionSuccessCallback, _onConnectionFailureCallback, _onNewOrUpdatedEndpointCallback + [commissioner.getCastingPlayer verifyOrEstablishConnectionWithCompletionBlock:^(NSError * _Nullable err) { + dispatch_async(clientQueue, ^{ + if (err == nil) { + 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 diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.h index b9a7384b0a3f7e..2bf28dc30ab6de 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.h @@ -17,6 +17,8 @@ #import +#import "../MCEndpoint.h" + #ifndef ContentApp_h #define ContentApp_h @@ -33,6 +35,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/compat-shim/ContentApp.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/ContentApp.mm index ac4649867bdb2a..fe0e92a1fab98a 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/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/compat-shim/DataSourceCompat.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.mm index 8adfd00fbeee8a..ce6f255bf60d45 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/DataSourceCompat.mm @@ -93,38 +93,30 @@ - (MCDeviceAttestationCredentials *)castingAppDidReceiveRequestForDeviceAttestat - (MatterError *)castingApp:(id)sender didReceiveRequestToSignCertificateRequest:(NSData *)csrData outRawSignature:(NSData * _Nonnull * _Nonnull)outRawSignature { - NSLog(@"castingApp didReceiveRequestToSignCertificateRequest"); - + ChipLogProgress(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest called"); if (self.dacHolder != nil) { - CHIP_ERROR result = CHIP_NO_ERROR; - // Get the private SecKey from dacHolder SecKeyRef privateSecKey = [self.dacHolder getDeviceAttestationCertPrivateKeyRef]; - if (privateSecKey == nil) { - NSLog(@"Failed to retrieve private key from dacHolder."); + 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 || asn1SignatureData == nil) { - NSLog(@"Failed to sign message. Error: %@", error); + if (error != nil) { + ChipLogError(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest failed to sign message, err: %@", error); return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT]; } - - // Convert ASN.1 DER signature to SEC1 raw format - MatterError * conversionError = [MCCryptoUtils ecdsaAsn1SignatureToRawWithFeLengthBytes:32 - asn1Signature:asn1SignatureData - outRawSignature:outRawSignature]; - - if (conversionError != MATTER_NO_ERROR) { - NSLog(@"Failed to convert to raw signature."); - return conversionError; + if (asn1SignatureData == nil) { + ChipLogError(AppServer, "DataSourceCompat::castingApp didReceiveRequestToSignCertificateRequest failed to sign message, asn1SignatureData is nil"); + return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT]; } - return [MCErrorUtils MatterErrorFromChipError:result]; + // Convert ASN.1 DER signature to SEC1 raw format + return [MCCryptoUtils ecdsaAsn1SignatureToRawWithFeLengthBytes:32 asn1Signature:asn1SignatureData + outRawSignature:outRawSignature]; } return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE]; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.m b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.m index 5940ea9cbea01d..2dab3588756643 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.m +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/compat-shim/VideoPlayer.m @@ -17,7 +17,9 @@ #import +#import "ContentApp.h" #import "VideoPlayer.h" +// #import "../MCCastingPlayer_Internal.h" @interface VideoPlayer () @@ -73,17 +75,21 @@ - (instancetype)initWithCastingPlayer:(MCCastingPlayer *)castingPlayer { if (self = [super init]) { _castingPlayer = castingPlayer; + //_nodeId = castingPlayer.nodeId; + //_fabricIndex = castingPlayer.fabricIndex; _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]]; + } _isConnected = false; // this will make the compat shim call the openBasicCommissioningWindow API _isInitialized = true; - - //_contentApps = contentApps; TODO - //_MACAddress = MACAddress; } return self; } 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 ff7f1e98f3f9a3..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,8 +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 */; }; - 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 */; }; @@ -69,8 +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 = ""; }; - 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 = ""; }; @@ -111,8 +107,6 @@ 3C7507B62853A3AD00D7DB3A /* CommissionerDiscoveryViewModel.swift */, 3C7507AE28529A5F00D7DB3A /* CommissioningView.swift */, 3C7507B82853EFF000D7DB3A /* CommissioningViewModel.swift */, - 3C81C75628F8E418001CB9D1 /* ConnectionView.swift */, - 3C81C75828F8E42D001CB9D1 /* ConnectionViewModel.swift */, 3CA1CA7928E281080023ED44 /* ClusterSelectorView.swift */, 3CA19434285BA780004768D5 /* ContentLauncherView.swift */, 3CA19436285BA877004768D5 /* ContentLauncherViewModel.swift */, @@ -277,7 +271,6 @@ 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/compat/CommissionerDiscoveryView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissionerDiscoveryView.swift index 542a980917d7e4..2910ebacebdd52 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissionerDiscoveryView.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissionerDiscoveryView.swift @@ -47,7 +47,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/compat/CommissioningView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningView.swift index a3a02e1747888f..f7716b2875b88c 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningView.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/CommissioningView.swift @@ -39,21 +39,15 @@ struct CommissioningView: View { .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/ConnectionView.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ConnectionView.swift deleted file mode 100644 index c7bfacc6cca49e..00000000000000 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/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/compat/ConnectionViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/ConnectionViewModel.swift deleted file mode 100644 index 2d97a47ab3966c..00000000000000 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/compat/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)") - } - }) - } - } -}