Doorbell Call Service

Last Updated on : 2023-05-22 06:38:31download

A doorbell can be bound with a home and stay online on your app. In this case, if the doorbell is pressed, IPC SDK receives a doorbell call event. Doorbell call operations are implemented with the management class. For example, listen for changes on the doorbell call status, and answer, hang up or reject calls.

To implement video streaming during doorbell calls, the live video streaming API methods must also be integrated.

Query the doorbell call management class

Example

ObjC:

TuyaSmartDoorBellManager *manager = [TuyaSmartDoorBellManager sharedInstance];

Swift:

let manager = TuyaSmartDoorBellManager.sharedInstance()

Doorbell call models

Doorbell calls are encapsulated by the model class TuyaSmartDoorBellCallModel. This class is used to store information about doorbell calls and maintain the doorbell call status. Each doorbell call is assigned a unique message ID indicated by messageId and matches a model indicated by TuyaSmartDoorBellCallModel.

Parameter Description
type The type of doorbell call. Valid values:
  • doorbell
  • ac_doorbell
  • Custom type
devId The device ID.
messageId The unique identifier of a doorbell call notification.
time The Unix timestamp when a doorbell call is triggered. Unit: seconds.
answeredBySelf Indicates whether the doorbell call is answered by the device owner.
answeredByOther Indicates whether the doorbell call is answered by other users.
canceled Indicates whether the doorbell call is canceled.

Query doorbell call models

To get the status of a doorbell call, use the model TuyaSmartDoorBellCallModel to return the target instance of TuyaSmartDoorBellCallModel.

API description

- (TuyaSmartDoorBellCallModel *)callModelWithMessageId:(NSString *)messageId;

Parameters

Parameter Description
messageId The unique identifier of a doorbell call notification.

Register a doorbell call listener

The app process must be active before the listener can be effective. If the app process runs in the background or is terminated, the listener becomes invalid.

API description

- (void)addObserver:(id<TuyaSmartDoorBellObserver>)observer;

Parameters

Parameter Description
TuyaSmartDoorBellObserver The doorbell call listener.

TuyaSmartDoorBellObserver

The doorbell call listener involves the callbacks throughout the life cycle of doorbell calls. The following table describes these callbacks.

