refactor router to open multiple ones

remixd
yann300 6 years ago
parent c9bea2d76b
commit c694ce46b5
  1. 15
      bin/remixd
  2. 6759
      package-lock.json
  3. 4
      package.json
  4. 17
      src/router.js
  5. 5
      src/websocket.js

@ -1,5 +1,6 @@
#!/usr/bin/env node
var Router = require('../src/router')
var servicesList = require('../src/servicesList')
var program = require('commander')
var startmistGeth = require('../src/services/startMistGeth')
var startFrontend = require('../src/services/startFrontend')
@ -17,6 +18,7 @@ program
.option('-a, --auto-mine', 'mine pending transactions')
.option('-r, --rpc <cors-domains>', 'start rpc server. Values are CORS domain')
.option('-rp, --rpc-port', 'rpc server port (default 8545)')
.option('--profiler', 'start profiler service')
.parse(process.argv)
console.log('example: --dev-path /home/devchains/chain1 --mist --geth --frontend /home/frontend --frontend-port 8084 --auto-mine')
program.outputHelp()
@ -43,8 +45,17 @@ if (program.frontend) {
if (program.sharedFolder) {
console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.')
console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolinc links are not forwarded to Remix IDE\n')
var router = new Router()
killCallBack.push(router.start(program.sharedFolder))
var sharedFolderrouter = new Router(65520, servicesList['sharedfolder'], (webSocket) => {
servicesList['sharedfolder'].setWebSocket(webSocket)
servicesList['sharedfolder'].setupNotifications(program.sharedFolder)
servicesList['sharedfolder'].sharedFolder(program.sharedFolder)
})
killCallBack.push(sharedFolderrouter.start())
}
if (program.profiler) {
var profilerRouter = new Router(65521, servicesList['profiler'])
killCallBack.push(profilerRouter.start())
}
// kill

6759
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -3,7 +3,9 @@
"version": "0.1.8-alpha.4",
"description": "remix server: allow accessing file system from remix.ethereum.org and start a dev environment (see help section)",
"main": "./src/index.js",
"bin" : { "remixd" : "./bin/remixd" },
"bin": {
"remixd": "./bin/remixd"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "./bin/remixd"

@ -1,17 +1,18 @@
var servicesList = require('./servicesList')
var Websocket = require('./websocket')
class Router {
start (sharedFolder) {
var websocket = new Websocket()
constructor (port, service, initCallback) {
this.port = port
this.service = service
this.initCallback = initCallback
}
start () {
var websocket = new Websocket(this.port)
this.websocket = websocket
this.websocket.start((message) => {
this.call(message.id, message.service, message.fn, message.args)
})
servicesList['sharedfolder'].setWebSocket(this.websocket)
servicesList['sharedfolder'].setupNotifications(sharedFolder)
servicesList['sharedfolder'].sharedFolder(sharedFolder)
console.log('Shared folder : ' + sharedFolder)
if (this.initCallback) this.initCallback(this.websocket)
return function () {
if (websocket) {
websocket.close()
@ -21,7 +22,7 @@ class Router {
call (callid, name, fn, args) {
try {
servicesList[name][fn](args, (error, data) => {
this.service[fn](args, (error, data) => {
var response = {
id: callid,
type: 'reply',

@ -3,8 +3,9 @@ var WebSocketServer = require('websocket').server
var http = require('http')
class WebSocket {
constructor () {
constructor (port) {
this.connection = null
this.port = port
}
start (callback) {
@ -14,7 +15,7 @@ class WebSocket {
response.end()
})
var loopback = '127.0.0.1'
this.server.listen(65520, loopback, function () {
this.server.listen(this.port, loopback, function () {
console.log((new Date()) + ' Remixd is listening on ' + loopback + ':65520')
})

Loading…
Cancel
Save