This Websuckit client library supports web browsers and Node.js
For tutorials and more in-depth information about websuckit Channels, visit our official docs.
The following topics are covered:
- Web
- We test against Chrome, Firefox and Safari.
- Works in web pages.
- Works with major web frameworks, including
- Node.js
If you're using websuckit Channels on a web page, you can install the library via:
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');
<script src="https://unpkg.com/@websuckit/js/dist/websuckit.umd.js"></script>
Having installed @websuckit/js
via an NPM-compatible package manager, run:
import Websuckit from '@websuckit/js';
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.
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,
})
// The expected return of the connectionUrl is a websocket connection e.g {ok: true, value: wss://backend.websuckit.com/e762eaad-397b-4af8-9376-a8eff2731966/bright/{encrypted_token}}
channelName
- name of channelchannelPassKey
- channel passkey
const channelResponse = ws.createChannel({
channel: "channel_name", // channel should be a slug e.g test-channel
max_connections?: number; // (optional) maximum number of concurrent connections per channel
})
const channelResponse = ws.getChannel({
channelName: "channel_name",
})
const channelResponse = ws.getChannels({
page: "0", // page is 0 indexed
per_page: "10",
search_key: "channel_name" // (optional) search channels by channel name
})
const channelResponse = ws.getOrCreateChannel({
channelName: "channelName", // channel should be a slug e.g test-channel
})
const channelResponse = ws.updateChannel({
channelId: "<CHANNEL_UUID>",
channel: "channel_name",
regenerate_pass_key: false // (optional) If regenerate_pass_key is true the channel passkey will be regenerated
max_connections?: number; // (optional) maximum number of concurrent connections per channel
})
const channelResponse = ws.deleteChannel({
channelId: "<CHANNEL_UUID>",
})
// Expected response
// string
yarn test
yarn install
yarn dev
- 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"