0.0.3 • Published 6 months ago

one-server-ws v0.0.3

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

It's a toolkit for nodejs WebSocket.

Functions

interface WebSocketConfig {
  port?:number; 
  https?:{
    key:string; 
    cert:string;
  },
  auth?: { 
    secret?:string; // TOKEN的加密密钥
  }
}

/**
 * 建立HTTP(s)/WS(S)连接, 进行Websocket通讯
 * 支持JWT身份验证
 * 客户端Demo: 
    const socket = new WebSocket('https://localhost:3030', {
      secure: true, // 指定使用安全的 HTTPS 协议
      rejectUnauthorized: false, // 如果不验证证书,设置为 true
      headers: { Authorization: token }
    });
 */
class WSSocket {
  constructor(filename:string);
  constructor(options:WebSocketConfig);
  handle(callback:(msg: Buffer | ArrayBuffer | Buffer[], socket:WebSocket)=>void): this;
  start(callback:(msg:string)=>void): this;
}
0.0.3

6 months ago

0.0.2

7 months ago

0.0.1

7 months ago