Wi-Fi Smart Lock Audio and Video Capabilities

Last Updated on : 2023-06-07 02:34:06

This topic describes the API methods that you can use to implement audio and video capabilities of Wi-Fi smart locks. For example, visual locks and camera locks support live video streaming and video talks.

Functional description

Class name Description
TuyaSmartWiFiLockDevice Wi-Fi lock operation class, encapsulating audio and video capabilities and inherited from TuyaSmartDevice
TuyaSmartWiFiLockDeviceDelegate Wi-Fi lock protocol delegate, extended from TuyaSmartDeviceDelegate

Delegate

TuyaSmartWiFiLockDeviceDelegate:

/// DP212: reports image uploading data.
///
/// @param device The lock.
/// @param message The data reported by the device.
- (void)onLockMessageArrived:(TuyaSmartWiFiLockDevice *)device
                     message:(NSDictionary *)message;

/// DP63: the callback for reporting live video streaming data.
///
/// @param device The lock.
/// @param model The data reported by the device.
- (void)onVideoRequestRealtime:(TuyaSmartWiFiLockDevice *)device
                         model:(NSString *)model;

/// DP9: reports the image of a remote unlocking request.
///
/// @param device The lock.
/// @param time The countdown data.
- (void)unlockRequestCountdown:(TuyaSmartWiFiLockDevice *)device
                          time:(NSInteger)time;

/// DP45: reports the image of an alert request.
///
/// @param device The lock.
/// @param time The countdown data.
- (void)alarmRequestCountdown:(TuyaSmartWiFiLockDevice *)device
                         time:(NSInteger)time;

/// DP50: reports the response to remote unlocking.
///
/// @param device The lock.
- (void)onRemoteUnlockReport:(TuyaSmartWiFiLockDevice *)device;

/// DP13: reports the response to forced double locking.
///
/// @param device The lock.
- (void)onForceLockUpReport:(TuyaSmartWiFiLockDevice *)device;

Example

// Initializes the SDK.
self.lockDevice = [[TuyaSmartWiFiLockDevice alloc] initWithDeviceId:self.device.deviceModel.devId];
// Sets a delegate.
self.lockDevice.delegate = self;

// DP63: requests remote unlocking.
- (void)onVideoRequestRealtime:(TuyaSmartWiFiLockDevice *)device model:(NSString *)model{
    //TODO
}

// DP212: reports image uploading data.
- (void)onLockMessageArrived:(TuyaSmartWiFiLockDevice *)device message:(nonnull NSDictionary *)message{
    //TODO
}

/// DP9: reports the image of a remote unlocking request.
- (void)unlockRequestCountdown:(TuyaSmartWiFiLockDevice *)device time:(NSInteger)time{
    //TODO    
}

// DP45: reports the image of an alert request.
- (void)alarmRequestCountdown:(TuyaSmartWiFiLockDevice *)device time:(NSInteger)time{
    //TODO
}

// DP50: reports the response to remote unlocking.
- (void)onRemoteUnlockReport:(TuyaSmartWiFiLockDevice *)device{
    //TODO
}

// DP13: reports the response to forced double locking.
- (void)onForceLockUpReport:(TuyaSmartWiFiLockDevice *)device{
    //TODO
}

Remote unlocking

API description

Implements remote operations, including unlocking, locking, unlocking rejection, and locking rejection.

- (void)remoteLockWithDevId:(NSString *)devId
                       open:(BOOL)open
                    confirm:(BOOL)confirm
                    success:(nullable TYSuccessBOOL)success
                    failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
devId The device ID.
open Specifies whether to unlock. Valid values:
  • YES: unlock
  • NO: lock
confirm Specifies whether to accept unlocking. Valid values:
  • YES: accept
  • NO: reject
success The success callback.
failure The failure callback.

The success callback only means the API method is called successfully, but cannot indicate the result of the command executed by the lock.

  • confirm=YES: The device status changes to run the unlocking or locking command. The command result depends on the listener for the result of the method onRemoteUnlockReport.
  • confirm=NO: The device status remains unchanged and no DP data is reported. success: The unlocking or locking request is rejected.

