Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dmhendricks/nodejs-simple-message-relay
A simple Node.js server to relay messages and data to listening Socket.IO clients.
https://github.com/dmhendricks/nodejs-simple-message-relay
browser-notifications growl nodejs-server socket-io socket-io-client socketio-messaging socketio-server websockets
Last synced: 11 days ago
JSON representation
A simple Node.js server to relay messages and data to listening Socket.IO clients.
- Host: GitHub
- URL: https://github.com/dmhendricks/nodejs-simple-message-relay
- Owner: dmhendricks
- License: apache-2.0
- Created: 2019-11-30T22:51:05.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-02T03:07:08.000Z (almost 5 years ago)
- Last Synced: 2024-12-24T10:13:06.495Z (18 days ago)
- Topics: browser-notifications, growl, nodejs-server, socket-io, socket-io-client, socketio-messaging, socketio-server, websockets
- Language: JavaScript
- Homepage:
- Size: 1.14 MB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Author](https://img.shields.io/badge/author-Daniel%20M.%20Hendricks-lightgrey.svg?colorB=9900cc )](https://www.danhendricks.com/?utm_source=github.com&utm_medium=campaign&utm_content=button&utm_campaign=dmhendricks%2Fnodejs-simple-message-relay)
[![License](https://img.shields.io/github/license/dmhendricks/nodejs-simple-message-relay.svg)](https://github.com/dmhendricks/nodejs-simple-message-relay/blob/master/LICENSE)
[![DigitalOcean](https://img.shields.io/badge/hosting-Digital%20Ocean-green.svg?style=flat-square&label=hosting&colorB=0152FF)](https://m.do.co/t/8a88362f5683?utm_source=github.com&utm_medium=campaign&utm_content=referral&utm_campaign=dmhendricks%2Fnodejs-simple-message-relay)
[![Twitter](https://img.shields.io/twitter/url/https/github.com/dmhendricks/nodejs-simple-message-relay.svg?style=social)](https://twitter.com/danielhendricks)
[![BrowserStack](https://img.shields.io/static/v1?style=social&label=BrowserStack&message=Passed&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAc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kM0RUZFRDdBQjhEOSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PhdfVWUAAAGAUExURXjIMP/Rhf/Xn4mHhwpRXnrY8CIXFv41Sk68OACv2QC+6svIAP5oEAC+6H7ToKa3nP9fF//AT/+tfPjVzpTPHf+6Rf1GLcbVAJDd8P/9+v/qyf/EY/+mNXHLidKyF126Mv/26anm8/+8TP/68P1jAFHO8lPAYu+SDqrh7v+xR/0eOgC/rIGvM7SvI9qKjAC+6lG5wf+SM/+2mOGnGf8NMgCcvLLEw5OZOv0yMfvARRfD7v+VSf9lZ/9mOqTs9lvAQ/+EK/+VY7Hr/f+cN0+7Lb2FMuqFG7tuOv9jEOCLLP93JKzj+ZDYwwC9s2LLrQB8k/9wEv+4R/9oD5/g1b3iAACtygCJo//w6MnHyPM5M+h3NuVyfcLPZP9MWKOYXMevu/+Xn5HG06nWAwDG8pzn6//lsZ/l85rik/+def/38fNoILPS3/1tF/+3Zf+sROmuICWPq3edprrG0VTW26jn/EhteD7CN9ibbgC8t/96NPmLQIjPY/9CKSQfIP///////+tAimMAAACAdFJOU/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8AOAVLZwAAAj9JREFUeNpU0vtb0lAYB/CzCTgeDrQpGwyUyzZwwwyBmTRNELwgkYpQZkUXumktyrJ13eFf9z0CZd8ftufZZ9/znPOcFw1HIWezp+u9Xm/9xaw8nASNXsczfNk0c2VJOjGni2fXkRQ1KWeWdxKBSCSS2DuZZslflDepPX76LrS/P/+7343slWfkMRJque+djGXlIcuo301IH+URFjU+Z97ayAAEIfl8NtxN3GUIxWMNS+aTDS/QysHBij8YXOTC3b21N4DkFIrTH95alt/j+nw+z0owmE32A78UdYhS2JZg0aiV9/hc1zc1C7q4hbolgx0ilgd8vuG1HoK5rkxcT/B+kusHDEFGm5ot5b6kvZbnCh9Nua7/R5ILR9piDP3EVxgdowtPPzRR5I7IIpvi7bSeGSPEvzhCBjUp3rjQo5/H6PO8mt8CbCtxuixvPnut695J1f+1wnHhgAG4pmG7vBu6p6ej367O+cALRa7/SQQsahjzJ8kWaPrl+fmy9yIEVgnUBdhQ7BBj+8+uE9KBa7WaTntcf2EgwFHkAlSxtOpkQ61OpxWqUAuXqoKiyIgwUMVHoFtcpcJRclAJG7AqQUN1DlPlt5OO44A4laUFvi4oYgqujLB1qrjxfnv1JmRp54gvgMGowGXL8blDnpYbDfpPg7dpLy6PZkgVjCrW8Cg8rhpggjqZPjUuGoWmDWQ3CwOB9tR/cyuzoqC0B4OBoVASWfn6UJMUo4gAVBQmRf6beGA1xsQVJc7EVDL5dinAAO2UucfjcPEkAAAAAElFTkSuQmCC)](https://browserstack.com/?utm_source=github.com&utm_medium=referral&utm_content=link&utm_campaign=dmhendricks%2Fnodejs-simple-message-relay)# Node.js Simple Message Relay
A simple example of using [Node.js](https://nodejs.org/) to send Growl-style messages to a browser via [Socket.IO](https://socket.io/).
- [Installation](#installation)
- [Configuration](https://github.com/dmhendricks/nodejs-simple-message-relay/wiki/Configuration)
- [Setting Environment](https://github.com/dmhendricks/nodejs-simple-message-relay/wiki/Configuration#setting-environment)
- [Usage](#usage)
- [Client-Side Example Code](https://github.com/dmhendricks/nodejs-simple-message-relay/wiki/Client-Side-Example-Code)
- [Screenshot](#screenshot):pushpin: Available on Docker Hub: [hendridm/socketio-relay](https://hub.docker.com/r/hendridm/socketio-relay)
### Requirements
- [Node.js](https://nodejs.org/)
### How It Works
**The server does one thing:** It accepts JSON data submitted to the endpoint and forwards it to the specified socket. It will relay _any_ data that you submit - it is up to the listening client to consume it.
You can have any number of clients listening to different sockets. In this way, you can have multiple apps listening for different events and different payloads. Purely as examples, you could have all of the following:
- An admin panel that listens on a socket named `admin-notifications`, receiving information about system events.
- An e-commerce site that listens on a socket named `sales-popups`, which displays a sale notification to visitors, similar to [Sales Pop](http://sales-pop.demo.beeketing.com/).
- A real-time chat application that listens on a socket named `chat-app`, which broadcasts user messages as they are submitted.These are just examples - you can relay any data to any number of sockets that you wish. **The included demo page is simply an example of consuming data received from the server.** Your usage will vary.
### Goals
- [x] Add simple Growl-style example
- [x] Add advanced example with custom template and image
- [ ] Improve input validation
- [ ] Improve exception handling
- [ ] WordPress plugin and integrations## Installation
To install, clone the repository, install dependencies and start the server:
```bash
git clone https://github.com/dmhendricks/nodejs-simple-message-relay.git
cd nodejs-simple-message-relay
npm install
npm run start
```
:pushpin: For local development, you can use `npm run dev` instead to automatically reload the server as you modify and save files.## Usage
1. Visit [http://localhost:3000/](http://localhost:3000/) in your web browser to bring up the client-side browser demo (disabled if `demo_page` is false in [config](https://github.com/dmhendricks/nodejs-simple-message-relay/wiki/Configuration)).
2. Use [Postman](https://www.getpostman.com/) or cURL to send a POST to the `/send` endpoint:**Send a Simple Notification**
```bash
curl -X POST 'http://localhost:3000/send/my-socket-name?api_key=YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"message": "Hello world!",
"color": "info"
}'
```**Send an Advanced Notification**
```bash
curl -X POST 'http://localhost:3000/send/my-socket-name?api_key=YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"type": "advanced",
"message": "Someone in Chicago, USA just bought a Toolbox Widget/Modular Toolbox Wrench Organizer!",
"link": "https://smile.amazon.com/dp/B07H6FJY9D/",
"image": "https://picsum.photos/id/237/200/200"
}'
```After sending one or more messages, they should appear on the browser demo page. See [`public/index.html`](https://github.com/dmhendricks/nodejs-simple-message-relay/blob/master/public/index.html) for source code.
**Note:** The `api_key` query string variable may be absent in [development](https://github.com/dmhendricks/nodejs-simple-message-relay/wiki/Configuration#setting-environment) mode (ie, when `NODE_ENV` is not defined).
## Screenshot
![Screenshot](https://raw.githubusercontent.com/dmhendricks/nodejs-simple-message-relay/master/public/assets/images/screenshot.gif)
[![Analytics](https://ga-beacon.appspot.com/UA-126205765-1/dmhendricks/nodejs-simple-message-relay?flat)](https://ga-beacon.appspot.com/?utm_source=github.com&utm_medium=campaign&utm_content=button&utm_campaign=dmhendricks%2Fnodejs-simple-message-relay)