有奖捉虫:办公协同&微信生态&物联网文档专题 HOT

监听事件

接口定义
sdk.on(type: string, listener: (...args) => void) => void
参数说明
参数名
参数描述
类型
type
要监听的事件。
string
listener
事件触发时的回调函数。
(...args) => void

取消监听事件

接口定义
sdk.off(type: string, listener: (...args) => void) => void
参数说明
参数名
参数描述
类型
type
要取消监听的事件。
string
listener
要取消监听的事件的回调函数,不传则清除该事件的所有回调函数。
(...args) => void

WebSocket 事件

wsClose 事件

WebSocket 的 close 事件。
参数名
参数描述
类型
code
服务器发送的关闭码
number
reason
服务器关闭连接的原因
string

wsError 事件

WebSocket 的错误事件

wsControl 事件

当 WebSocket 收到 control 指令后触发。
参数名
参数描述
类型
deviceId
设备 ID
string
deviceData
设备数据
object

wsReport 事件

当 WebSocket 收到 report 指令后触发。
参数名
参数描述
类型
deviceId
设备 ID
string
deviceData
设备数据
object

wsStatusChange 事件

当 WebSocket 收到 wsStatusChange 指令后触发。
参数名
参数描述
类型
deviceId
设备 ID
string
deviceStatus
设备在线状态,0离线,1在线
number

wsEventReport 事件

当 WebSocket 收到 wsEventReport 指令后触发。
参数名
参数描述
类型
deviceId
设备 ID
string
Payload
设备回复详情
object

wsActionPush 事件

当 WebSocket 收到 wsActionPush 指令后触发。
参数名
参数描述
类型
deviceId
设备 ID
string
Payload
下发的 Action 指定详情
object

wsActionReport 事件

当 WebSocket 收到 wsActionReport 指令后触发。
参数名
参数描述
类型
deviceId
设备 ID
string
Payload
设备回复的 Action 响应详情
object

前后台切换事件

appShow 事件

当小程序 App.onShow 执行后触发。

appHide 事件

当小程序 App.onHide 执行后触发。

pageShow 事件

当小程序 Page.onShow 执行后触发。

pageHide 事件

当小程序 Page.onHide 执行后触发。