From 39e12465aa30c79799e9c443f0fa393a07019cef Mon Sep 17 00:00:00 2001 From: RblSb Date: Sun, 8 Mar 2020 09:43:48 +0300 Subject: Use wss protocol on https page --- res/client.js | 8 ++++++-- src/client/Main.hx | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/res/client.js b/res/client.js index 240d382..932f180 100644 --- a/res/client.js +++ b/res/client.js @@ -806,7 +806,11 @@ client_Main.prototype = { } ,openWebSocket: function(host,port) { var _gthis = this; - this.ws = new WebSocket("ws://" + host + ":" + port); + var protocol = "ws:"; + if(window.location.protocol == "https:") { + protocol = "wss:"; + } + this.ws = new WebSocket("" + protocol + "//" + host + ":" + port); this.ws.onmessage = $bind(this,this.onMessage); this.ws.onopen = function() { _gthis.serverMessage(1); @@ -973,7 +977,7 @@ client_Main.prototype = { var data = JSON.parse(e.data); var t = data.type; var t1 = t.charAt(0).toLowerCase() + HxOverrides.substr(t,1,null); - haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 258, className : "client.Main", methodName : "onMessage", customParams : [data[t1]]}); + haxe_Log.trace("Event: " + data.type,{ fileName : "src/client/Main.hx", lineNumber : 260, className : "client.Main", methodName : "onMessage", customParams : [data[t1]]}); switch(data.type) { case "AddVideo": this.player.addVideoItem(data.addVideo.item,data.addVideo.atEnd); diff --git a/src/client/Main.hx b/src/client/Main.hx index 918a81a..8edeb8f 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -67,7 +67,9 @@ class Main { } function openWebSocket(host:String, port:String):Void { - ws = new WebSocket('ws://$host:$port'); + var protocol = "ws:"; + if (Browser.location.protocol == "https:") protocol = "wss:"; + ws = new WebSocket('$protocol//$host:$port'); ws.onmessage = onMessage; ws.onopen = () -> { serverMessage(1); -- cgit v1.2.3