dsock
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

dSock Node Client

Node client for dSock.

GitHub - npm

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 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 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",
});

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",
});

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",
});

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",
});

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i dsock

Weekly Downloads

17

Version

0.1.5

License

MIT

Unpacked Size

24.4 kB

Total Files

19

Last publish

Collaborators

  • cretezy