README
dSock Node Client
Node client for dSock.
Installation
npm install dsock
# or
yarn add dsock
Usage
const { dSockClient } = require("dsock");
# or
import { dSockClient } from "dsock";
const dsock = new dSockClient(dSockApiUrl, dSockToken);
Create claim
Create a claim for user authentication.
const claim = dsock.createClaim({
user: "user",
// optional
session: "session",
id: "id",
channels: ["channel"],
time: { duration: 30 }, // in seconds, or use `expiration` for seconds since epoch
});
Send message
Send a message to a target (one or many clients).
await dsock.send({
data: JSON.stringify({ type: "hello-world" }), // any string or Buffer
// target (choose one or many)
user: "user",
session: "session", // depends on `user
id: "id",
channel: "channel",
});
Disconnecting
Disconnect a target (one or many clients).
await dsock.disconnect({
keepClaims: false, // if to keep claims for target
// target (choose one or many)
user: "user",
session: "session", // depends on `user
id: "id",
channel: "channel",
});
Info
Get claim and connection info from a target (one or many clients).
const { claims, connections } = await dsock.info({
// target (choose one or many)
user: "user",
session: "session", // depends on `user
id: "id",
channel: "channel",
});
Channels
Subscribe/unsubscribe a target to a channel (one or many clients).
await dsock.channelSubscribe("new-channel", {
// target (choose one or many)
user: "user",
session: "session", // depends on `user
id: "id",
channel: "channel",
});
await dsock.channelUnsubscribe("new-channel", {
// target (choose one or many)
user: "user",
session: "session", // depends on `user
id: "id",
channel: "channel",
});