diff --git a/chatiframe1.html b/chatiframe1.html
index d0d4834..17f0242 100644
--- a/chatiframe1.html
+++ b/chatiframe1.html
@@ -1030,9 +1030,20 @@
Nostr keys
this.cleanupRelays();
// Set up a periodic cleanup to ensure no extension relays are added
- setInterval(() => {
- this.cleanupRelays();
- }, 2000); // Check every 2 seconds (more aggressive)
+ if (this._relayCleanupInterval) {
+ clearInterval(this._relayCleanupInterval);
+ }
+ this._relayCleanupInterval = setInterval(() => {
+ if (!document.hidden) {
+ this.cleanupRelays();
+ }
+ }, 30000); // Check every 30 seconds
+
+ document.addEventListener('visibilitychange', () => {
+ if (!document.hidden) {
+ this.cleanupRelays();
+ }
+ });
// Set up relay status tracking (only for the 2 configured relays)
if (this.ndk.pool) {
diff --git a/index.html b/index.html
index 337b19c..5aaa4e6 100644
--- a/index.html
+++ b/index.html
@@ -2327,23 +2327,31 @@ {
+ this._loadedMetadataListener = () => {
this.duration = audio.duration;
- });
+ };
+ audio.addEventListener('loadedmetadata', this._loadedMetadataListener);
// Update duration when duration changes
- audio.addEventListener('durationchange', () => {
+ this._durationChangeListener = () => {
this.duration = audio.duration;
- });
+ };
+ audio.addEventListener('durationchange', this._durationChangeListener);
// Try to listen for ICY metadata updates (non-standard, browser-dependent)
// Some browsers may fire metadataupdate events for Icecast streams
if ('onmetadataupdate' in audio || 'addEventListener' in audio) {
- const metadataHandler = (e) => {
+ this._metadataHandler = (e) => {
// Try to extract metadata from event or audio element
if (e && e.metadata) {
const metadata = e.metadata;
@@ -2387,8 +2397,8 @@ {
- setTimeout(setupAudioListeners, 100);
+ this.$watch('srcUrl', (value) => {
+ if (!value) {
+ this.teardownAudioListeners();
+ this._audioElement = null;
+ if (this._audioSetupTimeout) {
+ clearTimeout(this._audioSetupTimeout);
+ this._audioSetupTimeout = null;
+ }
+ return;
+ }
+
+ this.$nextTick(() => {
+ setupAudioListeners();
+ });
});
// Wait for router to be initialized by app.js
@@ -2484,6 +2506,38 @@