From 51eeef00a619cdf0a929fdfc6824ec82cb666aea Mon Sep 17 00:00:00 2001 From: Sky-High Date: Tue, 8 Aug 2023 21:23:09 +0200 Subject: [PATCH 1/7] fix-cast-with-localhost-server --- src/plugins/chromecastPlayer/plugin.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/plugins/chromecastPlayer/plugin.js b/src/plugins/chromecastPlayer/plugin.js index 569e347cd2..38ac2c8660 100644 --- a/src/plugins/chromecastPlayer/plugin.js +++ b/src/plugins/chromecastPlayer/plugin.js @@ -335,16 +335,25 @@ class CastPlayer { apiClient = ServerConnections.currentApiClient(); } + /* If serverAddress is localhost,this address can not be used for the cast receiver device. + * Use the local address (ULA, Unique Local Address) in that case. + */ + const srvAddress = apiClient.serverAddress(); + const srvLocalAddress = srvAddress.startsWith('http://localhost') || srvAddress.startsWith('http://127.') || srvAddress.startsWith('http://[::1]') + ? apiClient.serverInfo().LocalAddress : srvAddress; + message = Object.assign(message, { userId: apiClient.getCurrentUserId(), deviceId: apiClient.deviceId(), accessToken: apiClient.accessToken(), - serverAddress: apiClient.serverAddress(), + serverAddress: srvLocalAddress, serverId: apiClient.serverId(), serverVersion: apiClient.serverVersion(), receiverName: receiverName }); + console.debug('cc: message{'+message.command+'; '+srvAddress+' -> '+srvLocalAddress+'}'); + const bitrateSetting = appSettings.maxChromecastBitrate(); if (bitrateSetting) { message.maxBitrate = bitrateSetting; From 7746795730a3a2ff9a7bc3618064817496530694 Mon Sep 17 00:00:00 2001 From: Sky-High Date: Tue, 8 Aug 2023 22:14:00 +0200 Subject: [PATCH 2/7] fix-sonar-and-lint --- src/plugins/chromecastPlayer/plugin.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/chromecastPlayer/plugin.js b/src/plugins/chromecastPlayer/plugin.js index 38ac2c8660..7a5e971228 100644 --- a/src/plugins/chromecastPlayer/plugin.js +++ b/src/plugins/chromecastPlayer/plugin.js @@ -339,8 +339,9 @@ class CastPlayer { * Use the local address (ULA, Unique Local Address) in that case. */ const srvAddress = apiClient.serverAddress(); - const srvLocalAddress = srvAddress.startsWith('http://localhost') || srvAddress.startsWith('http://127.') || srvAddress.startsWith('http://[::1]') - ? apiClient.serverInfo().LocalAddress : srvAddress; + const prefix = 'http' + ':' + '//'; + const checkLocalhost = srvAddress.startsWith(prefix + 'localhost') || srvAddress.startsWith(prefix + '127.') || srvAddress.startsWith(prefix + '[::1]') + const srvLocalAddress = checkLocalhost ? apiClient.serverInfo().LocalAddress : srvAddress; message = Object.assign(message, { userId: apiClient.getCurrentUserId(), @@ -352,7 +353,7 @@ class CastPlayer { receiverName: receiverName }); - console.debug('cc: message{'+message.command+'; '+srvAddress+' -> '+srvLocalAddress+'}'); + console.debug('cc: message{' + message.command + '; ' + srvAddress + ' -> ' + srvLocalAddress + '}'); const bitrateSetting = appSettings.maxChromecastBitrate(); if (bitrateSetting) { From a42c31d6c038af29037e89a7cf16ee6f9c5f1855 Mon Sep 17 00:00:00 2001 From: Sky-High Date: Tue, 8 Aug 2023 22:19:30 +0200 Subject: [PATCH 3/7] fix-sonar-and-lint2 --- src/plugins/chromecastPlayer/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/chromecastPlayer/plugin.js b/src/plugins/chromecastPlayer/plugin.js index 7a5e971228..efae979c17 100644 --- a/src/plugins/chromecastPlayer/plugin.js +++ b/src/plugins/chromecastPlayer/plugin.js @@ -340,7 +340,7 @@ class CastPlayer { */ const srvAddress = apiClient.serverAddress(); const prefix = 'http' + ':' + '//'; - const checkLocalhost = srvAddress.startsWith(prefix + 'localhost') || srvAddress.startsWith(prefix + '127.') || srvAddress.startsWith(prefix + '[::1]') + const checkLocalhost = srvAddress.startsWith(prefix + 'localhost') || srvAddress.startsWith(prefix + '127.') || srvAddress.startsWith(prefix + '[::1]'); const srvLocalAddress = checkLocalhost ? apiClient.serverInfo().LocalAddress : srvAddress; message = Object.assign(message, { From 4076148580e831561bfce12afff490f60aa4149a Mon Sep 17 00:00:00 2001 From: Sky-High Date: Tue, 8 Aug 2023 22:47:41 +0200 Subject: [PATCH 4/7] fix-sonar-and-lint3 --- src/plugins/chromecastPlayer/plugin.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/plugins/chromecastPlayer/plugin.js b/src/plugins/chromecastPlayer/plugin.js index efae979c17..ff773e2a2a 100644 --- a/src/plugins/chromecastPlayer/plugin.js +++ b/src/plugins/chromecastPlayer/plugin.js @@ -27,12 +27,10 @@ function sendConnectionResult(isOk) { if (resolve) { resolve(); } + } else if (reject) { + reject(); } else { - if (reject) { - reject(); - } else { - playbackManager.removeActivePlayer(PlayerName); - } + playbackManager.removeActivePlayer(PlayerName); } } @@ -294,7 +292,7 @@ class CastPlayer { loadMedia(options, command) { if (!this.session) { console.debug('no session'); - return Promise.reject(); + return Promise.reject(new Error('no session')); } // convert items to smaller stubs to send minimal amount of information @@ -602,7 +600,7 @@ class ChromecastPlayer { currentResolve = null; currentReject = null; - return Promise.reject(); + return Promise.reject(new Error('tryPair failed')); } } From d77379043922c88465a065a7b8504c8dafec8d7b Mon Sep 17 00:00:00 2001 From: Sky-High Date: Sun, 10 Sep 2023 20:11:02 +0200 Subject: [PATCH 5/7] Use URL API for better readability --- src/plugins/chromecastPlayer/plugin.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins/chromecastPlayer/plugin.js b/src/plugins/chromecastPlayer/plugin.js index ff773e2a2a..77d0f27c98 100644 --- a/src/plugins/chromecastPlayer/plugin.js +++ b/src/plugins/chromecastPlayer/plugin.js @@ -336,22 +336,22 @@ class CastPlayer { /* If serverAddress is localhost,this address can not be used for the cast receiver device. * Use the local address (ULA, Unique Local Address) in that case. */ - const srvAddress = apiClient.serverAddress(); - const prefix = 'http' + ':' + '//'; - const checkLocalhost = srvAddress.startsWith(prefix + 'localhost') || srvAddress.startsWith(prefix + '127.') || srvAddress.startsWith(prefix + '[::1]'); - const srvLocalAddress = checkLocalhost ? apiClient.serverInfo().LocalAddress : srvAddress; + const serverAddress = apiClient.serverAddress(); + const hostname = (new URL(serverAddress)).hostname; + const isLocalhost = hostname === 'localhost' || hostname.startsWith('127.') || hostname === '[::1]'; + const serverLocalAddress = isLocalhost ? apiClient.serverInfo().LocalAddress : serverAddress; message = Object.assign(message, { userId: apiClient.getCurrentUserId(), deviceId: apiClient.deviceId(), accessToken: apiClient.accessToken(), - serverAddress: srvLocalAddress, + serverAddress: serverLocalAddress, serverId: apiClient.serverId(), serverVersion: apiClient.serverVersion(), receiverName: receiverName }); - console.debug('cc: message{' + message.command + '; ' + srvAddress + ' -> ' + srvLocalAddress + '}'); + console.debug('cc: message{' + message.command + '; ' + serverAddress + ' -> ' + serverLocalAddress + '}'); const bitrateSetting = appSettings.maxChromecastBitrate(); if (bitrateSetting) { From 70c1b5b6e4f46d37715c209f09d77fe1c2e90028 Mon Sep 17 00:00:00 2001 From: Sky-High Date: Sun, 10 Sep 2023 21:16:40 +0200 Subject: [PATCH 6/7] satisfy eslint --- src/plugins/chromecastPlayer/plugin.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/chromecastPlayer/plugin.js b/src/plugins/chromecastPlayer/plugin.js index 77d0f27c98..732ae4e9da 100644 --- a/src/plugins/chromecastPlayer/plugin.js +++ b/src/plugins/chromecastPlayer/plugin.js @@ -337,6 +337,7 @@ class CastPlayer { * Use the local address (ULA, Unique Local Address) in that case. */ const serverAddress = apiClient.serverAddress(); + // eslint-disable-next-line compat/compat const hostname = (new URL(serverAddress)).hostname; const isLocalhost = hostname === 'localhost' || hostname.startsWith('127.') || hostname === '[::1]'; const serverLocalAddress = isLocalhost ? apiClient.serverInfo().LocalAddress : serverAddress; From 31f035e3590ec6ef4a23d838c4baf14c6406db2b Mon Sep 17 00:00:00 2001 From: Sky-High Date: Tue, 12 Sep 2023 23:28:25 +0200 Subject: [PATCH 7/7] update module name in log message --- src/plugins/chromecastPlayer/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/chromecastPlayer/plugin.js b/src/plugins/chromecastPlayer/plugin.js index 732ae4e9da..e5663c2f08 100644 --- a/src/plugins/chromecastPlayer/plugin.js +++ b/src/plugins/chromecastPlayer/plugin.js @@ -352,7 +352,7 @@ class CastPlayer { receiverName: receiverName }); - console.debug('cc: message{' + message.command + '; ' + serverAddress + ' -> ' + serverLocalAddress + '}'); + console.debug('[chromecastPlayer] message{' + message.command + '; ' + serverAddress + ' -> ' + serverLocalAddress + '}'); const bitrateSetting = appSettings.maxChromecastBitrate(); if (bitrateSetting) {