diff options
| author | RblSb <msrblsb@gmail.com> | 2020-12-19 18:04:47 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-12-19 18:04:47 +0300 |
| commit | 6190cb511b481fbf2c0ea39e90101dbea371fbf5 (patch) | |
| tree | 6d4ed0ebe309c6b3125649813e668a3eccbc7529 | |
| parent | c32677a0b21d66c0b9b191cdffeb8281324373c3 (diff) | |
Improve ws server url
closes #14
| -rw-r--r-- | res/client.js | 28 | ||||
| -rw-r--r-- | src/client/Main.hx | 18 |
2 files changed, 20 insertions, 26 deletions
diff --git a/res/client.js b/res/client.js index df22653..ed6c43a 100644 --- a/res/client.js +++ b/res/client.js @@ -907,7 +907,7 @@ client_JsApi.fireVideoRemoveEvents = function(item) { var _g1 = client_JsApi.videoRemove; while(_g < _g1.length) _g1[_g++](item); }; -var client_Main = function(host,port) { +var client_Main = function() { this.matchNumbers = new EReg("^-?[0-9]+$",""); this.mask = new EReg("\\${([0-9]+)-([0-9]+)}","g"); this.isConnected = false; @@ -920,15 +920,9 @@ var client_Main = function(host,port) { this.isSyncActive = true; var _gthis = this; this.player = new client_Player(this); - if(host == null) { - host = $global.location.hostname; - } - if(host == "") { - host = "localhost"; - } - this.host = host; - if(port == null) { - port = $global.location.port; + this.host = $global.location.hostname; + if(this.host == "") { + this.host = "localhost"; } client_Settings.init({ version : 2, name : "", hash : "", isExtendedPlayer : false, playerSize : 1, chatSize : 300, synchThreshold : 2, isSwapped : false, isUserListHidden : true, latestLinks : [], hotkeysEnabled : true},$bind(this,this.settingsPatcher)); this.settings = client_Settings.read(); @@ -945,7 +939,7 @@ var client_Main = function(host,port) { Lang.init("langs",function() { client_Buttons.initTextButtons(_gthis); client_Buttons.initHotkeys(_gthis,_gthis.player); - _gthis.openWebSocket(host,port); + _gthis.openWebSocket(); }); client_JsApi.init(this,this.player); }; @@ -975,14 +969,16 @@ client_Main.prototype = { } this.send({ type : "GetTime"}); } - ,openWebSocket: function(host,port) { + ,openWebSocket: function() { var _gthis = this; - var colonPort = port.length > 0 ? ":" + port : port; var protocol = "ws:"; if($global.location.protocol == "https:") { protocol = "wss:"; } - this.ws = new WebSocket("" + protocol + "//" + host + colonPort); + var port = $global.location.port; + var colonPort = port.length > 0 ? ":" + port : port; + var path = $global.location.pathname; + this.ws = new WebSocket("" + protocol + "//" + this.host + colonPort + path); this.ws.onmessage = $bind(this,this.onMessage); this.ws.onopen = function() { _gthis.serverMessage(1); @@ -994,9 +990,7 @@ client_Main.prototype = { } _gthis.isConnected = false; _gthis.player.pause(); - return haxe_Timer.delay(function() { - _gthis.openWebSocket(host,port); - },2000); + return haxe_Timer.delay($bind(_gthis,_gthis.openWebSocket),2000); }; } ,initListeners: function() { diff --git a/src/client/Main.hx b/src/client/Main.hx index 6c40b6c..d567d92 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -42,12 +42,10 @@ class Main { static function main():Void new Main(); - function new(?host:String, ?port:String) { + function new() { player = new Player(this); - if (host == null) host = Browser.location.hostname; + host = Browser.location.hostname; if (host == "") host = "localhost"; - this.host = host; - if (port == null) port = Browser.location.port; final defaults:ClientSettings = { version: SETTINGS_VERSION, @@ -78,7 +76,7 @@ class Main { Lang.init("langs", () -> { Buttons.initTextButtons(this); Buttons.initHotkeys(this, player); - openWebSocket(host, port); + openWebSocket(); }); JsApi.init(this, player); } @@ -100,11 +98,13 @@ class Main { send({type: GetTime}); } - function openWebSocket(host:String, port:String):Void { - final colonPort = port.length > 0 ? ':$port' : port; + function openWebSocket():Void { var protocol = "ws:"; if (Browser.location.protocol == "https:") protocol = "wss:"; - ws = new WebSocket('$protocol//$host$colonPort'); + final port = Browser.location.port; + final colonPort = port.length > 0 ? ':$port' : port; + final path = Browser.location.pathname; + ws = new WebSocket('$protocol//$host$colonPort$path'); ws.onmessage = onMessage; ws.onopen = () -> { serverMessage(1); @@ -116,7 +116,7 @@ class Main { if (isConnected) serverMessage(2); isConnected = false; player.pause(); - Timer.delay(() -> openWebSocket(host, port), 2000); + Timer.delay(openWebSocket, 2000); } } |
