Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eldoy/kabel
Server that relays messages to websocket clients (i.e. browsers)
https://github.com/eldoy/kabel
Last synced: 6 days ago
JSON representation
Server that relays messages to websocket clients (i.e. browsers)
- Host: GitHub
- URL: https://github.com/eldoy/kabel
- Owner: eldoy
- License: mit
- Created: 2020-09-25T15:16:35.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-26T08:48:35.000Z (about 4 years ago)
- Last Synced: 2024-08-09T13:44:25.592Z (3 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kabel
Server that relays messages to websocket clients (i.e. browsers). Useful for sending commands to applications via the command line, for example tell the browser to reload when a file changes.### Installation
`npm i -g kabel`### Setup autoreload for your web app
#### Start kabel
```bash
# Default port is 3900
kabel# With different port as option
kabel -p 3010# or with env variable
KABEL_PORT=3011 kabel# You can also set the wait in ms before sending the message
kabel -w 500# or with env variable
KABEL_WAIT=500 kabel# Quiet output
kabel -q# or with env variable
KABEL_QUIET=0
```
You only need one kabel server for all your apps.#### Set up web socket connection
Include this on in your web app:
```htmlvar ws = new WebSocket('ws://localhost:3900')
ws.onopen = function() {
// Change the name to the name of your app
// The name should match what you're sending with curl
ws.send(JSON.stringify({ name: 'app' }))
}
ws.onmessage = function() {
window.location.reload(true)
}
ws.onerror = function() {
console.log('Error connecting to kabel')
}```
#### Automatic reload with nodemon
Create a `nodemon.json` file in your app root direcory that looks like this:
kabel.js notify 'http://localhost:3900?name=cfhqadmin'
```json
{
"events": {
"restart": "kabel notify 'http://localhost:3900?name=app'"
}
}
```
Your application will now reload every time nodemon restarts.Alternatively you can use `curl`:
```json
{
"events": {
"restart": "curl -X POST -d 'name=app' http://localhost:3900"
}
}
```#### Send a message to the browser via kabel
```
# From terminal using kabel
kabel notify 'http://localhost:3900?name=app'# From terminal using curl
curl -X POST -d 'name=app' http://localhost:3900
```
Your app should now have reloaded.### License
MIT licensed. Enjoy!