Audio and Video Capabilities

Last Updated on : 2024-06-27 10:34:04download

After retrieving the list of devices by home, you can check their models to see if they have IPC capabilities. With IPC capabilities, you can create a camera object based on the information in ThingSmartDeviceModel.

Check support for IPC capabilities

API description

Check whether a device has IPC capabilities with the method in ThingSmartDeviceModel+IPCSDK.

Do not use this method to determine the device category. Some hybrid products, like video door locks and pet feeders, come with advanced IPC capabilities alongside their own features.

- (BOOL)isIPCDevice;

Example

Objective-C:

[[ThingSmartHomeManager new] getHomeListWithSuccess:^(NSArray<ThingSmartHomeModel *> *homes) {
        [homes enumerateObjectsUsingBlock:^(ThingSmartHomeModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                ThingSmartHome *home = [ThingSmartHome homeWithHomeId:obj.homeId];
                [home getHomeDetailWithSuccess:^(ThingSmartHomeModel *homeModel) {
                        [home.deviceList enumerateObjectsUsingBlock:^(ThingSmartDeviceModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if ([obj isIPCDevice]) {
                        NSLog(@"%@ is a smart camera", obj.name);
                    }
        }];
        } failure:^(NSError *error) {

        }];
    }];
} failure:^(NSError *error) {

}];

Swift:

let homeManager = ThingSmartHomeManager()
homeManager.getHomeList(success: { homeList in
    homeList?.forEach({ homeModel in
        let home = ThingSmartHome(homeId: homeModel.homeId)
        home?.getDetailWithSuccess({ _ in
            home?.deviceList.forEach({ deviceModel in
                if deviceModel.isIPCDevice() {
                    print(deviceModel.name!, "is a smart camera")
                }
            })
        }, failure: { error in

        })
    })
}) { error in

}

The sample code shows the basic process for devices with advanced IPC capabilities. In practical development, display and manage devices based on UI logic.

Query P2P type

The Smart Camera SDK initializes the camera object by P2P type. You can check a device’s P2P type by calling - (NSInteger)p2pType in ThingSmartDeviceModel+IPCSDK.

API description

Query P2P type.

- (NSInteger)p2pType;

Return value

Type Description
NSInteger The P2P type.

Camera instance

Class (protocol) description

Class (protocol) Description
ThingSmartCameraFactory The utility class for creating camera configurations and camera objects.
ThingSmartCameraConfig The camera configuration class. You can leave it as is.
ThingSmartCameraType The camera methods, varying by the type of camera firmware.
ThingSmartCameraDelegate The camera delegates, used to return the results of operations.

ThingSmartCameraFactory provides a factory method for creating camera control objects.

API description

Create a camera instance.

+ (id<ThingSmartCameraType>)cameraWithP2PType:(id)type deviceId:(NSString *)devId delegate:(id<ThingSmartCameraDelegate>)delegate;

Parameters

Parameter Description
type The P2P type, with the parameter of Number type.
devId The device ID.
delegate Delegate object

Return value

Type Description
id The specific implementation of the camera method.

Example

Objective-C:

// deviceModel is the data model for camera devices in the device list.
NSInteger p2pType = [deviceModel p2pType];
id<ThingSmartCameraType> camera = [ThingSmartCameraFactory cameraWithP2PType:@(p2pType) deviceId:deviceModel.devId delegate:self];

Swift:

let p2pType: NSNumber = NSNumber(value: deviceModel.p2pType())
let camera = ThingSmartCameraFactory.camera(withP2PType: p2pType, deviceId: deviceModel.devId, delegate: self)

In the sample code, self specified for the delegate requires the protocol ThingSmartCameraDelegate.