daemonlib-ts
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

daemonlib-ts库

安装

npm install daemonlib-ts

Quickex Example

import { Proto, DaemonLib } from "daemonlib-ts";
 let daemonlib = new DaemonLib('192.168.0.222', 'wcs', {
  proto: Proto.TEXT,
  httpEnable: true,
  httpPort: 9191,
  websocketPort: 8181,
  websocketEnable: true,
  Route: true
 });

 // message process
 daemonlib.OnMessage((ev) => {
   let data={"status":0,"message":"ok"
   }
  ev.callback(JSON.stringify(data))
 });



 // get all client info

 daemonlib.GetClients().then(*clients*=>{
   console.log('get clients info',clients);
 })
  let requestData={"Action":"query"
  } 
 // Pubv2 Push messages with replies*
 daemonlib.PubV2('/zebus/192.168.10.121/ResourcesService',JSON.stringify(requestData),500,100).then(*res*=>{
   console.log('result message',res)
 })
 .catch(err=>{
   console.log('pubv2 error',err)
 })

 daemonlib.puPub

Constructor

 let daemonlib = new DaemonLib('192.168.0.222', 'wcs', {
  proto: Proto.TEXT,
  httpEnable: true,
  httpPort: 9191,
  websocketPort: 8181,
  websocketEnable: true,
  Route: true
 });
name type required Remarks
proto string yes proto.TEXT proto.BINARY
httpEnable boolean yes Whether to enable http
websocketEnable boolean yes Whether to enable websocket
httpPort number yes http port
websocketPort number yes websocket port

Method

Pub(topic: string, body: any): Promise

OnMessage(listener: (ev: CustomEvent) => any, options?: boolean | EventListenerOptions): DaemonLib

params:

export interface CustomMessageEvent { readonly message: Message; readonly callback: MessageReplyCallback; }

PubV2(topic: string, body: any, timeout?: number, defer?: number): Promise

GetClients(): Promise

return:

export declare class DaemonInfo {
    Ip: string;
    Server: string[];
    Config: Map<string, any>;
    Resource: string[];
    constructor();
}
export declare class ClientListInfo {
    offlines: string[];
    online: DaemonInfo[];
    server: string[];
    constructor();
}

/daemonlib-ts/

    Package Sidebar

    Install

    npm i daemonlib-ts

    Weekly Downloads

    6

    Version

    2.0.2

    License

    ISC

    Unpacked Size

    519 kB

    Total Files

    95

    Last publish

    Collaborators

    • wenchangshou