DeviceMethodResponse class

a DeviceMethodResponse object is provided to the user with each DeviceMethodRequest allowing the user to construct and send a well-formatted response back to the service for each device method call. An instance of this class is passed as the second parameter to the callback registered via onDeviceMethod(string, (request: DeviceMethodRequest, response: DeviceMethodResponse) => void).

Constructors

DeviceMethodResponse(string, DeviceTransport)

Properties

isResponseComplete

Boolean indicating whether the response has been sent already.

payload

The payload of the response, sent back to the caller on the service side.

requestId

The request identifier supplied by the service for this device method call.

status

Status code indicating whether the method succeeded (200) or not (any other number that is not 200).

Methods

send(number, any)
send(number, any, ErrorCallback)

Sends the device method's response back to the service via the underlying transport object using the status parameter as the status of the method call.

send(number, ErrorCallback)

Constructor Details

DeviceMethodResponse(string, DeviceTransport)

new DeviceMethodResponse(requestId: string, transport: DeviceTransport)

Parameters

requestId

string

transport
DeviceTransport

Property Details

isResponseComplete

Boolean indicating whether the response has been sent already.

isResponseComplete: boolean

Property Value

boolean

payload

The payload of the response, sent back to the caller on the service side.

payload: any

Property Value

any

requestId

The request identifier supplied by the service for this device method call.

requestId: string

Property Value

string

status

Status code indicating whether the method succeeded (200) or not (any other number that is not 200).

status: number

Property Value

number

Method Details

send(number, any)

function send(status: number, payload?: any): Promise<void>

Parameters

status

number

payload

any

Returns

Promise<void>

send(number, any, ErrorCallback)

Sends the device method's response back to the service via the underlying transport object using the status parameter as the status of the method call.

function send(status: number, payload?: any, done?: ErrorCallback)

Parameters

status

number

A numeric status code to be sent back to the service.

payload

any

[optional] The payload of the method response.

done

ErrorCallback

[optional] A callback function which will be called once the response has been sent back to the service. An error object is passed as an argument to the function in case an error occurs. If callback is not specified, a Promise will be returned.

send(number, ErrorCallback)

function send(status: number, done: ErrorCallback)

Parameters

status

number

done

ErrorCallback