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

websocket-sdk

v0.0.9

Published

webstart-sdk 的 websocket请求 请求协议的封装

Downloads

32

Readme

websocket-sdk

web js插件以及demo, 通过定义一套通信协议及机制,实现web端和本地程序之间的 websocket协议的通信

how to install

For JQuery and original js

Download js lib from npmjs

npm i websocket-sdk

add js to html

<script type="text/javascript" src="/webstart-sdk.min.js"></script>

For TypeScript such as Angular Vue React

install

npm i websocket-sdk --save-dev

Import

import * as WebSocketSdk from 'websocket-sdk';

协议规范

  • 通过websocket通信,通信端口:36666,36667,36668。为防止端口冲突,定义三个端口,只要有一个端口正常,即锁定为该端口。

  • 通信发起方与接收方:实时通信,在建立连接之后,双方可以在任意时刻,相互推送信息

SDK

初始化

WebSocketSdk.init(eventHandler, config);
eventHandler(event)

全局的事件处理回调

  • event.type:
    • [ ] log:全局日志
    • [ ] clientStatus:本地程序状态变化
    • [ ] result:执行全局结果
    • [ ] check:检测结果
  • event.message 消息
  • event.data 数据
  • event.status 状态码
function eventHandler(event) {
    if (event.type === 'log') {
      // 日志
    } else if (event.type === 'clientStatus') {
      // 本地程序状态变化
      // event.status:(OFF,ON,INITIAL)
    } else if (event.type === 'result') {
      // 执行全局结果
    } else if (event.type === 'check') {
      // 检测结果执行
    }
}
config 启动配置
{
  // 是否自动启动(针对JNLP方式启动的客户端),当需要通过Web启动JAVA程序时,需要将autoStart配置为true,并指定jnlpUrl的地址
  autoStart: true, // Optional
  agentAdminUrl: 'pcp://36666/', // Optional
  // health接口超时时间,默认1000毫秒
  heartBeatCheckTimeout: 1000, // Optional since V0.3.0
  port: [36666, 36667, 36668], // Default port Optional since V0.3.0
  // 启动后默认调用的一次数据接口(cmd指令)
  defalutCmd: 'statusService.register',
  // 启动后默认调用一次数据的参数(params)
  defaultParam: {"clientType":"C"},
  // 最大心跳检测次数
  heartBeatMaxTimes: 100,
  // 客户端版本
  appVersion: '1.2.2',
  // 下载客户端最新版本的地址
  appVersionUrl: '',
  // 检测客户端当前版本的cmd
  appVersionCmd: 'appService.version'
}

发送命令

var cmdId = WebSocketSdk.exec('cmd001', {
  param1: '123',
  param2: '456'
}, function (res) {
  log('同步返回值' + JSON.stringify(res));
});
if (cmdId !== null) {
  log('执行命令已发送:' + cmdId);
} else {
  log('执行命令发送失败');
}

下载最新客户端版本

/**
 *下载最新版本的客户端
 */
 webSocketSdk.download();

退出程序

/**
 * 退出程序,向后台发送退出命令
 */
WebSocketSdk.exit();

退出通信模式

/**
 * 退出通信,不向后台发送退出命令,仅前端退出
 */
WebSocketSdk.disconnect();

CHANGE LOG

V0.0.7

添加sdk自动启动功能

v0.0.1

创建websocket-sdk