mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 10:09:59 +00:00
Handle audio device support checking
This commit is contained in:
@@ -11,6 +11,7 @@ import selectorManager from "./selectorManager";
|
||||
|
||||
import { initMenus } from "./menus";
|
||||
import { initWhitelist } from "./whitelist";
|
||||
import { baseConfigStorage, fetchBaseConfig } from "../cast/googleapi";
|
||||
|
||||
const _ = browser.i18n.getMessage;
|
||||
|
||||
@@ -81,6 +82,31 @@ async function notifyBridgeCompat() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates locally-stored base config data if never downloaded or since
|
||||
* expired.
|
||||
*/
|
||||
async function cacheBaseConfig() {
|
||||
const { baseConfigUpdated } = await baseConfigStorage.get(
|
||||
"baseConfigUpdated"
|
||||
);
|
||||
|
||||
// If never updated or updated more than 48 hours ago
|
||||
if (
|
||||
!baseConfigUpdated ||
|
||||
(Date.now() - baseConfigUpdated) / 1000 >= 172800
|
||||
) {
|
||||
logger.info("Fetching updated Chromecast base config...");
|
||||
const baseConfig = await fetchBaseConfig();
|
||||
if (baseConfig) {
|
||||
await baseConfigStorage.set({
|
||||
baseConfig,
|
||||
baseConfigUpdated: Date.now()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let isInitialized = false;
|
||||
|
||||
async function init() {
|
||||
@@ -130,4 +156,5 @@ async function init() {
|
||||
});
|
||||
}
|
||||
|
||||
cacheBaseConfig();
|
||||
init();
|
||||
|
||||
@@ -4,6 +4,7 @@ import options from "../lib/options";
|
||||
import logger from "../lib/logger";
|
||||
|
||||
import { getMediaTypesForPageUrl } from "../lib/utils";
|
||||
import { BaseConfig, baseConfigStorage, getAppTag } from "../cast/googleapi";
|
||||
import { SessionRequest } from "../cast/sdk/classes";
|
||||
|
||||
import castManager from "./castManager";
|
||||
@@ -22,6 +23,16 @@ import {
|
||||
ReceiverSelectorMediaType
|
||||
} from "../types";
|
||||
|
||||
let baseConfig: BaseConfig;
|
||||
baseConfigStorage
|
||||
.get("baseConfig")
|
||||
.then(value => {
|
||||
baseConfig = value.baseConfig;
|
||||
})
|
||||
.catch(() => {
|
||||
logger.error("Failed to get Chromecast base config!");
|
||||
});
|
||||
|
||||
let sharedSelector: ReceiverSelector;
|
||||
async function getSelector() {
|
||||
if (!sharedSelector) {
|
||||
@@ -215,6 +226,12 @@ async function getSelection(
|
||||
// Ensure status manager is initialized
|
||||
await deviceManager.init();
|
||||
|
||||
let isRequestAppAudioCompatible: Optional<boolean>;
|
||||
if (castInstance?.appId) {
|
||||
const appTag = getAppTag(baseConfig, castInstance.appId);
|
||||
isRequestAppAudioCompatible = appTag?.supports_audio_only;
|
||||
}
|
||||
|
||||
sharedSelector.open({
|
||||
receiverDevices: deviceManager.getDevices(),
|
||||
defaultMediaType,
|
||||
@@ -226,7 +243,8 @@ async function getSelection(
|
||||
url: pageUrl,
|
||||
tabId: contextTabId,
|
||||
frameId: contextFrameId,
|
||||
sessionRequest: selectionOpts?.sessionRequest
|
||||
sessionRequest: selectionOpts?.sessionRequest,
|
||||
isRequestAppAudioCompatible
|
||||
}
|
||||
: undefined
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user