Example

    [self.lockDevice remoteLockWithDevId:devId
                                    open:YES
                                 confirm:NO
                                 success:^(BOOL result) {
						//TODO
    } failure:^(NSError *error) {
						//TODO
    }];

Capture image again

API description

Captures an image again. Then, the device transfers the captured image to cloud storage. onLockMessageArrived is called to report the image path. Due to device limits, this operation can only be implemented once within 15 seconds.

- (void)reTakePhoto:(BOOL)needTake
            success:(TYSuccessHandler)success
            failure:(TYFailureError)failure;

Parameters

Parameter Description
needTake Specifies whether to capture an image again.
success The success callback.
failure The failure callback.

Example

[self.lockDevice reTakePhoto:YES success:^{
						//TODO
    } failure:^(NSError *error) {
						//TODO
    }];

Forced double locking

API description

Implements forced double locking. The success callback onForceLockUpReport is executed.

- (void)enforceLock:(BOOL)needLock
            success:(TYSuccessHandler)success
            failure:(TYFailureError)failure;

Parameters

Parameter Description
needLock Specifies whether to implement forced double locking.
success The success callback.
failure The failure callback.

Example

[self.lockDevice enforceLock:YES
                         success:^{
						//TODO
    } failure:^(NSError *error) {
						//TODO
    }];

Get the latest image URL

API description

Returns the URL of the latest image from cloud storage. This request is made along with getPopupPictureAddressWithDevId.

- (void)getLatestPopupInfoWithDevId:(NSString *)devId
                           fileType:(NSInteger)fileType
                            success:(nullable TYSuccessID)success
                            failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
devId The device ID.
fileType The type of image. Valid values:
  • image captured due to remote unlocking
  • image captured due to an alert
success The success callback.
failure The failure callback.

Return value

Field Description
filePath The path of the image in cloud storage.
fileKey The key used to decrypt the image.
bucket The bucket in which the image is stored.

Example

    [self.lockDevice getLatestPopupInfoWithDevId:self.lockDevice.deviceModel.devId
                                        fileType:1
                                         success:^(id result) {
						//TODO
    } failure:^(NSError *error) {
						//TODO
    }];

Get URL of captured image

API description

Returns the URL of the image captured and uploaded to cloud storage. This request is made along with onLockMessageArrived or getLatestPicture.

- (void)getPopupPictureAddressWithDevId:(NSString *)devId
                                 bucket:(NSString *)bucket
                               filePath:(NSString *)filePath
                               success:(nullable TYSuccessID)success
                               failure:(nullable TYFailureError)failure;

Parameters

Parameter Description
devId The device ID.
bucket The bucket in which the image is stored.
filePath The encrypted URL of the image in cloud storage.
success The success callback.
failure The failure callback.

Return value

Field Description
fileUrl The path of the image in cloud storage.
mediaUrl The path of the video in cloud storage.
angle The rotation angle configured on the Tuya IoT Development Platform. Valid values: 0, 90, 180, and 270.

fileUrl is still an encrypted URL. onLockMessageArrived or getLatestPopupInfoWithDevId must be called to get the value of fileKey and decrypt the URL. Tuya provides the control TYEncryptImage to decrypt and display the image.

Example

