{"id":17408928,"url":"https://github.com/adamsey/easy-chat-pushjs","last_synced_at":"2025-04-15T20:16:15.753Z","repository":{"id":57218325,"uuid":"296741034","full_name":"AdamSEY/easy-chat-pushjs","owner":"AdamSEY","description":"Push Notifications using WebSocket, supports android, IOS and browser background notifications (FCM) and Slack notifications. ","archived":false,"fork":false,"pushed_at":"2024-03-28T18:51:25.000Z","size":547,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T20:16:04.647Z","etag":null,"topics":["android","fcm","fcm-notifications","ios","javascript","nodejs","notifications","ping","push-notifications","redis","slack","socketio","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AdamSEY.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-18T22:22:13.000Z","updated_at":"2023-01-23T17:41:37.000Z","dependencies_parsed_at":"2024-10-18T19:13:14.236Z","dependency_job_id":null,"html_url":"https://github.com/AdamSEY/easy-chat-pushjs","commit_stats":{"total_commits":83,"total_committers":2,"mean_commits":41.5,"dds":"0.012048192771084376","last_synced_commit":"46060019529be3db6d98c3ae563ea00c95f2ef02"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdamSEY%2Feasy-chat-pushjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdamSEY%2Feasy-chat-pushjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdamSEY%2Feasy-chat-pushjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AdamSEY%2Feasy-chat-pushjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AdamSEY","download_url":"https://codeload.github.com/AdamSEY/easy-chat-pushjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249145420,"owners_count":21219966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","fcm","fcm-notifications","ios","javascript","nodejs","notifications","ping","push-notifications","redis","slack","socketio","websocket"],"created_at":"2024-10-16T23:06:44.985Z","updated_at":"2025-04-15T20:16:15.699Z","avatar_url":"https://github.com/AdamSEY.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Easy-chat-pushjs\n\nGet your advanced chat and pushjs server ready in minutes\n\n## Features\n\n- Compatible with Socket.io version 3\n- Serverless authentication (JWT)\n- Push messages to Slack\n- Limit connection times by client's IP address or UserID (unqiueToken)\n- Clients can publish to specific rooms.\n- Join multiple rooms\n- Firebase cloud messaging notifications (push notifications to mobile phones).\n- Client \u0026 server can be on separate servers.\n- Peer 2 Peer chat via webRTC (beta)\n- Docker\n- Scaling to multiple servers for the same app.  \n## npm Installation\n\n    npm install --save easy-chat-pushjs\n\n\n## Server Setup\n\n\n### Docker\n\n```\n$ git clone https://github.com/AdamSEY/easy-chat-pushjs \u0026\u0026 cd easy-chat-pushjs/docker\n\n```\n\nCreate your RS256 private and public keys used for JWT authentication between the server and the client.\nWe only need the public key for the server. You will need the private key to create JWT tokens for authentication.\n\n```\n\nssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key \u0026\u0026 openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub\n\n```\n**Docker-compose.yaml edits**\nIf you want to use firebase cloud messaging notifications, add firebaseApiKey while starting the server.\nIf your application (client) will be on a different server other than the websocket server, let ZMQ listen to 0.0.0.0:3500 (check docker-compose.yaml file).\nif you're doing so, make sure to restrict connections to your server to only the IP address of the client.\n\n\nnow you're ready to start the server\n\n```\nsudo docker-compose up -d\n```\n\n### From scratch\n\n\n- Install redis [required for onlyOneConnection feature] [learn more](https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04)\n- Install ZMQ [required to push notifications to the websocket server] [learn more](https://zeromq.org/download/)\n\n\n\n#### Create JWT Token to connect to the server [frontend]\n\nCreate RS256 key pairs on Unix-like OS\n\n    ssh-keygen -t rsa -b 4096 -m PEM -f jwtRS256.key \u0026\u0026 openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub\n\n\n#### create users' authentication tokens [SERVER-SIDE][REST]\n\n    const {User} = require('easy-chat-pushjs');\n    const path = require('path');\n\n    const user = new User({\n        version: 1.0,\n        jwtPrivateKey: path.dirname(__dirname) + '/private.key',\n        zmqClientAddress: 'tcp://server_zmq_address:3500,tcp://server_zmq_address2:3500',\n        // you can publish to multiple websocket servers at once. add your servers ZMQ servers addresses separated by comma.\n        // if the Websocket Server is installed on this server, you can use 127.0.0.1:3500 or remove the line.\n    });\n    // version: used to invalidate the old tokens (must match the server version)\n    // jwtPrivateKey: absoulte path to the jwt private key, used to encrypt the token.\n    // slackURL: If you want to push notifications to slack (optional)\n\n    const token = user.createUserToken([ARRAY_OF_ROOMS] ,\"\u003cPUBLISH_ROOM\u003e\" , '\u003cUSER_ID\u003e', \"\u003cUNIQUE_ID\u003e\");\n\n    // ARRAY_OF_ROOMS: (optional) array of rooms \n    // CHAT_ROOM: (optional) users can publish via socket.io frontend-side only to this channel.\n    // USER_ID: (optional) used to push notifications to a speicifc user.\n    // UNIQUE_ID: (optional) used to disallow multiple connections could be a user IP e.g. 188.22.34.33\n\n\n\n*TIP: Check examples/client for more information about using this token*\n\nOnce your clients are connected to your websocket server, you're good to start pushing notifications\n\n### Run and create the websocket server:\n\nMake sure redis is up and running, in terminal type: `sudo service redis start`\n\ncreate your jwt RS256 key pairs and set the path in the options object.\n\ncreate your `server.js` file (see examples/websocket.js)\n\nRun your `server.js` by calling `node server.js`\n\n\n\n### Push notifications to connected clients\n\n**Now we assume your clients have connected to the websocket server and they're ready to receive socket messages.**\n\nif you'd like to push a message to all the clients who are connected to 'gender' you do the following\n\n    const {User} = require('easy-chat-pushjs');\n    const path = require('path');\n\n    const user = new User({\n        version: 1.0, \n        jwtPrivateKey: path.dirname(__dirname) + '/private.key', \n        slackURL: \"https://hooks.slack.com/services/EXAMPLE/....\",\n    });\n\n    user.pushNotification('gender', {message: 'hello there'}).then(() =\u003e {console.log(\"Message Pushed\")});\n\n\nSend a message to a specific user based on token's userId.\n\n    user.pushNotification(null, {message: hello} , '\u003cUSER_ID\u003e').then(() =\u003e {console.log(\"Message Pushed\")});;\n\n\npush a firebase notification, take a look at the following [link](https://developers.google.com/web/ilt/pwa/introduction-to-push-notifications) if you want to know how to get a browser token.\n\n    user.pushFirebaseNotifications(['FCM_TOKEN'], 'test', 'You have received a new request' ).then(() =\u003e {console.log(\"Firebase Message Pushed\")});;\n\npush slack notification, you need a webhook url to be set while configuring the server, for more information [click here](https://api.slack.com/messaging/webhooks)\n\n    user.pushSlackMessage('You have received a new request').then(() =\u003e {console.log(\"Slack Message Pushed\")});;\n\n\n### Nginx Setup Proxy\n\n    map $http_upgrade $connection_upgrade {\n        default upgrade;\n        '' close;\n    }\n    upstream socketio {\n        server 127.0.0.1:5511;\n    }\n    \n    Server{\n    \n      location ^~ /websocket/ {\n           \n            proxy_pass http://socketio;\n            proxy_set_header Host $http_host;\n            proxy_redirect off;\n            proxy_http_version 1.1;\n            proxy_set_header Upgrade $http_upgrade;\n            proxy_set_header Connection \"upgrade\";\n            proxy_read_timeout 86400;\n            \n            // if over loadbalancer or cloudflare \n            \n            proxy_set_header X-Real-IP $remote_addr;\n            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n      }\n      \n    }  \n\n### More Examples\n\nTake a look on the examples' directory, you'll find there:\n- How to start the websocket server. Check `websocket.js`\n- How to connect from the browser to the server and chat or receive push notifications. Check `client.js`\n- How to push notifications, push messages to Slack and Android- IOS (FCM). Check `push.js`\n\n\n\n### Notes\n- Redis used to store when the last time we received a \"ping\" from the client, if we don't receive a ping every 15 seconds we will disconnect the client.\n- production https://blog.jayway.com/2015/04/13/600k-concurrent-websocket-connections-on-aws-using-node-js/\n- We used this tutorial to get an idea how to allow only one concurrent connection using same userId, https://hackernoon.com/enforcing-a-single-web-socket-connection-per-user-with-node-js-socket-io-and-redis-65f9eb57f66a\n- Make sure to add socket.io version 3 to your html file otherwise you'll a get an error.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamsey%2Feasy-chat-pushjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamsey%2Feasy-chat-pushjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamsey%2Feasy-chat-pushjs/lists"}