@putdotio/socket-client
v5.0.2
Published
SockJS client for real-time put.io events.
Readme
Installation
Install with npm:
npm install @putdotio/socket-clientQuick Start
import { createPutioSocketClient, EVENT_TYPE } from "@putdotio/socket-client";
const client = createPutioSocketClient({
token: process.env.PUTIO_TOKEN!,
});
const unsubscribe = client.on(EVENT_TYPE.TRANSFER_UPDATE, (payload) => {
console.log(payload);
});
client.on(EVENT_TYPE.CONNECT, () => {
client.send({
type: "custom",
value: { hello: "world" },
});
});Connection Lifecycle
Call client.close() during teardown. Closing is idempotent and permanently stops
heartbeat checks and pending reconnects for that client. Create a new client to
connect again.
Transient closures trigger up to 10 reconnect attempts: the first is immediate,
then delays start at 100 ms and double after each failed attempt. A successful
connection resets the retry budget and emits connect followed by reconnect.
Normal closure, server error (1011), and unauthorized (4001) remain terminal.
Events
The package exports typed event names and payload maps for the socket stream:
import { EVENT_TYPE, type SocketEvents } from "@putdotio/socket-client";
const event: SocketEvents["TransferUpdate"] = {
type: EVENT_TYPE.TRANSFER_UPDATE,
value: {
id: 1,
},
};Docs
Contributing
See Contributing
License
This project is available under the MIT License
