Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/channelstream/channelstream-js-client
Channelstream JS Client
https://github.com/channelstream/channelstream-js-client
Last synced: 27 days ago
JSON representation
Channelstream JS Client
- Host: GitHub
- URL: https://github.com/channelstream/channelstream-js-client
- Owner: Channelstream
- License: bsd-3-clause
- Created: 2019-01-07T19:30:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-15T16:22:55.000Z (almost 5 years ago)
- Last Synced: 2024-11-18T11:16:31.745Z (about 2 months ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# channelstream-js-client
Browser client for Channelstream websocket server.
https://channelstream.org
https://www.npmjs.com/package/@channelstream/channelstream
First run channelstream server:
channelstreamNow 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:
```javascript
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.
## License
BSD 3-Clause License