GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - skillnull/WebEESocket: 通过事件驱动机制 EventEmitter 对 socket 进行集成封装 支持平台: 浏览器 · 微信小程序 · Node.js · React Native

BranchesTags
Open more actions menu

Latest commit

 

History

48 Commits
48 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/ISSUE_TEMPLATE
.github/ISSUE_TEMPLATE
 
 
dist
dist
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.npmrc
.npmrc
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
babel.config.ts
babel.config.ts
 
 
index.html
index.html
 
 
package.json
package.json
 
 
rollup.config.ts
rollup.config.ts
 
 
server.js
server.js
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

WebEESocket

License MIT

通过事件驱动机制 EventEmitter 对 Websocket 和微信 connectSocket 进行集成封装

CDN

使用 UMD 格式
<script src="https://www.unpkg.com/@skillnull/[email protected]/dist/WebEESocket.js"></script>
# or
<script src="https://cdn.jsdelivr.net/npm/@skillnull/[email protected]/dist/WebEESocket.js"></script>

使用 ES 格式
<script src="https://www.unpkg.com/@skillnull/[email protected]/dist/WebEESocket.es.js"></script>
# or
<script src="https://cdn.jsdelivr.net/npm/@skillnull/[email protected]/dist/WebEESocket.es.js"></script>

安装

yarn add @skillnull/webeesocket

# or with npm

npm install @skillnull/webeesocket

使用

// 使用 CDN 引用时,无需 import 
import { WEBSOCKET } from '@skillnull/webeesocket'

/**
 * @params: {
 *   url: <String> 服务器连接地址
 *   auth: <Any> 服务器认证信息
 *   heartbeat?: <Any> 心跳握手内容
 *   heartbeat_time?: <Any> 心跳握手间隔,默认30000ms,heartbeat 传值此项才会生效
 *   protocol?: <String | String[]> 协议
 *   reconnect_step?: <Number> 重连间隔,不传默认 1000,传 -1 表示不重连
 * }
 */
this.WEBSOCKET = new WEBSOCKET({ 
  url: "your socket server url",
  auth: {
    // server need auth info
  },
  heartbeat: {
    // heartbeat need info
  },
  heartbeat_time: 30000,
  protocol: "protocol for websocket",
  reconnect_step: 1000
})

/**
 * code: 与服务端约定的用于监听的 code
 */
this.WEBSOCKET.on(code, (data) => {
  // handler data
})

/**
 * 订阅
 * @data: {
 *   key?: <String> 用于缓存和退订,不传时 SDK 自动生成自增 key
 *   body: <Any> 服务端需要的,订阅的具体参数,默认将进行 JSON.stringify
 *   not_stringify?: <Boolean> 是否取消将参数 body 进行 JSON.stringify,默认 false
 * }
 */
const subscribeKey = this.WEBSOCKET.subscribe({
  body: "require",
  not_stringify: "not require"
})

/**
 * 退订
 * @data: {
 *   key: <String> 订阅时传的 key
 *   body?: <Any> 其他参数,会合并到订阅时缓存的 body 上,默认将合并后的 body 进行 JSON.stringify
 *   not_stringify?: <Boolean> 是否取消将合并后的参数 body 进行 JSON.stringify,默认 false
 * }
 */
this.WEBSOCKET.unsubscribe({
  key: subscribeKey, 
  body: "require", 
  not_stringify: "not require"
})

About

通过事件驱动机制 EventEmitter 对 socket 进行集成封装 支持平台: 浏览器 · 微信小程序 · Node.js · React Native

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.