# daemonlib-ts

> ## 安装

Latest version **2.0.2** (published 2021-03-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install daemonlib-ts
pnpm add daemonlib-ts
yarn add daemonlib-ts
bun add daemonlib-ts
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2021-03-17 |
| First published | 2021-03-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 506.5 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | wenchangshou |
| Keywords | typescript |

## Links

- npm: https://www.npmjs.com/package/daemonlib-ts
- npm.io page: https://npm.io/package/daemonlib-ts

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [class-transformer](https://npm.io/package/class-transformer.md) ^0.4.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2021-03-17
- 2.0.1 — 2021-03-17
- 1.0.7 — 2021-03-17
- 1.0.6 — 2021-03-15
- 1.0.5 — 2021-03-15
- 1.0.4 — 2021-03-15
- 1.0.3 — 2021-03-15
- 1.0.2 — 2021-03-15
- 1.0.1 — 2021-03-15
- 1.0.0 — 2021-03-12

## README

# daemonlib-ts库

## 安装

``` shell
npm install daemonlib-ts
```

## Quickex Example

``` js
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
``` javascript
 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<any>**

  **OnMessage(listener: (*ev*: CustomEvent<CustomMessageEvent>) => 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<ClientListInfo>**

**return:**

``` typescript
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();
}
```

---
_Source: https://npm.io/package/daemonlib-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
