yh-websocket

1.3.16 • Public • Published

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
    });

使用方式

  1. 安装 Using npm:
npm install yh-websocket --save-dev
  1. 传入回调函数
  (1) receivemessage :用于接收消息(Ack 回复以再包内处理)
  (2) connect:当im 连接成功时触发
  (3) disconnect :当im 连接时触发
  1. 提供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. 提供属性:
  (1)IsConnected :当前链接状态

Readme

Keywords

Package Sidebar

Install

npm i yh-websocket

Weekly Downloads

6

Version

1.3.16

License

MIT

Unpacked Size

858 kB

Total Files

118

Last publish

Collaborators

  • page317