npm install @putdotio/socket-clientimport { 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" },
});
});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.
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,
},
};This project is available under the MIT License
