项目作者: cvweiss

项目描述 :
Node implementation of redis to websocket broadcasting.
高级语言: JavaScript
项目地址: git://github.com/cvweiss/redis-websocket.git
创建时间: 2016-07-23T20:40:07Z
项目社区:https://github.com/cvweiss/redis-websocket

开源协议:MIT License

下载


redis-websocket

Creates a websocket on port 15241, listens to all channels on redis, and will publish to each connection the messages from each channel they have subscribed.

To install it:

  1. git clone https://github.com/cvweiss/redis-websocket.git
  2. cd redis-websocket
  3. npm install

To run it:

  1. nodejs app.js

To listen to the public channel, from the browser client connecting to the websocket:

  1. ws.send(JSON.stringify({'action':'sub','channel':'public'}));

Additional channels can be specified one at a time:

  1. ws.send(JSON.stringify({'action':'sub','channel':'datastream'}));

Example:

  1. > nodejs app.js
  2. Sat Jul 23 2016 20:54:15 GMT+0000 (UTC) Server is listening on port 15241
  3. Sat Jul 23 2016 20:54:20 GMT+0000 (UTC) Broadcasted to 72 clients: ping
  4. Sat Jul 23 2016 20:54:40 GMT+0000 (UTC) Broadcasted to 122 clients: pong
  5. Sat Jul 23 2016 20:55:02 GMT+0000 (UTC) Broadcasted to 239 clients: {"action": "test"}

An example of an nginx configuration that listens to port 2096 and passes this to the node app

  1. server {
  2. listen 2096 ssl;
  3. listen [::]:2096 ssl;
  4. server_name wss.example.com;
  5. include snippets/self-signed.conf;
  6. include snippets/ssl-params.conf;
  7. location / {
  8. proxy_pass http://127.0.0.1:15241;
  9. proxy_http_version 1.1;
  10. proxy_set_header Upgrade $http_upgrade;
  11. proxy_set_header Connection "upgrade";
  12. proxy_set_header Host $host;
  13. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  14. }
  15. access_log off;
  16. }