Created
July 10, 2024 07:45
-
-
Save bkram/870155da8ff085911adcaa31e316bc81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/web/js/3las/3las.js b/web/js/3las/3las.js | |
index 3ec297f..97c8ff0 100644 | |
--- a/web/js/3las/3las.js | |
+++ b/web/js/3las/3las.js | |
@@ -120,19 +120,27 @@ var _3LAS = /** @class */ (function () { | |
this.Fallback.OnSocketConnect(); | |
this.Fallback.Init(this.WebSocket); | |
}; | |
- _3LAS.prototype.OnSocketDisconnect = function () { | |
- this.Logger.Log("Lost connection to server."); | |
- this.Fallback.OnSocketDisconnect(); | |
- this.Fallback.Reset(); | |
- if (this.ConnectivityFlag) { | |
- this.ConnectivityFlag = false; | |
- if (this.ConnectivityCallback) | |
- this.ConnectivityCallback(false); | |
- } | |
+_3LAS.prototype.OnSocketDisconnect = function () { | |
+ this.Logger.Log("Lost connection to server."); | |
+ this.Fallback.OnSocketDisconnect(); | |
+ this.Fallback.Reset(); | |
+ | |
+ if (this.ConnectivityFlag) { | |
+ this.ConnectivityFlag = false; | |
+ if (this.ConnectivityCallback) | |
+ this.ConnectivityCallback(false); | |
+ } | |
+ | |
+ if (shouldReconnect) { | |
this.Start(); | |
- }; | |
+ } else { | |
+ this.Logger.Log("Reconnection is disabled."); | |
+ } | |
+}; | |
+ | |
+ | |
_3LAS.prototype.OnSocketDataReady = function (data) { | |
this.Fallback.OnSocketDataReady(data); | |
}; | |
return _3LAS; | |
-}()); | |
\ No newline at end of file | |
+}()); | |
diff --git a/web/js/3las/main.js b/web/js/3las/main.js | |
index 4812bed..6bc52f0 100644 | |
--- a/web/js/3las/main.js | |
+++ b/web/js/3las/main.js | |
@@ -1,43 +1,67 @@ | |
const DefaultVolume = 0.5; | |
let Stream; | |
+let shouldReconnect = true; | |
function Init(_ev) { | |
+ $(".playbutton").off('click').on('click', OnPlayButtonClick); // Ensure only one event handler is attached | |
+ $("#volumeSlider").off("input").on("input", updateVolume); // Ensure only one event handler is attached | |
+} | |
+ | |
+function createStream() { | |
try { | |
const settings = new _3LAS_Settings(); | |
- if (!Stream) { // Ensure Stream is not re-initialized | |
- Stream = new _3LAS(null, settings); | |
- } | |
+ Stream = new _3LAS(null, settings); | |
+ Stream.ConnectivityCallback = OnConnectivityCallback; | |
} catch (error) { | |
- console.log(error); | |
- return; | |
+ console.error("Initialization Error: ", error); | |
} | |
+} | |
- Stream.ConnectivityCallback = OnConnectivityCallback; | |
- $(".playbutton").off('click').on('click', OnPlayButtonClick); // Ensure only one event handler is attached | |
- $("#volumeSlider").off("input").on("input", updateVolume); // Ensure only one event handler is attached | |
+function destroyStream() { | |
+ if (Stream) { | |
+ Stream.Stop(); | |
+ Stream = null; | |
+ } | |
} | |
function OnConnectivityCallback(isConnected) { | |
- Stream.Volume = isConnected ? 1.0 : DefaultVolume; | |
+ console.log("Connectivity changed:", isConnected); | |
+ if (Stream) { | |
+ Stream.Volume = isConnected ? 1.0 : DefaultVolume; | |
+ } else { | |
+ console.warn("Stream is not initialized."); | |
+ } | |
} | |
function OnPlayButtonClick(_ev) { | |
const $playbutton = $('.playbutton'); | |
- $playbutton.find('.fa-solid').toggleClass('fa-play fa-stop'); | |
- | |
- if (Stream.ConnectivityFlag) { | |
- Stream.Stop(); | |
+ if (Stream) { | |
+ console.log("Stopping stream..."); | |
+ shouldReconnect = false; | |
+ destroyStream(); | |
+ $playbutton.find('.fa-solid').toggleClass('fa-stop fa-play'); | |
} else { | |
+ console.log("Starting stream..."); | |
+ shouldReconnect = true; | |
+ createStream(); | |
Stream.Start(); | |
- $playbutton.addClass('bg-gray').prop('disabled', true); | |
- setTimeout(() => { | |
- $playbutton.removeClass('bg-gray').prop('disabled', false); | |
- }, 3000); | |
+ $playbutton.find('.fa-solid').toggleClass('fa-play fa-stop'); | |
} | |
+ $playbutton.addClass('bg-gray').prop('disabled', true); | |
+ setTimeout(() => { | |
+ $playbutton.removeClass('bg-gray').prop('disabled', false); | |
+ }, 3000); | |
} | |
function updateVolume() { | |
- Stream.Volume = $(this).val(); | |
+ if (Stream) { | |
+ const newVolume = $(this).val(); | |
+ console.log("Volume updated to:", newVolume); | |
+ Stream.Volume = newVolume; | |
+ } else { | |
+ console.warn("Stream is not initialized."); | |
+ } | |
} | |
-$(document).ready(Init); | |
\ No newline at end of file | |
+$(document).ready(Init); | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment