From 5968eef349ec8d0af9c06b8ffe1e913d1d9d047b Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Wed, 23 Jan 2019 13:00:41 +0000 Subject: [PATCH] fix: simulator proxy with ws --- src/lib/modules/blockchain_process/simulator.js | 4 ++++ src/lib/utils/utils.js | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/lib/modules/blockchain_process/simulator.js b/src/lib/modules/blockchain_process/simulator.js index bb7c64b4f..64a8afc29 100644 --- a/src/lib/modules/blockchain_process/simulator.js +++ b/src/lib/modules/blockchain_process/simulator.js @@ -86,6 +86,10 @@ class Simulator { if(useProxy){ let ipcObject = new Ipc({ipcRole: 'client'}); + if (this.blockchainConfig.wsRPC) { + return new Proxy(ipcObject).serve(host, port, true, this.blockchainConfig.wsOrigins, []); + } + new Proxy(ipcObject).serve(host, port, false); } } diff --git a/src/lib/utils/utils.js b/src/lib/utils/utils.js index d1138afa0..4d32d39d8 100644 --- a/src/lib/utils/utils.js +++ b/src/lib/utils/utils.js @@ -127,7 +127,9 @@ function pingEndpoint(host, port, type, protocol, origin, callback) { }; const handleSuccess = (req, closeMethod, event) => { - req.once(event, () => { handleEvent(req, closeMethod); }); + req.once(event, () => { + handleEvent(req, closeMethod); + }); }; const handleRequest = (req, closeMethod, event) => { @@ -136,10 +138,8 @@ function pingEndpoint(host, port, type, protocol, origin, callback) { }; if (type === 'ws') { - const req = new (require('ws'))( - `${protocol === 'https' ? 'wss' : 'ws'}://${_host}:${port}/`, - origin ? {origin} : {} - ); + const url = `${protocol === 'https' ? 'wss' : 'ws'}://${_host}:${port}/`; + const req = new (require('ws'))(url, origin ? {origin} : {}); handleRequest(req, 'close', 'open'); } else { const headers = origin ? {Origin: origin} : {};