This package provides websocket support to wae web framework.
It supports the usage of the ws.Server
and
Wae supports websocket servers via the ws module.
Although this package is full capable of using the ws.Server
(with the noServer option)
Wae has its own Server Syntax.
Here is how you can use the ws.Server
const WebSocket = require('ws'); // You'll need ws
const wws = require("wae-ws"); // And the Wae ext module
// From the simple server demo (https://www.npmjs.com/package/ws#simple-server)
const wss = new WebSocket.Server({ noServer: true}); // noServer is required as this will share the http server.
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.send('something');
});
app.route("/socket").attach(new wws.AttachableSocket(wss));
Here is our wrapped version of the ws module designed for integration with our package. The syntax is inspired by Python websockets and uses the javascript promises for asynchronous usage.
const wws = require("wae-ws"); // You will not need to import the ws package, but will need the ext module.
app.route("/socket").attach(new wws.WebSockServer(async(ws)=>{
await ws.send("somthing");
for await (message of ws.messages()) {
console.log('received: %s', message);
}
// You can still access the raw socket (ws.WebSocket)
ws.socket.send("somthing else");
}));
- 0.0.1 - Moved from main package to separate package
- 0.0.2 - Fixed bugs and added the ability to access raw socket in wrapped variant