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

uno-ws-client

v0.2.2

Published

websocket客户端

Downloads

12

Readme

Installation

npm install uno-ws-client --save

Usage

import { Ws, SDKBase } from '@ali/ws-client';

const ws = new Ws('wss://pre-citybrain-open.aliyun.com/app/space-ws/ws', {
  // autoConnect: true,
  registerData: {
    source: 'web1',
    target: ['UE'],
    data: {
      sid: "96954",
      name: "appX1",
      group: "abcd"
    },
    event: 'register',
  },
  // reconnectionDelay: 2000,
  // closeHeartbeat: false,
  // heartbeatDelay: 30000,
  // heartbeatWait: 2000,
  callback: (data) => {
    console.log(data);
  },
  // connectByClose: true
});

const sdk = new SDKBase({
  service: 'wss://pre-citybrain-open.aliyun.com/app/space-ws/ws',
  source: 'web1'
  target: ['UE'],
  roomExclude: [''],
  registerData: {
    name: "appX1",
    group: "abcd"
  },
  extraWs: {
    closeHeartbeat: true
  },
});

WSOptions

| 属性名 | 说明 | 必填 | 类型 | 默认值 | 备注 | | :-----| :---- | :----: | :----: | :----: | :---- | | autoConnect | 是否需要自动连接 | 否 | Boolean | true | --- | | reconnectionDelay | 重连间隔时间 | 否 | Number | 2000 | --- | | closeHeartbeat | 是否关闭心跳检测 | 否 | Boolean | false | --- | | heartbeatDelay | 心跳检测间隔 | 否 | Number | 20000 | closeHeartbeat为false时生效 | | heartbeatWait | 心跳检测超时时间,超出重连 | 否 | Number | 2000 | closeHeartbeat为false时生效 | | connectByClose | 断开重连 | 否 | Boolean | true | --- | | registerData | 注册信息,初始化有的话,自动注册 | 否 | RegisterData | null | --- | | callback | 收到消息的回调 | 否 | (msg: Object) => {} | null | --- |

SDKOptions

| 属性名 | 说明 | 必填 | 类型 | 默认值 | | :-----| :---- | :----: | :---- | :----: | | service | 需要连接的服务地址 | 是 | String | - | | source | 当前客户端id | 否 | String | - | | target | 消息发送目标端 | 否 | Array | - | | roomExclude | 当前广播需要过滤的端, target优先级高 | 否 | Array | - | | registerData | 注册内容 | 是 | RegisterData | - | | extraWs | websocket扩展配置 | 否 | Options | {} |

RegisterData

| 属性名 | 说明 | 必填 | 类型 | 默认值 | | :-----| :---- | :----: | :----: | :----: | | name | 发送端名称 | 否 | string | - | | group | 消息通道房间名称 | 是 | string | - | | hasCbMsg | 注册消息是否需要广播 | 否 | boolean | - | | disconnectTime | 长时间不发送消息时,服务端主动断开服务需要的时间 | 否 | number | 60000 |

WSInstance API

| 属性名 | 说明 | 类型 | 备注 | | :---- | :---- | :---- | :---- | | send | 发送消息 | (data: Object) => {} | --- | | destroy | 销毁当前实例 | Function | --- | | init | 初始化(销毁后可以手动初始化) | Function | --- | | updateOptRetry | 更新配置后重新初始化 | (url: Options | string, opts?: Options) => {} | --- | | register | 自定义注册 | (registerData: Object) => {} | --- | | on | 事件监听 | eventList | --- |

SDKInstance API

| 属性名 | 说明 | 类型 | 备注 | | :-----| :---- | :---- | :---- | | listener | 按event和action监听消息内容返回 | (eventName: string, callback: (message: object) => void) => void | - | | registerEvent | 注册自定义事件 | (eventName: string, parser: (data) => data)) => {} | - | | send | 发送消息 | (event: string, message: object) => {} | - | | updateOptRetry | 更新配置后重新初始化 | (opts: Options) => {} | - | | destroy | 销毁函数 | Function | - |

eventList

| 事件名 | 说明 | | :----: | :---- | | load | ws连接成功 |