Wi-Fi 门锁音视频能力

更新时间:2023-11-29 10:21:57下载pdf

门锁音视频能力接口支持可视门锁、拍照锁的实时视频查看、对讲等功能。

功能简介

类名 说明
ThingSmartWiFiLockDevice 封装了音视频能力的Wi-Fi 门锁设备操作类,继承自 ThingSmartDevice
ThingSmartWiFiLockDeviceDelegate Wi-Fi 门锁设备协议代理,拓展自 ThingSmartDeviceDelegate

代理说明

ThingSmartWiFiLockDeviceDelegate:

/// 设备传图数据上报 dp212
///
/// @param device 门锁设备
/// @param message 设备上报的数据
- (void)onLockMessageArrived:(ThingSmartWiFiLockDevice *)device
                     message:(NSDictionary *)message;

/// 实时视频上报回调 dp63
///
/// @param device 门锁设备
/// @param model 设备上报的数据
- (void)onVideoRequestRealtime:(ThingSmartWiFiLockDevice *)device
                         model:(NSString *)model;

/// 远程开门请求图片上报 dp9
///
/// @param device 门锁设备
/// @param time 倒计时数据
- (void)unlockRequestCountdown:(ThingSmartWiFiLockDevice *)device
                          time:(NSInteger)time;

/// 告警请求图片上报 dp45
///
/// @param device 门锁设备
/// @param time 倒计时数据
- (void)alarmRequestCountdown:(ThingSmartWiFiLockDevice *)device
                         time:(NSInteger)time;

/// 远程开门回复上报 dp50
///
/// @param device 门锁设备
- (void)onRemoteUnlockReport:(ThingSmartWiFiLockDevice *)device;

/// 强制反锁回复上报 dp13
///
/// @param device 门锁设备
- (void)onForceLockUpReport:(ThingSmartWiFiLockDevice *)device;

示例代码

//初始化
self.lockDevice = [[ThingSmartWiFiLockDevice alloc] initWithDeviceId:self.device.deviceModel.devId];
//设置代理
self.lockDevice.delegate = self;

//远程请求开门 dp63
- (void)onVideoRequestRealtime:(ThingSmartWiFiLockDevice *)device model:(NSString *)model{
    //TODO
}

//设备传图数据 dp212
- (void)onLockMessageArrived:(ThingSmartWiFiLockDevice *)device message:(nonnull NSDictionary *)message{
    //TODO
}

//远程开门请求图片 dp9
- (void)unlockRequestCountdown:(ThingSmartWiFiLockDevice *)device time:(NSInteger)time{
    //TODO    
}

//告警请求图片 dp45
- (void)alarmRequestCountdown:(ThingSmartWiFiLockDevice *)device time:(NSInteger)time{
    //TODO
}

//远程开门回复上报 dp50
- (void)onRemoteUnlockReport:(ThingSmartWiFiLockDevice *)device{
    //TODO
}

//强制反锁回复上报 dp13
- (void)onForceLockUpReport:(ThingSmartWiFiLockDevice *)device{
    //TODO
}

远程开锁

接口说明

通过此接口可以实现远程开锁、关锁、拒绝开锁、拒绝关锁。

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

参数说明

参数 说明
devId 设备ID
open 开门还是关门,YES:开门,NO:关门
confirm 允许还是拒绝,YES:允许,NO:拒绝
success 接口成功回调
failure 接口失败回调

提示

success 回调只能表示接口调用成功,不能作为门锁设备执行指令判断标准,confirm = YES 的情况下设备状态发生变化(开锁、关锁),设备执行成功后依赖监听方法 onRemoteUnlockReport 回调结果。confirm=NO 的情况设备状态没有产生变化,不会上报 DP,success 可以认为拒绝开锁/拒绝关锁执行成功。

示例代码

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

重新拍照

接口说明

重新拍照,设备会把抓拍的图片传到云存储,并上报通过 onLockMessageArrived 上报图片路径信息。

防抖处理,15s 内别重复调用。

- (void)reTakePhoto:(BOOL)needTake
            success:(ThingSuccessHandler)success
            failure:(ThingFailureError)failure;

参数说明

参数 说明
needTake 是否重新拍照
success 接口成功回调
failure 接口失败回调

示例代码

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

强制反锁

接口说明

强制反锁,设备执行成功会通过 onForceLockUpReport 回调结果。

- (void)enforceLock:(BOOL)needLock
            success:(ThingSuccessHandler)success
            failure:(ThingFailureError)failure;

参数说明

参数 说明
needLock 是否强制反锁
success 接口成功回调
failure 接口失败回调

示例代码

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

获取最新的图片地址信息

接口说明

获取云存储上最新的一张图片信息。需要配合接口 getPopupPictureAddressWithDevId 一起使用。

- (void)getLatestPopupInfoWithDevId:(NSString *)devId
                           fileType:(NSInteger)fileType
                            success:(nullable ThingSuccessID)success
                            failure:(nullable ThingFailureError)failure;

参数说明

参数 说明
devId 设备 ID
fileType 图片类型:远程解锁抓拍图片,告警抓拍图片
success 接口成功回调
failure 接口失败回调

返回值说明

字段 说明
filePath 图片在云存储的路径
fileKey 解密 key
bucket 云存储 bucket

示例代码

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

