yh-websocket
v1.3.16
Published
webpack library example 使用webpack打包自己写的一个JavaScript类库,并上传至NPM
Downloads
23
Readme
yh-websocket
用于内部封装的websocket 类库
简介
this.Client = new WebSocketClass("ip:port/a", {
user: {
token: store.state.user.token,
Id: store.state.user.Id.toString(),
},
receivemessage: this.receivemsg.bind(this.that),
connect: this.ConnectAction,
disconnect: this.DisConnectAction
});
使用方式
- 安装 Using npm:
npm install yh-websocket --save-dev
- 传入回调函数
(1) receivemessage :用于接收消息(Ack 回复以再包内处理)
(2) connect:当im 连接成功时触发
(3) disconnect :当im 连接时触发
- 提供api:
(1) close :关闭当前链接
(2) sendToUser : 发送单个用户消息
let packetMg = {
to: this.touserid,
chatType: this.chattype
}
let uk = this.client.sendToUser(this.msg, packetMg);
this.msg 对象格式参考:http://192.168.100.203:8090/confluence/pages/viewpage.action?pageId=70224898#IM通讯协议汇总-PEER、GROUP聊天消息
- 提供属性:
(1)IsConnected :当前链接状态