mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 18:19: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;
|
applicationVersion = response.data;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import defaultOptions from "./options/defaultOptions";
|
import defaultOptions from "./options/defaultOptions";
|
||||||
import messageRouter from "./messageRouter";
|
import messageRouter from "./messageRouter";
|
||||||
|
import getBridgeInfo from "./lib/getBridgeInfo";
|
||||||
|
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
|
|
||||||
@@ -421,7 +422,16 @@ messageRouter.register("main", async (message, sender) => {
|
|||||||
|
|
||||||
switch (message.subject) {
|
switch (message.subject) {
|
||||||
case "main:initialize": {
|
case "main:initialize": {
|
||||||
initBridge(tabId, sender.tab.frameId);
|
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;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ function onMediaSeekError (err) {
|
|||||||
|
|
||||||
window.__onGCastApiAvailable = async function (loaded, errorInfo) {
|
window.__onGCastApiAvailable = async function (loaded, errorInfo) {
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
logMessage("__onGCastApiAvailable error");
|
console.error("__onGCastApiAvailable error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,9 +256,4 @@ onMessage(message => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger bridge mDNS discovery
|
|
||||||
sendMessage({
|
|
||||||
subject: "main:initialize"
|
|
||||||
});
|
|
||||||
|
|
||||||
export default cast;
|
export default cast;
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
import cast from "./cast";
|
import cast from "./cast";
|
||||||
import media from "./media";
|
import media from "./media";
|
||||||
|
|
||||||
|
import { onMessage, sendMessage } from "./messageBridge";
|
||||||
|
|
||||||
|
|
||||||
if (!window.chrome) {
|
if (!window.chrome) {
|
||||||
window.chrome = {};
|
window.chrome = {};
|
||||||
}
|
}
|
||||||
@@ -10,9 +13,23 @@ if (!window.chrome) {
|
|||||||
window.chrome.cast = cast;
|
window.chrome.cast = cast;
|
||||||
window.chrome.cast.media = media;
|
window.chrome.cast.media = media;
|
||||||
|
|
||||||
// Call page's API loaded function if defined
|
|
||||||
const readyFunction = window.__onGCastApiAvailable;
|
onMessage(message => {
|
||||||
console.log(readyFunction);
|
switch (message.subject) {
|
||||||
if (readyFunction && typeof readyFunction === "function") {
|
case "shim:initialized": {
|
||||||
readyFunction(true);
|
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