1.0.3 • Published 2 years ago
gallium-io v1.0.3
What is this about?
It is a package for node.js, that will ensure easy websocket configuration without any manual code. In two steps the websocket connection is made.
How to install ?
npm i gallium-io --save
Then..
const {MakeConnection} = require('gallium-io')
const wss = MakeConnection(server)
wss.OnConnect(true)
Step 1. Import MakeConnection function from gallium-io
Step 2. Make the WebSocketServer using the MakeConnection
Step 3. And then to start the websocket use wss.onConnect(true).
Note: Make sure your frontend is set up with gallium-react, Before initiating the server. The best part about it is that we can also handle http requests on our server, which handles both the WS connection as well as normal express server.
Here is the full setup
const express = require('express')
const app = express()
const server = require('http').createServer(app);
const {MakeConnection} = require('gallium-io')
const wss = MakeConnection(server)
const Ws = wss.OnConnect(true)
app.get('/',(req,res)=>{res.send("Hello world")})
server.listen(9876, ()=>console.log(`Listening on port ${9876}`))
Note: Both gallium-react and gallium-io should be on same WS connetion and port.