@samlior/socket-io-client
v2.0.1
Published
`@samlior/socket-io-client` is a socketIO client based on JSONRPC.
Downloads
12
Readme
@samlior/socket-io-client
@samlior/socket-io-client
is a socketIO client based on JSONRPC.
Install
npm install @samlior/socket-io-client
Usage
import {
SocketIOClientManager,
ISocketIOHandler,
} from "@samlior/socket-io-client";
class MockClientEchoHandler implements ISocketIOHandler {
async handle(params: any): Promise<string> {
if (typeof params !== "string") {
throw new Error("invalid params");
}
return "from client " + params;
}
}
async function main() {
const manager = new SocketIOClientManager();
const client = await manager.connect("wss://aaa.bbb.ccc/namespace");
console.log("response:", await client.req("method", "params"));
client.close();
}
main().catch((err) => console.log("main, catch error:", err));