2.0.0 • Published 8 months ago
@samlior/socket-io-server v2.0.0
@samlior/socket-io-server
@samlior/socket-io-server
is a socketIO server based on JSONRPC.
Install
npm install @samlior/socket-io-server
Usage
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);
});