wss testing

This commit is contained in:
2019-04-26 01:44:01 +10:00
parent f9b5512073
commit 449db92e01
3 changed files with 49 additions and 6 deletions

20
package-lock.json generated
View File

@@ -401,6 +401,17 @@
"snekfetch": "^3.6.4", "snekfetch": "^3.6.4",
"tweetnacl": "^1.0.0", "tweetnacl": "^1.0.0",
"ws": "^4.0.0" "ws": "^4.0.0"
},
"dependencies": {
"ws": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz",
"integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==",
"requires": {
"async-limiter": "~1.0.0",
"safe-buffer": "~5.1.0"
}
}
} }
}, },
"duplexify": { "duplexify": {
@@ -1831,12 +1842,11 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}, },
"ws": { "ws": {
"version": "4.1.0", "version": "6.2.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-4.1.0.tgz", "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz",
"integrity": "sha512-ZGh/8kF9rrRNffkLFV4AzhvooEclrOH0xaugmqGsIfFgOE/pIz4fMc4Ef+5HSQqTEug2S9JZIWDR47duDSLfaA==", "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==",
"requires": { "requires": {
"async-limiter": "~1.0.0", "async-limiter": "~1.0.0"
"safe-buffer": "~5.1.0"
} }
}, },
"xtend": { "xtend": {

View File

@@ -15,7 +15,8 @@
"ping": "^0.2.2", "ping": "^0.2.2",
"promise-mysql": "^3.3.1", "promise-mysql": "^3.3.1",
"readline": "^1.3.0", "readline": "^1.3.0",
"request": "^2.88.0" "request": "^2.88.0",
"ws": "^6.2.1"
}, },
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {

32
plugins/wss.js Normal file
View File

@@ -0,0 +1,32 @@
const fs = require('fs');
const https = require('https');
const WebSocket = require('ws');
const fs = require("fs")
module.exports = {
name: "Websockets Server (8080)",
init: (dclient) => {
client = dclient
const server = https.createServer({
cert: fs.readFileSync('./cert.pem'),
key: fs.readFileSync('./privkey.pem')
});
const wss = new WebSocket.Server({ server });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
ws.send(`something ${message}`);
});
ws.send('something');
});
server.listen(8080);
}
}