# @samlior/socket-io-server

> `@samlior/socket-io-server` is a socketIO server based on JSONRPC.

Latest version **2.0.0** (published 2023-09-07) · GPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @samlior/socket-io-server
pnpm add @samlior/socket-io-server
yarn add @samlior/socket-io-server
bun add @samlior/socket-io-server
```

## 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.0 |
| Published | 2023-09-07 |
| First published | 2023-01-19 |
| Weekly downloads | 0 |
| License | GPL-3.0-or-later |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 15.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | samlior |
| Maintainers | samlior_ |

## Links

- npm: https://www.npmjs.com/package/@samlior/socket-io-server
- Repository: https://github.com/samlior/framework
- Homepage: https://github.com/samlior/framework#readme
- Issues: https://github.com/samlior/framework/issues
- npm.io page: https://npm.io/package/@samlior/socket-io-server

## Dependencies (4)

- [socket.io](https://npm.io/package/socket.io.md) ^4.5.4
- [@samlior/utils](https://npm.io/package/@samlior/utils.md) ^2.0.0
- [http-terminator](https://npm.io/package/http-terminator.md) ^3.2.0
- [@samlior/socket-io-client](https://npm.io/package/@samlior/socket-io-client.md) ^2.0.0

## Recent versions

- 2.0.0 (latest) — 2023-09-07
- 1.0.4 — 2023-01-28
- 1.0.3 — 2023-01-27
- 1.0.2 — 2023-01-26
- 1.0.1 — 2023-01-23
- 1.0.0 — 2023-01-19

## README

# `@samlior/socket-io-server`

`@samlior/socket-io-server` is a socketIO server based on JSONRPC.

## Install

```sh
npm install @samlior/socket-io-server
```

## Usage

```ts
import { SocketIOServer } from "@samlior/socket-io-server";
import { ISocketIOHandler } from "@samlior/socket-io-client";

class MockEchoHandler implements ISocketIOHandler {
  async handle(params: any): Promise<string> {
    if (typeof params !== "string") {
      throw new Error("invalid params");
    }
    return params;
  }
}

const { server, httpServer, terminator } = await SocketIOServer.create(
  { maxTokens: 10, maxQueued: 2 },
  8080
);

// register handler
server.register("echo", new MockEchoHandler());

// start
server.start();

process.on("SIGINT", async () => {
  // this function will ensure that all executing requests are completed
  // and safely close all client connections
  await SocketIOServer.shutdown(server, terminator);

  // do something...

  process.exit(0);
});
```

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