npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dao-im-sdk

v1.0.4

Published

基于WebSocket的封装

Downloads

3

Readme

dao-im-sdk guide

Install&Usage (安装&使用)

# Install(安装)
npm install --save dao-im-sdk

# Usage(使用)
//浏览器
<script src="//unpkg.com/[email protected]/index.js"></script>
<script> console.log(imsdk);</script>

//ES6
import imsdk from 'dao-im-sdk'

// commonjs
const imsdk = require('dao-im-sdk')

发送消息格式

{
  "code": "USER_INFO",  # 事件码(必填项)
  "data": "xxxxxxx",    # 发送给服务器数据(aes加密)
  "mes": "获取用户信息" # 操作说明
}

返回消息格式

{
  "code": "USER_INFO",  # 事件码
  "data": "xxxxxxxxx",  # 响应的数据(first为true时使用ras解密,否则aes解密)
  "first": false,       # 是否是创建连接以来第一次响应数据
  "mes": "获取用户信息",# 提示信息(status 为false时可能需要展示给用户看)
  "status": true        # 本次操作状态 true成功,false失败
}

Api 使用指南

imsdk类,IM即时通讯SDK.

new imsdk(url, wsUrl, wsConfig, pingTimeout, pongTimeout, reconnectTimeout, pingMsg, repeatLimit, isEncrypt, theme)

options 传入参数

| Name| Type| Description| | :--|:--|:--| | url | String | http链接地址.| | wsUrl | String | websocket链接地址.| | wsConfig | Object | websocket 参数配置.| | pingTimeout | Number | 未收到消息多少秒之后发送ping请求,默认15000毫秒.| | pongTimeout | Number | 发送ping之后,未收到消息超时时间,默认10000毫秒.| | reconnectTimeout | Number | 重连等待时间,默认2000毫秒.| | pingMsg | String | 心跳检测默认值,默认ping.| | repeatLimit | Number | 最大重连次数.| | isEncrypt | Boolean | 是否启用RSA/AES加密(注意:启用需要后端配合开发).| | theme| Object | 主题皮肤(窗口配置).|

Methods 方法

| Name| Type| Description| | :--|:--|:--| |callback()|Object|callback 操作回调监听(含onmessage、onclose、onopen、onreconnect、onerror等)| |close()|Object|关闭webocket连接| |onclose()|Object|websocket关闭监听| |onerror()|Object|websocket错误监听| |onmessage()|Object|websocket通知消息监听| |onopen()|Object|websocket打开监听| |onreconnect()|Object|websocket断线重连监听| |onSend()|Object|websocket 发送消息方法(传入Object(固定格式的参数))| |setAesIv(iv)|String|设置AES偏移量(默认为ABCDEF1234123412)| |setAesKey(key)|String|设置aes密钥| |setRsaPrivateKey(key)|String|设置rsa私钥| |setRsaPublicKey(key)|String|设置rsa公钥| |formatData()|Object|解析onMessage Data接受的数据(后端websocket推送的内容解密)| |formatDataSend()|Object|编码onSend Data发送的数据(前端websocket推送的内容加密)| |getRSAWsConfig()|String|获取ws配置的RSA加密串(根据wsConfig传入的参数生成RSA加密串)| |getRSAWsConfigBase64()|String|获取ws配置的RSA加密串base64编码(根据wsConfig传入的参数生成RSA加密串(进行BASE64编码))|

传入参数

//zd  0:小程序 1:PC 2:手机WEB -1:银行端APP
//lx  1:企业用户, 2:个人用户,3:银行, 4:平台客服
//ws://20.168.1.234:8085/ws?p=(sessionId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&zd=1&lx=1)
//--------------------------------------------
 var mesMap = {
    PING_PONG: "检测心跳",
    NEW_MESSAGE: "新消息",
    USER_INFO: "获取用户信息",
    READ_MESSAGE: "读消息",
    SEND_MESSAGE: "发送消息",
    UPDATE_KEY: "更新rsa key",
    SERVER_ERROR: "服务器错误",
    HISTORY_LIST: "获取历史会话列表",
    REMOVE_MESSAGE: "移除会话消息",
    RECEIVE_MESSAGE_STATUS: "消息状态",
    HISTORY_MESSAGE_LIST: "获取历史消息列表",
    UNREAD_MESSAGE_TOTAL: "获取该用户未读消息总数",
  };
//初始化实例
let im = new imsdk({
      isEncrypt:true,
      wsUrl:"ws://127.0.0.1:3001",
      wsConfig: {
        zd: -1,
        lx: 1,
        token: "66a33a46-5031-42bd-b624-8460036d28e6",
        t: new Date().getTime(),
      }
  });
im.callback = function (e) {
  console.log("callback监听()=>", e);
  if(e.event==="onmessage"){
    console.log("onmessage=>",e.data)
  }else{
    console.log("callback=>",e)
  }
}

// 初始化更新
if (event === "onmessage" && data.code != "PING_PONG") {
  for (const i in mesMap) {
    if (mesMap.hasOwnProperty(i)) {
      const el = mesMap[i];
      if (data.code === "UPDATE_KEY") {
        im.setAesKey(data.data);
      }
      if (data.code === i) {
        console.log("【" + el + "=>】", data.data || null);
      }
    }
  }
}


# 下面无关紧要的代码
//自动生成事件绑定
 var getId = function (id) {
    return document.getElementById(id);
  };
  var html = "";
  for (const i in mesMap) {
    if (mesMap.hasOwnProperty(i)) {
      const el = mesMap[i];
      html +=
        '<button style="margin-bottom:10px" id="' +
        i +
        '">' +
        el +
        "</button></br>";
    }
  }
  getId("examples").innerHTML = html;
  var btns = getId("examples").querySelectorAll("button");
  for (let i = 0; i < btns.length; i++) {
    btns[i].onclick = function (e) {
      // console.log(e.target.id, e.target.innerHTML);
      var code = e.target.id;
      if(code==="pong"){
        im.onSend("pong");
      }
      im.onSend({
        code: code,
        data: { text: e.target.innerHTML },
        mes: "",
        //user:code!="PING_PONG" && "MqZNRtRIS0K7Al13SbBXSQ==" || "" //无关紧要的代码
      });
    };
  }