Browser client for Channelstream websocket server.
https://www.npmjs.com/package/@channelstream/channelstream
First run channelstream server:
channelstream
Now you can implement the client side of websocket handling, first install the client:
npm i @channelstream/channelstream
You are ready to add the client to your application and act on events:
import {ChannelStreamConnection} from '@channelstream/channelstream';
let connection = new ChannelStreamConnection();
// this points to your application view
connection.connectUrl = '/connect';
connection.messageUrl = '/message';
// this points to channelstream
connection.websocketUrl = 'ws://127.0.0.1:8000/ws';
connection.longPollUrl = 'http://127.0.0.1:8000/listen';
connection.listenMessageCallback = (messages) => {
for (let message of messages) {
console.log('channelstream message', message);
// Do something on message received
}
};
// optional
connection.listenOpenedCallback = () => {
// Do something on websocket open
};
// this will try to obtain connection UUID from `connectUrl` endpoint of your
// WEB application via XHR calland then use it to make websocket connection
// optionally set the username for XHR call
// your server side application can normally handle this
connection.username = "someID"
connection.connect();Consult the project website for more in depth examples.
Clone the repository and install dependencies:
git clone https://github.com/Channelstream/channelstream-js-client.git
cd channelstream-js-client
npm installBuild the ES modules using Rollup:
npm run buildThis converts the CommonJS SHA modules to ES modules (sha-esm.js, sha1-esm.js).
Note: The build runs automatically on npm install via the prepare script.
Generate API documentation with JSDoc:
npm run jsdocDocumentation is output to the jsdoc_out/ directory.
-
Remove private flag: Edit
package.jsonand set"private": falseor remove the field entirely. -
Update version: Bump the version in
package.json:npm version patch # or minor/major -
Login to npm:
npm login
-
Publish (scoped packages require
--access public):npm publish --access public
BSD 3-Clause License