API name Parameter list Return value Description
didReceivedFromDevice TuyaSmartDoorBellCallModel, TuyaSmartDeviceModel void The doorbell call event from the device is received.
doorBellCallDidHangUp TuyaSmartDoorBellCallModel void The doorbell call is hung up on the device.
doorBellCallDidAnsweredByOther TuyaSmartDoorBellCallModel void The doorbell call is answered by other users. The service layer determines whether to automatically cancel or hold the call.
  • To reject the call, call the refuseDoorBellCall API method and end the call.
  • To hold the call, the device owner can pick up and listen to the ongoing call that is being answered by another user but cannot talk through the call.
    doorBellCallDidAnswered TuyaSmartDoorBellCallModel void The doorbell call has been answered.
    doorBellCallDidCanceled TuyaSmartDoorBellCallModel, BOOL void The doorbell call is canceled. The parameter isTimeOut indicates whether the call is automatically canceled due to timeout or manually canceled on the device.
    doorBellCallDidRefuse TuyaSmartDoorBellCallModel void The doorbell call is rejected.

    When the doorbell call event didReceivedFromDevice from the device is received, we recommend that you save the object TuyaSmartDoorBellCallModel or the doorbell call identifier messageId. Either will be required in the API request to answer, hang up, or reject calls.

    Example

    ObjC:

    @interface CameraDoorbellManager ()<TuyaSmartDoorBellObserver>
    @property (nonatomic, copy) NSString *messageId;
    @end
    
    @implementation CameraDoorbellManager
    
    - (void)doorBellCall:(TuyaSmartDoorBellCallModel *)callModel didReceivedFromDevice:(TuyaSmartDeviceModel *)deviceModel {
        self.messageId = callModel.messageId;
    }
    
    - (void)doorBellCallDidRefuse:(TuyaSmartDoorBellCallModel *)callModel {
    
    }
    
    - (void)doorBellCallDidHangUp:(TuyaSmartDoorBellCallModel *)callModel {
    
    }
    
    - (void)doorBellCallDidAnsweredByOther:(TuyaSmartDoorBellCallModel *)callModel {
    
    }
    
    - (void)doorBellCallDidAnswered:(TuyaSmartDoorBellCallModel *)callModel {
    
    }
    
    - (void)doorBellCallDidCanceled:(TuyaSmartDoorBellCallModel *)callModel timeOut:(BOOL)isTimeOut {
    
    }
    
    @end
    

    Swift:

    class DoorbellManager: NSObject {
        let manager = TuyaSmartDoorBellManager.sharedInstance()
        var messageId:String = ""
    }
    
    extension DoorbellManager:TuyaSmartDoorBellObserver {
        func doorBellCall(_ callModel: TuyaSmartDoorBellCallModel!, didReceivedFromDevice deviceModel: TuyaSmartDeviceModel!) {
            messageId = callModel.messageId
        }
    
        func doorBellCallDidRefuse(_ callModel: TuyaSmartDoorBellCallModel!) {
    
        }
    
        func doorBellCallDidHangUp(_ callModel: TuyaSmartDoorBellCallModel!) {
    
        }
    
        func doorBellCallDidAnswered(byOther callModel: TuyaSmartDoorBellCallModel!) {
    
        }
    
        func doorBellCallDidCanceled(_ callModel: TuyaSmartDoorBellCallModel!, timeOut isTimeOut: Bool) {
    
        }
    }
    

    Remove a doorbell call listener

    Removes a doorbell call listener if it is not required.

    API description

    - (void)removeObserver:(id<TuyaSmartDoorBellObserver>)observer;
    

    Example

    ObjC:

    [[TuyaSmartDoorBellManager sharedInstance] removeObserver:self];
    

    Swift:

    TuyaSmartDoorBellManager.sharedInstance()?.remove(self)
    

    Ignore calls following an ongoing call on the same device

    Specifies whether to ignore subsequent calls when a call is being answered on the same device.

    Property description

    @property (nonatomic, assign) BOOL ignoreWhenCalling;
    
    Property Description
    ignoreWhenCalling
    • YES: automatically ignores subsequent calls when a call is being answered on the same device.
    • NO: does not ignore calls following an ongoing call on the same device.
    Default value: YES.

    Set a timeout value for doorbell calls

    Sets a timeout value for doorbell calls. If a doorbell call is not processed within the specified period, the callback doorBellCallDidCanceled is executed to send a notification and end this call.

    Property description

    @property (nonatomic, assign) NSInteger doorbellRingTimeOut;
    
    Property Description
    doorbellRingTimeOut The timeout value of doorbell calls. Unit: seconds. Default value: 25.

    Answer a doorbell call

    Answers a doorbell call after it is received. The call might fail to be answered because it is being answered or canceled, or due to other reasons. In the case of failure to answer a call, the failure reason is returned as an error message. For more information, see Error codes.

    API description

    - (TYDoorBellError)answerDoorBellCall:(NSString *)messageId;
    

    Example

    ObjC:

    [[TuyaSmartDoorBellManager sharedInstance] answerDoorBellCall:self.messageId];
    

    Swift:

    TuyaSmartDoorBellManager.sharedInstance()?.answerDoorBellCall(messageId)
    

    Reject a doorbell call

    Rejects a doorbell call after it is received.

    API description

    - (void)refuseDoorBellCall:(NSString *)messageId;
    

    Example

    ObjC:

    [[TuyaSmartDoorBellManager sharedInstance] refuseDoorBellCall:self.messageId];
    

    Swift:

    TuyaSmartDoorBellManager.sharedInstance()?.refuseDoorBellCall(messageId)
    

    Hang up a doorbell call

    Hangs up a doorbell call after it is received. The call might fail to be hung up because it is not answered or due to other reasons. In the case of failure to hang up a call, the failure reason is returned as an error message. For more information, see Error codes.

    API description

    - (TYDoorBellError)hangupDoorBellCall:(NSString *)messageId;
    

    Example

    ObjC:

    [[TuyaSmartDoorBellManager sharedInstance] hangupDoorBellCall:self.messageId];
    

    Swift:

    TuyaSmartDoorBellManager.sharedInstance()?.hangupDoorBellCall(messageId)
    

    Process other types of doorbell calls

    Processes doorbell calls that are received on the app by means such as push notifications, rather than MQTT. A doorbell call model is generated based on the parameters passed in to implement subsequent operations. For example, answer, hang up, or reject the doorbell call.

    API description

    - (void)generateCall:(NSDictionary *)params;
    

    Parameters

    Parameter Description
    params The received doorbell call notification.

    Error codes

    Error code Description
    0 The operation is successful without errors.
    -1001 A doorbell call is being answered by another user when the API method is called to answer the call.
    -1002 The doorbell call has been canceled on the device.
    -1003 The doorbell call timed out.
    -1004 The doorbell call has been answered.
    -1005 A doorbell call is not answered when the API method is called to hang up the call.
    -1006 The device type such as doorbell is not supported.
    -1007 The parameters are invalid.