Merge pull request #4746 from Sky-High/cast-with-localhost-server

This commit is contained in:
Bill Thornton 2023-09-12 20:46:02 -04:00 committed by GitHub
commit c506d0b753
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,13 +27,11 @@ function sendConnectionResult(isOk) {
if (resolve) {
resolve();
}
} else {
if (reject) {
} else if (reject) {
reject();
} else {
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
@ -335,16 +333,27 @@ 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 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;
message = Object.assign(message, {
userId: apiClient.getCurrentUserId(),
deviceId: apiClient.deviceId(),
accessToken: apiClient.accessToken(),
serverAddress: apiClient.serverAddress(),
serverAddress: serverLocalAddress,
serverId: apiClient.serverId(),
serverVersion: apiClient.serverVersion(),
receiverName: receiverName
});
console.debug('[chromecastPlayer] message{' + message.command + '; ' + serverAddress + ' -> ' + serverLocalAddress + '}');
const bitrateSetting = appSettings.maxChromecastBitrate();
if (bitrateSetting) {
message.maxBitrate = bitrateSetting;
@ -592,7 +601,7 @@ class ChromecastPlayer {
currentResolve = null;
currentReject = null;
return Promise.reject();
return Promise.reject(new Error('tryPair failed'));
}
}