From 93a7b20b32b947c13d246a10e3959d102fa11d43 Mon Sep 17 00:00:00 2001 From: Amir Sanni <amirsanni@gmail.com> Date: Sat, 11 Apr 2020 15:51:52 +0100 Subject: [PATCH] Do not connect to web socket until after page load --- js/comm.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/js/comm.js b/js/comm.js index 2ecb4c3..849f93e 100644 --- a/js/comm.js +++ b/js/comm.js @@ -20,15 +20,23 @@ let wsChat; const room = getRoom(); -if(location.protocol === 'http:'){ - wsChat = new WebSocket("ws://localhost:8080/comm"); -} +window.addEventListener('load', function(){ + if(location.protocol === 'http:'){ + wsChat = new WebSocket("ws://localhost:8080/comm"); + } + + else{ + wsChat = new WebSocket("wss://localhost:8080/comm"); + } -else{ - wsChat = new WebSocket("wss://localhost:8080/comm"); -} + /* + ******************************************************************************************************************************** + ******************************************************************************************************************************** + ******************************************************************************************************************************** + ******************************************************************************************************************************** + ******************************************************************************************************************************** + */ -window.addEventListener('load', function(){ //startCounter();//shows the time spent in room /*