0.1.5 • Published 3 years ago

dsock v0.1.5

Weekly downloads
84
License
MIT
Repository
-
Last release
3 years ago

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

License

MIT

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

4 years ago

0.1.0

4 years ago