From fbd68ccdcbabd55b1eaa50fe8eb2c3496a982812 Mon Sep 17 00:00:00 2001 From: Philip Gregor Date: Thu, 20 Jun 2024 17:29:54 -0700 Subject: [PATCH] Addressed comments by sharadb-amazon --- .../MatterTvCastingBridge/MCCastingPlayer.mm | 2 +- .../MCCommissionerDeclaration.h | 36 ++++++++--- .../MCCommissionerDeclaration.mm | 59 ------------------- .../MatterTvCastingBridge/MCDataSource.h | 10 ---- .../MCIdentificationDeclarationOptions.h | 41 ++++++++++--- .../MCIdentificationDeclarationOptions.mm | 33 +---------- .../MatterTvCastingBridge/MCTargetAppInfo.h | 19 ++---- .../MatterTvCastingBridge/MCTargetAppInfo.mm | 32 ---------- .../TvCasting.xcodeproj/project.pbxproj | 4 ++ ...ionBasicReadVendorIDExampleViewModel.swift | 18 +----- .../MCConnectionExampleViewModel.swift | 8 +-- ...entLauncherLaunchURLExampleViewModel.swift | 18 +----- .../TvCasting/MCEndpointSelector.swift | 38 ++++++++++++ ...scribeToCurrentStateExampleViewModel.swift | 18 +----- .../TvCasting/TvCasting/TvCastingApp.swift | 4 +- 15 files changed, 128 insertions(+), 212 deletions(-) create mode 100644 examples/tv-casting-app/darwin/TvCasting/TvCasting/MCEndpointSelector.swift diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm index 11375c4252b472..793f76ff7ee791 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCastingPlayer.mm @@ -133,7 +133,7 @@ - (NSError *)verifyOrEstablishConnectionWithCallbacks:(MCConnectionCallbacks * _ if (identificationDeclarationOptions != nil) { cppIdOptions = [identificationDeclarationOptions getCppIdentificationDeclarationOptions]; } else { - ChipLogProgress(AppServer, "MCCastingPlayer.verifyOrEstablishConnectionWithCallbacks()->setupCppIdOptions() helper. Client did not set the optional MCIdentificationDeclarationOptions using default options"); + ChipLogProgress(AppServer, "MCCastingPlayer.setupCppIdOptions() Client did not set the optional MCIdentificationDeclarationOptions using default options"); } return cppIdOptions; } diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommissionerDeclaration.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommissionerDeclaration.h index f92cb79fe3d7e9..85bc465c667ab8 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommissionerDeclaration.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommissionerDeclaration.h @@ -48,6 +48,35 @@ typedef NS_ENUM(NSInteger, CdError) { kUnexpectedCommissionerPasscodeReady = 18 }; +/** Feature: All - Indicates errors incurred during commissioning. */ +@property (nonatomic, readonly) CdError errorCode; +/** + * Feature: Coordinate PIN Dialogs - When NoPasscode field set to true, and the Commissioner + * determines that a Passcode code will be needed for commissioning. + */ +@property (nonatomic, readonly) BOOL needsPasscode; +/** + * Feature: Target Content Application - No apps with AccountLogin cluster implementation were + * found for the last IdentificationDeclaration request. Only apps which provide access to the + * vendor id of the Commissionee will be considered. + */ +@property (nonatomic, readonly) BOOL noAppsFound; +/** + * Feature: Coordinate PIN Dialogs - A Passcode input dialog is now displayed for the user on the + * Commissioner. + */ +@property (nonatomic, readonly) BOOL passcodeDialogDisplayed; +/** + * Feature: Commissioner-Generated Passcode - A Passcode is now displayed for the user by the + * CastingPlayer/Commissioner. + */ +@property (nonatomic, readonly) BOOL commissionerPasscode; +/** + * Feature: Commissioner-Generated Passcode - The user experience conveying a Passcode to the user + * also displays a QR code. + */ +@property (nonatomic, readonly) BOOL qRCodeDisplayed; + - (instancetype)initWithOptions:(NSInteger)errorCode needsPasscode:(BOOL)needsPasscode noAppsFound:(BOOL)noAppsFound @@ -55,13 +84,6 @@ typedef NS_ENUM(NSInteger, CdError) { commissionerPasscode:(BOOL)commissionerPasscode qRCodeDisplayed:(BOOL)qRCodeDisplayed; -- (CdError)getErrorCode; -- (BOOL)getNeedsPasscode; -- (BOOL)getNoAppsFound; -- (BOOL)getPasscodeDialogDisplayed; -- (BOOL)getCommissionerPasscode; -- (BOOL)getQRCodeDisplayed; - - (NSString *)description; - (void)logDetail; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommissionerDeclaration.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommissionerDeclaration.mm index 6c1e270f4ac9f2..1663f1626bb1f8 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommissionerDeclaration.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCCommissionerDeclaration.mm @@ -20,35 +20,6 @@ @interface MCCommissionerDeclaration () -/** Feature: All - Indicates errors incurred during commissioning. */ -@property (nonatomic) CdError errorCode; -/** - * Feature: Coordinate PIN Dialogs - When NoPasscode field set to true, and the Commissioner - * determines that a Passcode code will be needed for commissioning. - */ -@property (nonatomic) BOOL needsPasscode; -/** - * Feature: Target Content Application - No apps with AccountLogin cluster implementation were - * found for the last IdentificationDeclaration request. Only apps which provide access to the - * vendor id of the Commissionee will be considered. - */ -@property (nonatomic) BOOL noAppsFound; -/** - * Feature: Coordinate PIN Dialogs - A Passcode input dialog is now displayed for the user on the - * Commissioner. - */ -@property (nonatomic) BOOL passcodeDialogDisplayed; -/** - * Feature: Commissioner-Generated Passcode - A Passcode is now displayed for the user by the - * CastingPlayer/Commissioner. - */ -@property (nonatomic) BOOL commissionerPasscode; -/** - * Feature: Commissioner-Generated Passcode - The user experience conveying a Passcode to the user - * also displays a QR code. - */ -@property (nonatomic) BOOL qRCodeDisplayed; - @property (nonatomic, readwrite) matter::casting::memory::Strong cppCommissionerDeclaration; @end @@ -88,36 +59,6 @@ - (instancetype)initWithOptions:(NSInteger)errorCode return self; } -- (CdError)getErrorCode -{ - return _errorCode; -} - -- (BOOL)getNeedsPasscode -{ - return _needsPasscode; -} - -- (BOOL)getNoAppsFound -{ - return _noAppsFound; -} - -- (BOOL)getPasscodeDialogDisplayed -{ - return _passcodeDialogDisplayed; -} - -- (BOOL)getCommissionerPasscode -{ - return _commissionerPasscode; -} - -- (BOOL)getQRCodeDisplayed -{ - return _qRCodeDisplayed; -} - - (NSString *)description { return [NSString stringWithFormat:@"MCCommissionerDeclaration::errorCode: %@\nMCCommissionerDeclaration::needsPasscode: %d\nMCCommissionerDeclaration::noAppsFound: %d\nMCCommissionerDeclaration::passcodeDialogDisplayed: %d\nMCCommissionerDeclaration::commissionerPasscode: %d\nMCCommissionerDeclaration::qRCodeDisplayed: %d", diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDataSource.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDataSource.h index 61c03d67acfa9f..6339de82bc2695 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDataSource.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCDataSource.h @@ -29,16 +29,6 @@ */ - (dispatch_queue_t _Nonnull)clientQueue; -/** - * @brief Updates the MCCommissionableData object stored inside MCAppParametersDataSource, which was used to - * initialize the MCCastingApp. This function needs to be implemented by the client in use cases where the - * MCCommissionableData needs to be updated post-initialization. For example, when the Commissioner-Generated - * Passcode feature is used. - * - * @param newCommissionableData The new MCCommissionableData object to be used for the next commissioning session. - */ -- (void)update:(MCCommissionableData * _Nonnull)newCommissionableData; - /** * @brief Provide UniqueId used to generate the RotatingDeviceId advertised during commissioning by the MCCastingApp * Must be at least 16 bytes (i.e. ConfigurationManager::kMinRotatingDeviceIDUniqueIDLength) diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCIdentificationDeclarationOptions.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCIdentificationDeclarationOptions.h index 0fb0da29c59cd8..98969576a256ed 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCIdentificationDeclarationOptions.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCIdentificationDeclarationOptions.h @@ -27,22 +27,49 @@ */ @interface MCIdentificationDeclarationOptions : NSObject +/** + * Feature: Target Content Application - Flag to instruct the Commissioner not to display a + * Passcode input dialog, and instead send a CommissionerDeclaration message if a commissioning + * Passcode is needed. + */ +@property (nonatomic, readonly) BOOL noPasscode; +/** + * Feature: Coordinate Passcode Dialogs - Flag to instruct the Commissioner to send a + * CommissionerDeclaration message when the Passcode input dialog on the Commissioner has been + * shown to the user. + */ +@property (nonatomic, readonly) BOOL cdUponPasscodeDialog; +/** + * Feature: Commissioner-Generated Passcode - Flag to instruct the Commissioner to use the + * Commissioner-generated Passcode for commissioning. + */ +@property (nonatomic, readonly) BOOL commissionerPasscode; +/** + * Feature: Commissioner-Generated Passcode - Flag to indicate whether or not the Commissionee has + * obtained the Commissioner Passcode from the user and is therefore ready for commissioning. + */ +@property (nonatomic, readonly) BOOL commissionerPasscodeReady; +/** + * Feature: Coordinate Passcode Dialogs Flag - to indicate when the Commissionee user has decided + * to exit the commissioning process. + */ +@property (nonatomic, readonly) BOOL cancelPasscode; + - (instancetype)init; - (instancetype)initWithCommissionerPasscodeOnly:(BOOL)commissionerPasscode; -// Getter methods -- (BOOL)getNoPasscode; -- (BOOL)getCdUponPasscodeDialog; -- (BOOL)getCommissionerPasscode; -- (BOOL)getCommissionerPasscodeReady; -- (BOOL)getCancelPasscode; - /** * @brief Adds a TargetAppInfo to the IdentificationDeclarationOptions.java TargetAppInfos list, * up to a maximum of CHIP_DEVICE_CONFIG_UDC_MAX_TARGET_APPS. */ - (BOOL)addTargetAppInfo:(MCTargetAppInfo *)targetAppInfo NS_SWIFT_NAME(addTargetAppInfo(_:)); +/** + * Feature: Target Content Application - The set of content app Vendor IDs (and optionally, + * Product IDs) that can be used for authentication. Also, if TargetAppInfo is passed in, + * VerifyOrEstablishConnection() will force User Directed Commissioning, in case the desired + * TargetApp is not found in the on-device CastingStore. + */ - (NSArray *)getTargetAppInfoList; - (NSString *)description; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCIdentificationDeclarationOptions.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCIdentificationDeclarationOptions.mm index cdde8e268d46ee..9d7d1f53ef5110 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCIdentificationDeclarationOptions.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCIdentificationDeclarationOptions.mm @@ -21,35 +21,6 @@ @interface MCIdentificationDeclarationOptions () -// Private properties: - -/** - * Feature: Target Content Application - Flag to instruct the Commissioner not to display a - * Passcode input dialog, and instead send a CommissionerDeclaration message if a commissioning - * Passcode is needed. - */ -@property (nonatomic) BOOL noPasscode; -/** - * Feature: Coordinate Passcode Dialogs - Flag to instruct the Commissioner to send a - * CommissionerDeclaration message when the Passcode input dialog on the Commissioner has been - * shown to the user. - */ -@property (nonatomic) BOOL cdUponPasscodeDialog; -/** - * Feature: Commissioner-Generated Passcode - Flag to instruct the Commissioner to use the - * Commissioner-generated Passcode for commissioning. - */ -@property (nonatomic) BOOL commissionerPasscode; -/** - * Feature: Commissioner-Generated Passcode - Flag to indicate whether or not the Commissionee has - * obtained the Commissioner Passcode from the user and is therefore ready for commissioning. - */ -@property (nonatomic) BOOL commissionerPasscodeReady; -/** - * Feature: Coordinate Passcode Dialogs Flag - to indicate when the Commissionee user has decided - * to exit the commissioning process. - */ -@property (nonatomic) BOOL cancelPasscode; /** * Feature: Target Content Application - The set of content app Vendor IDs (and optionally, * Product IDs) that can be used for authentication. Also, if TargetAppInfo is passed in, @@ -159,8 +130,8 @@ - (NSString *)description NSArray * targetAppInfos = [self getTargetAppInfoList]; for (MCTargetAppInfo * appInfo in targetAppInfos) { chip::Protocols::UserDirectedCommissioning::TargetAppInfo targetAppInfo; - targetAppInfo.vendorId = appInfo.getVendorId; - targetAppInfo.productId = appInfo.getProductId; + targetAppInfo.vendorId = appInfo.vendorId; + targetAppInfo.productId = appInfo.productId; CHIP_ERROR err = cppIdOptions.addTargetAppInfo(targetAppInfo); if (err != CHIP_NO_ERROR) { ChipLogError(AppServer, "MCIdentificationDeclarationOptions.getCppIdentificationDeclarationOptions() Failed to add TargetAppInfo: %@", appInfo.description); diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCTargetAppInfo.h b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCTargetAppInfo.h index c3ae652109e6a7..b5f0cb052c458e 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCTargetAppInfo.h +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCTargetAppInfo.h @@ -26,8 +26,13 @@ */ @interface MCTargetAppInfo : NSObject -/** Initialize with vendorId and productId set to 0 */ +/** Target Target Content Application Vendor ID, 0 means unspecified */ +@property (nonatomic, readonly) uint16_t vendorId; + +/** Target Target Content Application Product ID, 0 means unspecified */ +@property (nonatomic, readonly) uint16_t productId; +/** Initialize with vendorId and productId set to 0 */ - (instancetype)init; /** Initialize with vendorId, productId defaults to 0 */ @@ -36,18 +41,6 @@ /** Initialize with vendorId and productId */ - (instancetype _Nonnull)initWithVendorId:(uint16_t)vendorId productId:(uint16_t)productId NS_DESIGNATED_INITIALIZER; -/** Vendor ID getter */ -- (uint16_t)getVendorId; - -/** Vendor ID setter */ -- (void)setVendorId:(uint16_t)vendorId; - -/** Product ID getter */ -- (uint16_t)getProductId; - -/** Product ID setter */ -- (void)setProductId:(uint16_t)productId; - /** Description method */ - (NSString * _Nonnull)description; diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCTargetAppInfo.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCTargetAppInfo.mm index 1f85051ba14f92..8c35d433b8318a 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCTargetAppInfo.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/MCTargetAppInfo.mm @@ -17,18 +17,6 @@ #import "MCTargetAppInfo.h" -@interface MCTargetAppInfo () - -// Private properties: - -/** Target Target Content Application Vendor ID, 0 means unspecified */ -@property (nonatomic) uint16_t vendorId; - -/** Target Target Content Application Product ID, 0 means unspecified */ -@property (nonatomic) uint16_t productId; - -@end - @implementation MCTargetAppInfo - (instancetype)init @@ -56,26 +44,6 @@ - (instancetype)initWithVendorId:(uint16_t)vendorId productId:(uint16_t)productI return self; } -- (uint16_t)getVendorId -{ - return _vendorId; -} - -- (void)setVendorId:(uint16_t)vendorId -{ - _vendorId = vendorId; -} - -- (uint16_t)getProductId -{ - return _productId; -} - -- (void)setProductId:(uint16_t)productId -{ - _productId = productId; -} - - (NSString *)description { return [NSString stringWithFormat:@"MCTargetAppInfo: vendorId: %d, productId: %d", self.vendorId, self.productId]; 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 2d4a142cd515a5..7716d722be4c43 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting.xcodeproj/project.pbxproj +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 39231BEA2C24F90200ADFB3A /* MCEndpointSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39231BE92C24F90200ADFB3A /* MCEndpointSelector.swift */; }; 3C40586E2B632DC500C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C40586D2B632DC500C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleView.swift */; }; 3C4058702B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C40586F2B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift */; }; 3C4F52302B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C4F522F2B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift */; }; @@ -54,6 +55,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 39231BE92C24F90200ADFB3A /* MCEndpointSelector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCEndpointSelector.swift; sourceTree = ""; }; 3C40586D2B632DC500C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCMediaPlaybackSubscribeToCurrentStateExampleView.swift; sourceTree = ""; }; 3C40586F2B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift; sourceTree = ""; }; 3C4F522F2B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MCContentLauncherLaunchURLExampleViewModel.swift; sourceTree = ""; }; @@ -158,6 +160,7 @@ 3C94377C2B364D380096E5F4 /* MCDiscoveryExampleViewModel.swift */, 3C94378F2B3B3FF90096E5F4 /* MCConnectionExampleView.swift */, 3C94377E2B364D510096E5F4 /* MCConnectionExampleViewModel.swift */, + 39231BE92C24F90200ADFB3A /* MCEndpointSelector.swift */, 3C621CB42B607FFD005CDBA3 /* MCActionSelectorView.swift */, 3C4F52312B5721D000BB8A10 /* MCContentLauncherLaunchURLExampleView.swift */, 3C4F522F2B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift */, @@ -266,6 +269,7 @@ 3C94377F2B364D510096E5F4 /* MCConnectionExampleViewModel.swift in Sources */, 3C4058702B632DDB00C7C6D6 /* MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift in Sources */, 3CCB8745286A5D0F00771BAD /* CommissionerDiscoveryView.swift in Sources */, + 39231BEA2C24F90200ADFB3A /* MCEndpointSelector.swift in Sources */, 3C621CB12B6078A9005CDBA3 /* MCApplicationBasicReadVendorIDExampleView.swift in Sources */, 3CCB8746286A5D0F00771BAD /* CommissionerDiscoveryViewModel.swift in Sources */, 3C4F52302B51F32000BB8A10 /* MCContentLauncherLaunchURLExampleViewModel.swift in Sources */, diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCApplicationBasicReadVendorIDExampleViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCApplicationBasicReadVendorIDExampleViewModel.swift index fea1772f4ee920..a95580f5aaf7cd 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCApplicationBasicReadVendorIDExampleViewModel.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCApplicationBasicReadVendorIDExampleViewModel.swift @@ -32,22 +32,10 @@ class MCApplicationBasicReadVendorIDExampleViewModel: ObservableObject { { self.Log.info("MCApplicationBasicReadVendorIDExampleViewModel.read()") castingPlayer.logAllEndpoints() - var selectedEndpoint: MCEndpoint? - // select the MCEndpoint on the MCCastingPlayer to invoke the command on - if let endpoint = castingPlayer.endpoints().filter({ $0.vendorId().intValue == sampleEndpointVid }).first { - selectedEndpoint = endpoint - // For the example Commissioner-Generated passcode commissioning flow, run demo interactions with the Endpoint with - // ID 1. For this flow, we commissioned with the Target Content Application with Vendor ID 1111. Since this target - // content application does not report its Endpoint's Vendor IDs, we find the desired endpoint based on the Endpoint - // ID. See connectedhomeip/examples/tv-app/tv-common/include/AppTv.h. - } else if let endpoint = castingPlayer.endpoints().filter({ $0.identifier().intValue == 1 }).first { - self.Log.info("MCApplicationBasicReadVendorIDExampleViewModel.read() No endpoint matching the sampleEndpointVid: \(String(describing: self.sampleEndpointVid)), but found endpoint with identifier: 1") - selectedEndpoint = endpoint - } - - guard let endpoint = selectedEndpoint else { - self.Log.error("No endpoint matching the example VID or identifier 1 found") + // Use MCEndpointSelector to select the endpoint + guard let endpoint = MCEndpointSelector.selectEndpoint(from: castingPlayer, sampleEndpointVid: sampleEndpointVid) else { + self.Log.error("MCApplicationBasicReadVendorIDExampleViewModel.read() No endpoint matching the example VID or identifier 1 found") DispatchQueue.main.async { self.status = "No endpoint matching the example VID or identifier 1 found" } diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCConnectionExampleViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCConnectionExampleViewModel.swift index 71f29e5ee917e8..13293d9b7ca1ee 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCConnectionExampleViewModel.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCConnectionExampleViewModel.swift @@ -63,7 +63,7 @@ class MCConnectionExampleViewModel: ObservableObject { let commissionerDeclarationCallback: (MCCommissionerDeclaration) -> Void = { commissionerDeclarationMessage in DispatchQueue.main.async { self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, recived a message form the MCCastingPlayer:\n\(commissionerDeclarationMessage)") - if commissionerDeclarationMessage.getCommissionerPasscode() { + if commissionerDeclarationMessage.commissionerPasscode { self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, calling getTopMostViewController()") if let topViewController = self.getTopMostViewController() { self.Log.info("MCConnectionExampleViewModel connect() commissionerDeclarationCallback, calling displayPasscodeInputDialog()") @@ -118,19 +118,19 @@ class MCConnectionExampleViewModel: ObservableObject { } let identificationDeclarationOptions: MCIdentificationDeclarationOptions - let targetAppInfo: MCTargetAppInfo = MCTargetAppInfo() + let targetAppInfo: MCTargetAppInfo let connectionCallbacks: MCConnectionCallbacks if useCommissionerGeneratedPasscode { identificationDeclarationOptions = MCIdentificationDeclarationOptions(commissionerPasscodeOnly: true) - targetAppInfo.setVendorId(kDesiredEndpointVendorIdCGP) + targetAppInfo = MCTargetAppInfo(vendorId: kDesiredEndpointVendorIdCGP) connectionCallbacks = MCConnectionCallbacks( callbacks: connectionCompleteCallback, commissionerDeclarationCallback: commissionerDeclarationCallback ) } else { identificationDeclarationOptions = MCIdentificationDeclarationOptions() - targetAppInfo.setVendorId(kDesiredEndpointVendorId) + targetAppInfo = MCTargetAppInfo(vendorId: kDesiredEndpointVendorId) connectionCallbacks = MCConnectionCallbacks( callbacks: connectionCompleteCallback, commissionerDeclarationCallback: nil diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCContentLauncherLaunchURLExampleViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCContentLauncherLaunchURLExampleViewModel.swift index 9923e2301ea30f..aaf18375bb2c82 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCContentLauncherLaunchURLExampleViewModel.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCContentLauncherLaunchURLExampleViewModel.swift @@ -32,22 +32,10 @@ class MCContentLauncherLaunchURLExampleViewModel: ObservableObject { { self.Log.info("MCContentLauncherLaunchURLExampleViewModel.invokeCommand()") castingPlayer.logAllEndpoints() - var selectedEndpoint: MCEndpoint? - // select the MCEndpoint on the MCCastingPlayer to invoke the command on - if let endpoint = castingPlayer.endpoints().filter({ $0.vendorId().intValue == sampleEndpointVid }).first { - selectedEndpoint = endpoint - // For the example Commissioner-Generated passcode commissioning flow, run demo interactions with the Endpoint with - // ID 1. For this flow, we commissioned with the Target Content Application with Vendor ID 1111. Since this target - // content application does not report its Endpoint's Vendor IDs, we find the desired endpoint based on the Endpoint - // ID. See connectedhomeip/examples/tv-app/tv-common/include/AppTv.h. - } else if let endpoint = castingPlayer.endpoints().filter({ $0.identifier().intValue == 1 }).first { - self.Log.info("MCContentLauncherLaunchURLExampleViewModel.invokeCommand() No endpoint matching the sampleEndpointVid: \(String(describing: self.sampleEndpointVid)), but found endpoint with identifier: 1") - selectedEndpoint = endpoint - } - - guard let endpoint = selectedEndpoint else { - self.Log.error("No endpoint matching the example VID or identifier 1 found") + // Use MCEndpointSelector to select the endpoint + guard let endpoint = MCEndpointSelector.selectEndpoint(from: castingPlayer, sampleEndpointVid: sampleEndpointVid) else { + self.Log.error("MCContentLauncherLaunchURLExampleViewModel.invokeCommand() No endpoint matching the example VID or identifier 1 found") DispatchQueue.main.async { self.status = "No endpoint matching the example VID or identifier 1 found" } diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCEndpointSelector.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCEndpointSelector.swift new file mode 100644 index 00000000000000..fa842c5f81f70b --- /dev/null +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCEndpointSelector.swift @@ -0,0 +1,38 @@ +/** + * + * 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 Foundation +import os.log + +class MCEndpointSelector { + static let Log = Logger(subsystem: "com.matter.casting", category: "MCEndpointSelector") + + static func selectEndpoint(from castingPlayer: MCCastingPlayer, sampleEndpointVid: Int) -> MCEndpoint? { + Log.info("MCEndpointSelector.selectEndpoint()") + + if let endpoint = castingPlayer.endpoints().filter({ $0.vendorId().intValue == sampleEndpointVid }).first { + Log.info("MCEndpointSelector.selectEndpoint() Found endpoint matching the sampleEndpointVid: \(sampleEndpointVid)") + return endpoint + } else if let endpoint = castingPlayer.endpoints().filter({ $0.identifier().intValue == 1 }).first { + Log.info("MCEndpointSelector.selectEndpoint() No endpoint matching the sampleEndpointVid: \(sampleEndpointVid), but found endpoint with identifier: 1") + return endpoint + } + + Log.error("No endpoint matching the example VID or identifier 1 found") + return nil + } +} diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift index bd6f7fb6f6b1a2..7a4752431e1846 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.swift @@ -32,22 +32,10 @@ class MCMediaPlaybackSubscribeToCurrentStateExampleViewModel: ObservableObject { { self.Log.info("MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.subscribe()") castingPlayer.logAllEndpoints() - var selectedEndpoint: MCEndpoint? - // select the MCEndpoint on the MCCastingPlayer to invoke the command on - if let endpoint = castingPlayer.endpoints().filter({ $0.vendorId().intValue == sampleEndpointVid }).first { - selectedEndpoint = endpoint - // For the example Commissioner-Generated passcode commissioning flow, run demo interactions with the Endpoint with - // ID 1. For this flow, we commissioned with the Target Content Application with Vendor ID 1111. Since this target - // content application does not report its Endpoint's Vendor IDs, we find the desired endpoint based on the Endpoint - // ID. See connectedhomeip/examples/tv-app/tv-common/include/AppTv.h. - } else if let endpoint = castingPlayer.endpoints().filter({ $0.identifier().intValue == 1 }).first { - self.Log.info("MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.subscribe() No endpoint matching the sampleEndpointVid: \(String(describing: self.sampleEndpointVid)), but found endpoint with identifier: 1") - selectedEndpoint = endpoint - } - - guard let endpoint = selectedEndpoint else { - self.Log.error("No endpoint matching the example VID or identifier 1 found") + // Use MCEndpointSelector to select the endpoint + guard let endpoint = MCEndpointSelector.selectEndpoint(from: castingPlayer, sampleEndpointVid: sampleEndpointVid) else { + self.Log.error("MCMediaPlaybackSubscribeToCurrentStateExampleViewModel.subscribe() No endpoint matching the example VID or identifier 1 found") DispatchQueue.main.async { self.status = "No endpoint matching the example VID or identifier 1 found" } diff --git a/examples/tv-casting-app/darwin/TvCasting/TvCasting/TvCastingApp.swift b/examples/tv-casting-app/darwin/TvCasting/TvCasting/TvCastingApp.swift index c27eec95fd5f3e..c164c62a1ff518 100644 --- a/examples/tv-casting-app/darwin/TvCasting/TvCasting/TvCastingApp.swift +++ b/examples/tv-casting-app/darwin/TvCasting/TvCasting/TvCastingApp.swift @@ -32,9 +32,7 @@ struct TvCastingApp: App { if ProcessInfo.processInfo.environment["CHIP_CASTING_SIMPLIFIED"] == "1" { self.Log.info("CHIP_CASTING_SIMPLIFIED = 1") - - let initializationExample = MCInitializationExample.shared - let err: Error? = initializationExample.initialize() + let err: Error? = MCInitializationExample.shared.initialize() if err != nil { self.Log.error("MCCastingApp initialization failed \(err)")