// Returns the URL of the cover image.
[self.lockDevice getPopupPictureAddressWithDevId:self.lockDevice.deviceModel.devId
                                          bucket:bucket
                                        filePath:filePath
                                         success:^(id result) {
            NSInteger angle = [result[@"angle"] integerValue];
            NSString *fileUrl = result[@"fileUrl"];

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

// Returns the image after the image URL is decrypted.
UIImageView *imageView = [UIImageView new];
[imageView ty_setAESImageWithPath:fileUrl
                       encryptKey:fileKey
                        completed:^(UIImage * _Nullable image, NSURL * _Nullable url, TYEncryptWebImageFromType from, TYEncryptWebImageStage stage, NSError * _Nullable error) {
        //TODO
    }];

Get video streaming view object

Property description

@property (nonatomic, strong, readonly) id<TuyaSmartCameraType> cameraType; // The camera object.

P2P connections

Before live video streaming, a P2P connection must be created. The P2P connection status is subject to your maintenance. The SDK can only send commands to and receive responses from the device.

API description

Create a P2P connection

- (void)p2pConnect;

Close a P2P connection

- (void)p2pDisConnect;

Whether P2P connection is built

- (BOOL)isP2pConnected;

Whether P2P connection in progress

- (BOOL)isP2pConnecting;

Play live video

After a P2P connection is created, live video streaming can be started.

API description

Start live video streaming

- (void)startPreviewWithDefinition:(TuyaSmartCameraDefinition)definition

Stop live video streaming

- (void)stopPreview;

Parameters

Parameter Description
definition The video definition.

Definition modes

Mode Value
Standard definition 0x2
High definition 0x4

Example

[self.lockDevice startPreviewWithDefinition:TuyaSmartCameraDefinitionStandard];

Local recording

During live video streaming or record playback, the ongoing videos can be recorded on a mobile phone.

During video recording, do not switch between video definition modes or modify the audio channel switch and live video talk settings.

Enable video recording

API description

- (void)startRecordWithRotateDirection:(TuyaSmartVideoRotateDirection)direction
                              filePath:(NSString *)filePath;

Video recording requires the read and write permissions of the album.

Parameters

Parameter Description
direction The angle of rotation.
filePath The specified storage directory.

Stop video recording

API description

- (void)stopRecordAndFetchPath;

Whether recording in progress

API description

- (BOOL)isRecording;

Example

    if ([self.lockDevice isRecording]) {
        [self.lockDevice stopRecordAndFetchPath];
    }else{
        [self.lockDevice startRecordWithRotateDirection:TuyaSmartVideoRotateDirectionUp filePath:@"Storage directory"];
    }

Video screenshots

Captures screenshots of live video images. Then, users can store them in the album of a mobile phone.

API description

- (UIImage *)snapShootWithRotateDirection:(TuyaSmartVideoRotateDirection)direction
                              savedAtPath:(NSString *)filePath
                             thumbnilPath:(NSString *)thumbnilPath;

Parameters

Parameter Description
direction The angle of rotation.
filePath The specified storage directory.
thumbnilPath The thumbnail.

Example

[self.lockDevice snapShootWithRotateDirection:TuyaSmartVideoRotateDirectionUp savedAtPath:@"Storage directory" thumbnilPath:nil];

Audio settings

During live video streaming or video playback, the audio channel can be enabled or disabled. By default, it is disabled.

API description

Enables or disables the audio channel.

- (void)enableMute:(BOOL)mute;
Audio mode Value
mute
  • YES: mutes videos.
  • NO: unmutes videos.

Whether to enable audio

- (BOOL)isMuting;

Example

BOOL isMuted = [self.lockDevice isMuting];
[self.lockDevice enableMute:!isMuted];

Live video talk

After a P2P connection is created, the live video talk feature can be enabled to talk to the device. Before the talk, the app must be granted access to the microphone of the mobile phone.

Enable or disable video talks

Transmits audio data from the mobile phone to the device.

- (void)startTalk;

Stops transmitting audio data from the mobile phone to the device.

- (void)stopTalk;

Video talk to be supported or already enabled

Indicates whether the device is processing video talk.

- (BOOL)isTalking;

Indicates whether the device supports video talk.

- (BOOL)isSupportedTalk;
- (BOOL)isTalking;

Example

    BOOL isTalking = [self.lockDevice isTalking];
    BOOL isSupportedTalk = [self.lockDevice isSupportedTalk];

    if (isSupportedTalk) {
        if (isTalking) {
            [self.lockDevice stopTalk];
        }else{
            [self.lockDevice startTalk];
        }
    }

Others

API description

Indicates whether the device is equipped with a pickup. If so, videos from the device are audible.

- (BOOL)isSupportedSound;

API description

Indicates the default video talk mode.

- (TuyaSmartCameraTalkbackMode)supportedAudioMode;