获取抓拍图片地址

接口说明

设备抓拍的图片会上传到云存储,通过此接口获取图片的地址。和监听回调 onLockMessageArrived 方法或 getLatestPicture 配合使用。

- (void)getPopupPictureAddressWithDevId:(NSString *)devId
                                 bucket:(NSString *)bucket
                               filePath:(NSString *)filePath
                               success:(nullable ThingSuccessID)success
                               failure:(nullable ThingFailureError)failure;

参数说明

参数 说明
devId 设备 ID
bucket 云存储 bucket
filePath 云存储加密 url
success 接口成功回调
failure 接口失败回调

返回值说明

字段 说明
fileUrl 图片在云存储的路径
mediaUrl 视频在云存储的路径
angle 角度,在 IoT 平台配置的角度旋转,值有 0、90、180、270

注意

fileUrl 仍然是加密链接,需要 onLockMessageArrivedgetLatestPopupInfoWithDevId 获取 fileKey 解密。涂鸦提供控件 TYEncryptImage 负责解密和显示图像。

示例代码

//查询封面图地址
[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) {
            
        }];

//解密图片链接后获取 image
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 (nonatomic, strong, readonly) UIView *videoView;

注册 P2P 监听

示例代码

//初始化
self.lockDevice = [[ThingSmartWiFiLockDevice alloc] initWithDeviceId:self.device.deviceModel.devId];
//设置代理
self.lockDevice.delegate = self;

P2P 连接

在开始视频播放之前,需要先连接 P2P 通道。P2P 状态需要使用者自己维护,SDK 只负责下发指令和接收摄像机响应结果。

接口说明

连接 P2P 通道

- (void)p2pConnect;

断开 P2P 通道

- (void)p2pDisConnect;

是否已连上

- (BOOL)isP2pConnected;

是否在连接中

- (BOOL)isP2pConnecting;

实时播放视频

P2P连接成功之后,就能进行实时视频播放了。

接口说明

开始播放实时视频

- (void)startPreviewWithDefinition:(NSInteger)definition
                           success:(ThingSuccessHandler)success
                           failure:(ThingFailureError)failure;

停止播放实时视频

- (void)stopPreview;

参数说明

参数 说明
definition 清晰度模式
success 接口成功回调
failure 接口失败回调

清晰度模式

模式
标清 0x2
高清 0x4

示例代码

[self.lockDevice startPreviewWithDefinition:0x2 
 																		success:^{
                        //TODO
            											} failure:^(NSError *error) {
                        //TODO
}];

[self.lockDevice stopPreview];

本地录制

当视频成功开始播放以后(可以是视频直播,也可以是录像回放),可以将当前正在播放的视频录制到手机中。

在视频录制的过程中,请不要再切换视频清晰度,开关声音及对讲。

开启视频录制

接口说明

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

录制视频需要相册读写权限。

参数说明

参数 说明
direction 旋转角度
filePath 指定存储目录

停止录制视频

接口说明

- (void)stopRecordAndFetchPath;

回调参数说明

停止录制会返回两条数据:视频存放路径和视频二进制数据流,分别通过 key path data 获取对应 value。

是否在录制视频

接口说明

- (BOOL)isRecording;

示例代码

if ([self.lockDevice isRecording]) {
        [self.lockDevice stopRecordAndFetchPath];
    }else{
        [self.lockDevice startRecordWithRotateDirection:ThingSmartVideoRotateDirectionRight
															 filePath:filePath];
    }

视频截图

截取实时视频的图片后

接口说明

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

参数说明

参数 说明
direction 旋转角度
filePath 指定存储目录
thumbnilPath 接口成功回调

回调参数说明

截屏成功返回两条数据:图片存放路径和图片二进制数据流,分别通过 key path data 获取对应 value。

示例代码

[self.lockDevice snapShootWithRotateDirection:ThingSmartVideoRotateDirectionRight
                                         savedAtPath:path
                                        thumbnilPath:thumbnilPath];

视频声音

当视频成功开始播放以后,可以开启视频声音,默认声音是关闭状态。

接口说明

开启/关闭视频声音

- (void)enableMute:(BOOL)mute;
音频模式
mute YES:开启静音,NO:关闭静音

是否开启声音

- (BOOL)isMuting;

示例代码

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

实时对讲

在 P2P 连接成功后,可以开启与设备的实时通话功能。在开始对讲前,需要确保 App 已获得手机麦克风的访问权限。

开启对讲/关闭对讲

打开/关闭手机声音传输给摄像机操作。

- (void)startTalk;
- (void)stopTalk;

是否支持对讲/是否已开启对讲

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

示例代码

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

其他

设备是否有拾音器。若设备配置有拾音器,表示设备的视频有声音。

接口说明

- (BOOL)isSupportedSound;

获取默认的对讲方式。

接口说明

- (ThingSmartCameraTalkbackMode)supportedAudioMode;

示例代码

BOOL isSupportedSound = [self.lockDevice isSupportedSound];
ThingSmartCameraTalkbackMode mode = [self.lockDevice supportedAudioMode];

销毁

接口说明

当不再使用相关功能时,调用销毁方法,避免程序发生异常。拿到 ThingSmartWiFiLockDevice 对象 cameraType 属性,调用属性协议 ThingSmartCameraType 方法 destory 进行销毁。