Constructor
new (require("$ui/utils/socket"))(options)
构造函数
Example
const socket = new Socket({
server: WEB_SOCKET_SOCKET
})
socket.$on('open', function () {
socket.send('发送消息')
})
socket.$on('message', function (m) {
console.log('收到信息:' + m)
})
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | 实例化参数 Properties
|
Methods
close()
关闭连接
connect()
建立连接
destroy()
销毁
getState() → {*}
获取WebSocket状态
Returns:
- Type
- *
reconnect()
重新连接
send(message)
发送信息
Parameters:
Name | Type | Description |
---|---|---|
message |
Object | String | 消息内容 |
Events
close
连接关闭触发
error
连接错误触发
message
收到消息触发
Parameters:
Name | Type | Description |
---|---|---|
info |
String | Object | 消息 |
open
连接建立成功触发