mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-13 19:09:58 +00:00
Check bridge compat before initializing cast shim
This commit is contained in:
@@ -10,6 +10,7 @@ export default async function getBridgeInfo () {
|
||||
|
||||
applicationVersion = response.data;
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import defaultOptions from "./options/defaultOptions";
|
||||
import messageRouter from "./messageRouter";
|
||||
import getBridgeInfo from "./lib/getBridgeInfo";
|
||||
|
||||
import semver from "semver";
|
||||
|
||||
@@ -421,7 +422,16 @@ messageRouter.register("main", async (message, sender) => {
|
||||
|
||||
switch (message.subject) {
|
||||
case "main:initialize": {
|
||||
const bridgeInfo = await getBridgeInfo();
|
||||
if (bridgeInfo && bridgeInfo.isVersionCompatible) {
|
||||
initBridge(tabId, sender.tab.frameId);
|
||||
}
|
||||
|
||||
browser.tabs.sendMessage(sender.tab.id, {
|
||||
subject: "shim:initialized"
|
||||
, data: bridgeInfo
|
||||
}, { frameId: sender.tab.frameId });
|
||||
|
||||
break;
|
||||
};
|
||||
|
||||
|
||||
@@ -244,7 +244,7 @@ function onMediaSeekError (err) {
|
||||
|
||||
window.__onGCastApiAvailable = async function (loaded, errorInfo) {
|
||||
if (!loaded) {
|
||||
logMessage("__onGCastApiAvailable error");
|
||||
console.error("__onGCastApiAvailable error");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -256,9 +256,4 @@ onMessage(message => {
|
||||
}
|
||||
});
|
||||
|
||||
// Trigger bridge mDNS discovery
|
||||
sendMessage({
|
||||
subject: "main:initialize"
|
||||
});
|
||||
|
||||
export default cast;
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
import cast from "./cast";
|
||||
import media from "./media";
|
||||
|
||||
import { onMessage, sendMessage } from "./messageBridge";
|
||||
|
||||
|
||||
if (!window.chrome) {
|
||||
window.chrome = {};
|
||||
}
|
||||
@@ -10,9 +13,23 @@ if (!window.chrome) {
|
||||
window.chrome.cast = cast;
|
||||
window.chrome.cast.media = media;
|
||||
|
||||
// Call page's API loaded function if defined
|
||||
const readyFunction = window.__onGCastApiAvailable;
|
||||
console.log(readyFunction);
|
||||
if (readyFunction && typeof readyFunction === "function") {
|
||||
readyFunction(true);
|
||||
}
|
||||
|
||||
onMessage(message => {
|
||||
switch (message.subject) {
|
||||
case "shim:initialized": {
|
||||
const bridgeInfo = message.data;
|
||||
|
||||
// Call page's API loaded function if defined
|
||||
const readyFunction = window.__onGCastApiAvailable;
|
||||
if (readyFunction && typeof readyFunction === "function") {
|
||||
readyFunction(bridgeInfo && bridgeInfo.isVersionCompatible);
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
// Trigger bridge mDNS discovery
|
||||
sendMessage({
|
||||
subject: "main:initialize"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user