Last Updated on : 2024-09-14 06:26:28download
This topic describes the API methods that you can use to implement audio and video capabilities for Wi-Fi locks, for example, live streaming and two-way talk.
Class name | Description |
---|---|
ThingSmartWiFiLockDevice |
Wi-Fi lock operation class, encapsulating audio and video capabilities, inherited from ThingSmartDevice . |
ThingSmartWiFiLockDeviceDelegate |
Wi-Fi lock protocol delegate, extended from ThingSmartDeviceDelegate . |
Delegate
ThingSmartWiFiLockDeviceDelegate
/// Device uploads images DP 212
///
/// @param device The lock
/// @param message The data reported by the lock
- (void)onLockMessageArrived:(ThingSmartWiFiLockDevice *)device
message:(NSDictionary *)message;
/// The callback for live streaming reporting DP 63
///
/// @param device The lock
/// @param model The data reported by the lock
- (void)onVideoRequestRealtime:(ThingSmartWiFiLockDevice *)device
model:(NSString *)model;
/// Report the remote unlocking request image DP 9
///
/// @param device The lock
/// @param time Countdown
- (void)unlockRequestCountdown:(ThingSmartWiFiLockDevice *)device
time:(NSInteger)time;
/// Report the alert image DP 45
///
/// @param device The lock
/// @param time Countdown
- (void)alarmRequestCountdown:(ThingSmartWiFiLockDevice *)device
time:(NSInteger)time;
/// Report the response to remote unlocking DP 50
///
/// @param device The lock
- (void)onRemoteUnlockReport:(ThingSmartWiFiLockDevice *)device;
/// Report the response to force double locking DP 13
///
/// @param device The lock
- (void)onForceLockUpReport:(ThingSmartWiFiLockDevice *)device;
Example
// Initialization
self.lockDevice = [[ThingSmartWiFiLockDevice alloc] initWithDeviceId:self.device.deviceModel.devId];
// Set the delegate
self.lockDevice.delegate = self;
// Remote unlocking request DP 63
- (void)onVideoRequestRealtime:(ThingSmartWiFiLockDevice *)device model:(NSString *)model{
//TODO
}
// Device uploads images DP 212
- (void)onLockMessageArrived:(ThingSmartWiFiLockDevice *)device message:(nonnull NSDictionary *)message{
//TODO
}
// The image for remote unlocking request DP 9
- (void)unlockRequestCountdown:(ThingSmartWiFiLockDevice *)device time:(NSInteger)time{
//TODO
}
// The image for alert request DP 45
- (void)alarmRequestCountdown:(ThingSmartWiFiLockDevice *)device time:(NSInteger)time{
//TODO
}
// Report the response to remote unlocking DP 50
- (void)onRemoteUnlockReport:(ThingSmartWiFiLockDevice *)device{
//TODO
}
// Report the response to force double locking DP 13
- (void)onForceLockUpReport:(ThingSmartWiFiLockDevice *)device{
//TODO
}
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 ThingSuccessBOOL)success
failure:(nullable ThingFailureError)failure;
Parameter description
Parameters | Description |
---|---|
devId | The device ID. |
open | Specifies whether to unlock the door. YES : Unlock. NO : Lock. |
confirm | Specifies whether to accept unlocking. YES : Accept. NO : Reject. |
success | The success callback. |
failure | The failure callback. |
The success
callback only represents a successful API call, which does not guarantee the lock has executed the specified command. When confirm
is YES
, the device status changes. onRemoteUnlockReport
returns the result of the command execution. When confirm
is NO
, the device status does not change, with no data reported. In this case, the success
callback can indicate that a rejection command is executed.
Example
[self.lockDevice remoteLockWithDevId:devId
open:YES
confirm:NO
success:^(BOOL result) {
//TODO
} failure:^(NSError *error) {
//TODO
}];
API description
The device captures an image, uploads it to the cloud storage, and then reports the image path through onLockMessageArrived
.
Do not call this method more than once within a 15-second interval.
- (void)reTakePhoto:(BOOL)needTake
success:(ThingSuccessHandler)success
failure:(ThingFailureError)failure;
Parameter description
Parameters | 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
}];
API description
Force double lock the door. onForceLockUpReport
returns the result on success.
- (void)enforceLock:(BOOL)needLock
success:(ThingSuccessHandler)success
failure:(ThingFailureError)failure;
Parameter description
Parameters | Description |
---|---|
needLock | Specifies whether to implement force double locking. |
success | The success callback. |
failure | The failure callback. |
Example
[self.lockDevice enforceLock:YES
success:^{
//TODO
} failure:^(NSError *error) {
//TODO
}];
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 ThingSuccessID)success
failure:(nullable ThingFailureError)failure;
Parameter description
Parameters | Description |
---|---|
devId | The device ID. |
fileType | The type of image.
|
success | The success callback. |
failure | The failure callback. |
Return values
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
}];
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 ThingSuccessID)success
failure:(nullable ThingFailureError)failure;
Parameter description
Parameters | 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 values
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 Developer Platform. Valid values: 0, 90, 180, and 270. |
Note
fileUrl
is 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
// Query 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) {
}];
// Get the image after decrypting the image URL.
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
}];
Property description
@property (nonatomic, strong, readonly) UIView *videoView;
Example
// Initialization
self.lockDevice = [[ThingSmartWiFiLockDevice alloc] initWithDeviceId:self.device.deviceModel.devId];
// Set the delegate
self.lockDevice.delegate = self;
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
- (void)p2pConnect;
- (void)p2pDisConnect;
- (BOOL)isP2pConnected;
- (BOOL)isP2pConnecting;
After a P2P connection is created, live video streaming can be started.
API description
- (void)startPreviewWithDefinition:(NSInteger)definition
success:(ThingSuccessHandler)success
failure:(ThingFailureError)failure;
- (void)stopPreview;
Parameter description
Parameters | Description |
---|---|
definition | The video definition mode. |
success | The success callback. |
failure | The failure callback. |
The video definition mode.
Mode | Value |
---|---|
Standard definition (SD) | 0x2 |
High definition (HD) | 0x4 |
Example
[self.lockDevice startPreviewWithDefinition:0x2
success:^{
//TODO
} failure:^(NSError *error) {
//TODO
}];
[self.lockDevice stopPreview];
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 two-way talk settings.
API description
- (void)startRecordWithRotateDirection:(ThingSmartVideoRotateDirection)direction
filePath:(NSString *)filePath;
Video recording requires the read and write permissions of the album.
Parameter description
Parameters | Description |
---|---|
direction | The angle of rotation. |
filePath | The specified storage directory. |
API description
- (void)stopRecordAndFetchPath;
Callback parameter description
On success, the callback returns the video storage path (path
) and binary video stream (data
).
API description
- (BOOL)isRecording;
Example
if ([self.lockDevice isRecording]) {
[self.lockDevice stopRecordAndFetchPath];
}else{
[self.lockDevice startRecordWithRotateDirection:ThingSmartVideoRotateDirectionRight
filePath:filePath];
}
After screenshot
API description
- (UIImage *)snapShootWithRotateDirection:(ThingSmartVideoRotateDirection)direction
savedAtPath:(NSString *)filePath
thumbnilPath:(NSString *)thumbnilPath;
Parameter description
Parameters | Description |
---|---|
direction | The angle of rotation. |
filePath | The specified storage directory. |
thumbnilPath | The success callback. |
Callback parameter description
On success, the callback returns the image storage path (path
) and binary image stream (data
).
Example
[self.lockDevice snapShootWithRotateDirection:ThingSmartVideoRotateDirectionRight
savedAtPath:path
thumbnilPath:thumbnilPath];
During video streaming or playback, the audio channel can be turned on or off. By default, audio is muted.
API description
Turn on/off audio channel
- (void)enableMute:(BOOL)mute;
Audio mode | Value |
---|---|
mute | YES : Turn on mute. NO : Turn off mute. |
- (BOOL)isMuting;
Example
BOOL isMuted = [self.lockDevice isMuting];
[self.lockDevice enableMute:!isMuted];
After a P2P connection is created, a two-way talk with the device can be turned on. Before the talk, the app must be granted access to the microphone of the mobile phone.
Turn on or off transmission of audio data from the mobile phone to the device.
- (void)startTalk;
- (void)stopTalk;
- (BOOL)isSupportedTalk;
- (BOOL)isTalking;
Example
BOOL isTalking = [self.lockDevice isTalking];
BOOL isSupportedTalk = [self.lockDevice isSupportedTalk];
Indicates whether the device is equipped with a pickup. If so, the video from the device has sound.
API description
- (BOOL)isSupportedSound;
Returns the default two-way talk mode.
API description
- (ThingSmartCameraTalkbackMode)supportedAudioMode;
Example
BOOL isSupportedSound = [self.lockDevice isSupportedSound];
ThingSmartCameraTalkbackMode mode = [self.lockDevice supportedAudioMode];
API description
Get the cameraType
of the ThingSmartWiFiLockDevice
object, and then call the setAudioEffectType
method in ThingSmartCameraType
to set up a custom audio effect. For more information, see Custom audio effect.
- (int)setAudioEffectType:(ThingCameraAudioEffectType)audioEffectType;
API description
Destroys the allocated resource if a feature is not used. This helps to avoid possible errors. Get the cameraType
of the ThingSmartWiFiLockDevice
object, and then call the destroy
method in ThingSmartCameraType
.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback