1.1.13 • Published 4 years ago

wbs-sdk v1.1.13

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

引入

npm install wbs-sdk

使用

  const DsSocket = require('wbs-sdk')
  
  // 注册实例  
  const options = { // todo 这些默认可以不填写
     header:{ // 模拟一些 ua

     },
     apiHost:'', //
     wssHost:'',
     heartTime:60000, // wbs心跳时间,默认60000
  }
  const Ds = new DsSocket(options) 
  // 初始化,init成功会返回
  const initOptions = {
    channel:'007',
    to:'996', 
    source:2
  })
  const instance = Ds.init(initOptions,type?) // 参数type='http'时启动http轮询模式,默认websocket模式
  // instance如果是websoket

  // 发送消息
  Ds.send('4396')
  // 收到消息
  Ds.message((res)=>{
      
      //  返回格式
      { 
          "status":0,
          "data":{ // 
              "socketReadyState":1,
              "errorStep":-10000,
              "error":null,
              "wbs":[ // socket状态服务 onmessage响应的完整数据
                  {
                      "source":"2",
                      "channel":"9214",
                      "rectype":"C2C",
                      "msgtype":"TEXT",
                      "to":9214,
                      "content":"{"time":1592414438752,"status":2}", // 后台推给状态服务的信息,然后推给前台
                      "send":1,
                      "timestamp":1592414438,
                      "rand":1159,
                      "sequence":21
                  }
              ]
          },
          "message":"success"
      }

  })
  // 错误回调
  Ds.error((err)=>{
      //  返回格式
      {
          "status":1,
          "data":{
              "socketReadyState":1,
              "errorStep":-10000,
              "error":'xxxxx',
              "wbs": null //
          },
         "message":"error"
      }
    console.log('错误了❌',err)
  })
  const state =  Ds.geState()
  // 关闭链接
  Ds.close()

版本更新记录

  • 1.1.3: 新增http长轮询机制
  • 1.1.4: 增加host配置 apiHost,wssHost
1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.10

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago