remote js executor block io on 'loadJS' added

This commit is contained in:
王劲鹏
2019-10-22 10:25:10 +08:00
committed by unknown
parent 9c7c6a411e
commit 5d2ef87325
8 changed files with 174 additions and 11 deletions

1
remote/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules/

20
remote/index.js Normal file
View File

@@ -0,0 +1,20 @@
const WebSocket = require('ws')
const vm = require("vm")
const wss = new WebSocket.Server({ port: 2080 })
var sandbox = {}
var context = vm.createContext(sandbox)
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
let messageObject = JSON.parse(message)
switch(messageObject.cmd) {
case "loadJS":
let result = vm.runInContext(messageObject.script, sandbox)
ws.send(JSON.stringify({cmd: 'loadJS', result: String(result)}))
break
case "evaluateJS":
break
}
})
})

21
remote/package-lock.json generated Normal file
View File

@@ -0,0 +1,21 @@
{
"name": "remote",
"version": "0.1.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"async-limiter": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz",
"integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ=="
},
"ws": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.0.tgz",
"integrity": "sha512-+SqNqFbwTm/0DC18KYzIsMTnEWpLwJsiasW/O17la4iDRRIO9uaHbvKiAS3AHgTiuuWerK/brj4O6MYZkei9xg==",
"requires": {
"async-limiter": "^1.0.0"
}
}
}
}

10
remote/package.json Normal file
View File

@@ -0,0 +1,10 @@
{
"name": "remote",
"version": "0.1.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"ws": "^7.2.0"
}
}