From d041b49fd1fe144ca80279ad106198a0b86d5de6 Mon Sep 17 00:00:00 2001 From: masad-frost Date: Mon, 25 Mar 2019 16:53:23 -0700 Subject: [PATCH] Pass socket creator function instead of url --- core/rfb.js | 10 +++------- core/websock.js | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/core/rfb.js b/core/rfb.js index 89b8130d..6c672d68 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -34,18 +34,15 @@ const DISCONNECT_TIMEOUT = 3; const DEFAULT_BACKGROUND = 'rgb(40, 40, 40)'; export default class RFB extends EventTargetMixin { - constructor(target, url, options) { + constructor(target, websocketCreator, options) { if (!target) { throw new Error("Must specify target"); } - if (!url) { - throw new Error("Must specify URL"); - } super(); this._target = target; - this._url = url; + this._websocketCreator = websocketCreator; // Connection details options = options || {}; @@ -393,11 +390,10 @@ export default class RFB extends EventTargetMixin { _connect() { Log.Debug(">> RFB.connect"); - Log.Info("connecting to " + this._url); try { // WebSocket.onopen transitions to the RFB init states - this._sock.open(this._url, ['binary']); + this._sock.open(this._websocketCreator); } catch (e) { if (e.name === 'SyntaxError') { this._fail("Invalid host or port (" + e + ")"); diff --git a/core/websock.js b/core/websock.js index 51b9a66f..2c202de6 100644 --- a/core/websock.js +++ b/core/websock.js @@ -178,10 +178,10 @@ export default class Websock { this._websocket = null; } - open(uri, protocols) { + open(socketCreator) { this.init(); - this._websocket = new WebSocket(uri, protocols); + this._websocket = socketCreator(); this._websocket.binaryType = 'arraybuffer'; this._websocket.onmessage = this._recv_message.bind(this);