This repository has been archived on 2021-06-30. You can view files and clone it, but cannot push or open issues or pull requests.
node-polyglot/app.js

35 lines
641 B
JavaScript
Raw Normal View History

require('dotenv').config();
const WebSocket = require('ws');
const WebSocketStream = require('websocket-stream');
2018-08-29 12:24:38 +00:00
class WebSocketServer {
constructor() {
this.io = new WebSocket.Server({
port: process.env.PORT || 1337,
});
this.stream = WebSocketStream.createServer({
server: this.io,
}, this.handleStream)
this.createEventListeners();
}
2018-08-29 12:24:38 +00:00
handleStream(stream, req) {
console.log(stream);
}
createEventListeners() {
this.io.on('connection', (io) => {
io.on('message', (msg) => {
console.log('Recieved: %s', msg);
})
})
}
2018-08-29 12:24:38 +00:00
}
const wss = new WebSocketServer();