This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/remote/index.js

22 lines
569 B
JavaScript
Raw Normal View History

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)
2019-10-22 18:01:10 +08:00
switch (messageObject.cmd) {
case "loadJS":
let result = vm.runInContext(messageObject.script, sandbox)
2019-10-22 18:01:10 +08:00
ws.send(JSON.stringify({ cmd: 'loadJS', result: String(result) }))
break
case "evaluateJS":
break
}
})
2019-10-22 18:01:10 +08:00
})