Websuckit Javascript Client
![Deploy to NPM](https://github.com/WebSuckIt/web-suck-it-js/actions/workflows/deploy.yml/badge.svg)
This Websuckit client library supports web browsers and Node.js
For tutorials and more in-depth information about websuckit Channels, visit
our official docs.
Usage Overview
The following topics are covered:
Supported platforms
- Web
- We test against Chrome, Firefox and Safari.
- Works in web pages.
- Works with major web frameworks, including
- Node.js
Installation
Web
If you're using websuckit Channels on a web page, you can install the library via:
Yarn (or NPM)
You can use any NPM-compatible package manager, including NPM itself and Yarn.
yarn add @websuckit/js
Then:
import websuckit from '@websuckit/js';
Or, if you're not using ES6 modules:
const websuckit = require('@websuckit/js');
CDN
<script src="https://unpkg.com/@websuckit/js@0.0.7/dist/websuckit.umd.js"></script>
Node.js
Having installed @websuckit/js
via an NPM-compatible package manager, run:
import websuckit from '@websuckit/js';
Initialization
const ws = new Websuckit({
userId: USER_ID,
accessKey: ACCESS_KEY,
publicKey: PUBLIC_KEY,
})
You can get your USER_ID
, ACCESS_KEY
and PUBLIC_KEY
from the websuckit dashboard.
Channel
Create channel
const channelResponse = ws.createChannel({
channel: "channel_name",
})
Get channel
const channelResponse = ws.getChannel({
channelName: "channel_name",
})
Get channels (paginated)
const channelResponse = ws.getChannels({
page: "0",
per_page: "10",
search_key: "channel_name";
})
Get or Create channel
const channelResponse = ws.getOrCreateChannel({
channelName: "channelName",
})
Update channel
const channelResponse = ws.getOrCreateChannel({
channelId: "<CHANNEL_UUID>",
channel: "channel_name"
regenerate_pass_key: false;
})
Delete channel
const channelResponse = ws.getOrCreateChannel({
channelId: "<CHANNEL_UUID>",
})
Accessing a channel's websocket URL
It is possible to access a channel websocket URL by channel name, through the getConnectionUrl
function:
const connectionUrl = ws.getConnectionUrl({
channelName: CHANNEL_NAME,
channelPassKey: CHANNEL_PASSKEY,
})
channelName
- name of channelchannelPassKey
- channel passkey
Test SDK
yarn test
Run Locally
yarn install
yarn dev
Run SDK locally
- Run
yarn build && cp package.json ./dist && cd dist && yarn link
in the root directory. - Next, Change directory into example folder and run
cd ../example && yarn link "@websuckit/js"