remove remote; add ws & types@ws

This commit is contained in:
王劲鹏 2019-10-22 20:09:14 +08:00 committed by pengfei.zhou
parent 9861cd60a6
commit 186b0dfb80
8 changed files with 42 additions and 76 deletions

View File

@ -14,6 +14,8 @@
* limitations under the License.
*/
import * as doric from './src/runtime/sandbox'
import * as WebSocket from "ws"
let global = new Function('return this')()
global.doric = doric
const contextId = "DoricDebug"
@ -21,6 +23,21 @@ global.context = doric.jsObtainContext(contextId)
global.Entry = doric.jsObtainEntry(contextId)
console.log('Start Server')
const wss = new WebSocket.Server({ port: 2080 })
var sandbox = {}
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message: string) {
let messageObject = JSON.parse(message)
switch (messageObject.cmd) {
case "loadJS":
break
case "evaluateJS":
break
}
})
})
global.injectGlobal = (objName: string, obj: string) => {
Reflect.set(global, objName, JSON.parse(obj))
}

View File

@ -22,6 +22,14 @@
"@types/node": "*"
}
},
"@types/ws": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.3.tgz",
"integrity": "sha512-yBTM0P05Tx9iXGq00BbJPo37ox68R5vaGTXivs6RGh/BQ6QP5zqZDGWdAO6JbRE/iR1l80xeGAwCQS2nMV9S/w==",
"requires": {
"@types/node": "*"
}
},
"acorn": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz",
@ -69,6 +77,11 @@
"resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.3.tgz",
"integrity": "sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ=="
},
"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=="
},
"atob": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz",
@ -2072,6 +2085,14 @@
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"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"
}
}
}
}

View File

@ -20,11 +20,13 @@
},
"homepage": "https://github.com/doric-pub/doric#readme",
"dependencies": {
"@types/ws": "^6.0.3",
"reflect-metadata": "^0.1.13",
"rollup": "^1.17.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-watch": "^4.3.1",
"tslib": "^1.10.0",
"typescript": "^3.5.3"
"typescript": "^3.5.3",
"ws": "^7.2.0"
}
}

1
remote/.gitignore vendored
View File

@ -1 +0,0 @@
node_modules/

View File

@ -1,21 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/index.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
},
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229
}
]
}

View File

@ -1,21 +0,0 @@
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
}
})
})

View File

@ -1,21 +0,0 @@
{
"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"
}
}
}
}

View File

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