From 857615acfcb07e710e638500f4da3979d63d922d Mon Sep 17 00:00:00 2001 From: NoobishSVK Date: Sun, 28 Jan 2024 21:51:34 +0100 Subject: [PATCH] pause/play for stream + ip bugfix --- index.js | 10 +++--- web/js/3las/3las.js | 45 ++++++++++++++++++++++++ web/js/3las/main.js | 15 ++++---- web/js/3las/util/3las.websocketclient.js | 5 +++ 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 3723b19..06db017 100644 --- a/index.js +++ b/index.js @@ -54,12 +54,14 @@ wss.on('connection', (ws, request) => { response.on('end', () => { try { const locationInfo = JSON.parse(data); - if(locationInfo.country == 'undefined') { - logInfo(`Web client \x1b[32mconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]`); + console.log(locationInfo.country); + if(locationInfo.country === undefined) { + logInfo(`Web client \x1b[32mconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]\x1b[0m`); + } else { + logInfo(`Web client \x1b[32mconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]\x1b[0m Location: ${locationInfo.city}, ${locationInfo.region}, ${locationInfo.country}`); } - logInfo(`Web client \x1b[32mconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}] Location: ${locationInfo.city}, ${locationInfo.region}, ${locationInfo.country}`); } catch (error) { - logInfo(`Web client \x1b[32mconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]`); + logInfo(`Web client \x1b[32mconnected\x1b[0m (${clientIp}) \x1b[90m[${currentUsers}]\x1b[0m`); } }); }); diff --git a/web/js/3las/3las.js b/web/js/3las/3las.js index 7879f4e..e33f318 100644 --- a/web/js/3las/3las.js +++ b/web/js/3las/3las.js @@ -80,6 +80,51 @@ var _3LAS = /** @class */ (function () { throw new Error(); } }; + _3LAS.prototype.Stop = function () { + try { + // Close WebSocket connection + if (this.WebSocket) { + this.WebSocket.Close(); + this.WebSocket.OnClose(); + this.WebSocket = null; + this.Logger.Log("WebSocket connection closed."); + } + + // Stop WakeLock if it exists and is an Android device + if (isAndroid && this.WakeLock) { + this.WakeLock.End(); + this.Logger.Log("WakeLock stopped."); + } + + // Reset WebRTC if it exists + if (this.WebRTC) { + this.WebRTC.OnSocketDisconnect(); + this.WebRTC.Reset(); + this.WebRTC.Stop(); + this.Logger.Log("WebRTC reset."); + } + + // Reset Fallback if it exists + if (this.Fallback) { + this.Fallback.OnSocketDisconnect(); + this.Fallback.Stop(); + this.Fallback.Reset(); + this.Logger.Log("Fallback reset."); + } + + // Reset connectivity flag + if (this.ConnectivityFlag) { + this.ConnectivityFlag = null; + if (this.ConnectivityCallback) { + this.ConnectivityCallback(null); + } + } + + this.Logger.Log("3LAS stopped successfully."); + } catch (e) { + this.Logger.Log("Error while stopping 3LAS: " + e); + } + }; _3LAS.prototype.OnActivity = function () { if (this.ActivityCallback) this.ActivityCallback(); diff --git a/web/js/3las/main.js b/web/js/3las/main.js index b4d9170..a20e063 100644 --- a/web/js/3las/main.js +++ b/web/js/3las/main.js @@ -34,16 +34,17 @@ function OnConnectivityCallback(isConnected) { function OnPlayButtonClick(_ev) { try { - Stream.Start(); - $('#playbutton').prop('disabled', true); - $('#playbutton').find('.fa-solid').removeClass('fa-play').addClass('fa-pause'); + if (Stream.ConnectivityFlag) { + Stream.Stop(); + $('#playbutton').find('.fa-solid').removeClass('fa-pause').addClass('fa-play'); + } else { + Stream.Start(); + $('#playbutton').find('.fa-solid').removeClass('fa-play').addClass('fa-pause'); + } } catch (_ex) { } } - function updateVolume() { Stream.Volume = $(this).val(); -} - -var lastTapTime = -1; \ No newline at end of file +} \ No newline at end of file diff --git a/web/js/3las/util/3las.websocketclient.js b/web/js/3las/util/3las.websocketclient.js index e290f43..e0dba71 100644 --- a/web/js/3las/util/3las.websocketclient.js +++ b/web/js/3las/util/3las.websocketclient.js @@ -69,6 +69,11 @@ var WebSocketClient = /** @class */ (function () { this.DisconnectCallback(); } }; + WebSocketClient.prototype.Close = function () { + if (this.Socket) { + this.Socket.close(); + } + }; // Handle incomping data WebSocketClient.prototype.OnMessage = function (ev) { // Trigger callback