mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 10:39:57 +00:00
Move all Google endpoint URLs to a separate module
This commit is contained in:
45
ext/src/endpoints.ts
Normal file
45
ext/src/endpoints.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast sender API loader script URL.
|
||||||
|
*
|
||||||
|
* Since the actual cast sender API script is hosted locally
|
||||||
|
* within Chrome, this script just acts a loader script for
|
||||||
|
* the real script whilst also doing some UA string
|
||||||
|
* checking.
|
||||||
|
*/
|
||||||
|
export const CAST_LOADER_SCRIPT_URL =
|
||||||
|
"https://www.gstatic.com/cv/js/sender/v1/cast_sender.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Framework API loader script URL.
|
||||||
|
*
|
||||||
|
* Same URL as the usual loader script, but the additional
|
||||||
|
* search parameter is checked from within the script and
|
||||||
|
* the framework API script is conditionally loaded in
|
||||||
|
* addition to the regular API script.
|
||||||
|
*/
|
||||||
|
export const CAST_FRAMEWORK_LOADER_SCRIPT_URL =
|
||||||
|
`${CAST_LOADER_SCRIPT_URL}?loadCastFramework=1`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast API script URLs.
|
||||||
|
*
|
||||||
|
* Cast functionality in Chrome was previously provided by
|
||||||
|
* an extension. The cast API script is still provided via
|
||||||
|
* chrome-extension URLs for compatibility reasons.
|
||||||
|
*/
|
||||||
|
export const CAST_SCRIPT_URLS = [
|
||||||
|
"chrome-extension://pkedcjkdefgpdelpbcmbmeomcjbeemfm/cast_sender.js"
|
||||||
|
, "chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js"
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Framework API script URL.
|
||||||
|
*
|
||||||
|
* Unlike the basic cast sender API, the framework API is
|
||||||
|
* not hosted locally within Chrome and is the only script
|
||||||
|
* fetched directly from Google servers.
|
||||||
|
*/
|
||||||
|
export const CAST_FRAMEWORK_SCRIPT_URL =
|
||||||
|
"https://www.gstatic.com/cast/sdk/libs/sender/1.0/cast_framework.js";
|
||||||
@@ -22,6 +22,9 @@ import { ReceiverStatusMessage
|
|||||||
, ServiceDownMessage
|
, ServiceDownMessage
|
||||||
, ServiceUpMessage } from "./messageTypes";
|
, ServiceUpMessage } from "./messageTypes";
|
||||||
|
|
||||||
|
import { CAST_FRAMEWORK_LOADER_SCRIPT_URL
|
||||||
|
, CAST_LOADER_SCRIPT_URL } from "./endpoints";
|
||||||
|
|
||||||
|
|
||||||
const _ = browser.i18n.getMessage;
|
const _ = browser.i18n.getMessage;
|
||||||
|
|
||||||
@@ -244,13 +247,6 @@ browser.menus.onShown.addListener(info => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Google-hosted API loader script
|
|
||||||
const SENDER_SCRIPT_URL =
|
|
||||||
"https://www.gstatic.com/cv/js/sender/v1/cast_sender.js";
|
|
||||||
|
|
||||||
const SENDER_SCRIPT_FRAMEWORK_URL =
|
|
||||||
`${SENDER_SCRIPT_URL}?loadCastFramework=1`;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sender applications load a cast_sender.js script that
|
* Sender applications load a cast_sender.js script that
|
||||||
* functions as a loader for the internal chrome-extension:
|
* functions as a loader for the internal chrome-extension:
|
||||||
@@ -261,11 +257,9 @@ const SENDER_SCRIPT_FRAMEWORK_URL =
|
|||||||
*/
|
*/
|
||||||
browser.webRequest.onBeforeRequest.addListener(
|
browser.webRequest.onBeforeRequest.addListener(
|
||||||
async details => {
|
async details => {
|
||||||
|
|
||||||
const isFramework = details.url === SENDER_SCRIPT_FRAMEWORK_URL;
|
|
||||||
|
|
||||||
await browser.tabs.executeScript(details.tabId, {
|
await browser.tabs.executeScript(details.tabId, {
|
||||||
code: `window._isFramework = ${isFramework}`
|
code: `window._isFramework = ${
|
||||||
|
details.url === CAST_FRAMEWORK_LOADER_SCRIPT_URL}`
|
||||||
, frameId: details.frameId
|
, frameId: details.frameId
|
||||||
, runAt: "document_start"
|
, runAt: "document_start"
|
||||||
});
|
});
|
||||||
@@ -276,14 +270,13 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||||||
, runAt: "document_start"
|
, runAt: "document_start"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
redirectUrl: browser.runtime.getURL("shim/bundle.js")
|
redirectUrl: browser.runtime.getURL("shim/bundle.js")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
, { urls: [
|
, { urls: [
|
||||||
SENDER_SCRIPT_URL
|
CAST_LOADER_SCRIPT_URL
|
||||||
, SENDER_SCRIPT_FRAMEWORK_URL
|
, CAST_FRAMEWORK_LOADER_SCRIPT_URL
|
||||||
]}
|
]}
|
||||||
, [ "blocking" ]);
|
, [ "blocking" ]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import Timeout from "./Timeout";
|
|
||||||
import { Capability } from "../enums";
|
import { Capability } from "../enums";
|
||||||
|
import Timeout from "./Timeout";
|
||||||
|
|
||||||
|
|
||||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.SessionRequest
|
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.SessionRequest
|
||||||
@@ -15,5 +15,5 @@ export default class SessionRequest {
|
|||||||
Capability.VIDEO_OUT
|
Capability.VIDEO_OUT
|
||||||
, Capability.AUDIO_OUT ]
|
, Capability.AUDIO_OUT ]
|
||||||
, public requestSessionTimeout: number
|
, public requestSessionTimeout: number
|
||||||
= (new Timeout).requestSession) {}
|
= (new Timeout()).requestSession) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Timeout
|
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Timeout
|
||||||
export default class Timeout {
|
export default class Timeout {
|
||||||
leaveSession = 3000;
|
public leaveSession = 3000;
|
||||||
requestSession = 60000;
|
public requestSession = 60000;
|
||||||
sendCustomMessage = 3000;
|
public sendCustomMessage = 3000;
|
||||||
setReceiverVolume = 3000;
|
public setReceiverVolume = 3000;
|
||||||
stopSession = 3000;
|
public stopSession = 3000;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,15 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
import { CAST_LOADER_SCRIPT_URL
|
||||||
|
, CAST_SCRIPT_URLS } from "../endpoints";
|
||||||
|
|
||||||
|
|
||||||
const _window = (window.wrappedJSObject as any);
|
const _window = (window.wrappedJSObject as any);
|
||||||
|
|
||||||
_window.chrome = cloneInto({}, window);
|
_window.chrome = cloneInto({}, window);
|
||||||
_window.navigator.presentation = cloneInto({}, window);
|
_window.navigator.presentation = cloneInto({}, window);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const EXT_SENDER_SCRIPT_URLS = [
|
|
||||||
"chrome-extension://pkedcjkdefgpdelpbcmbmeomcjbeemfm/cast_sender.js"
|
|
||||||
, "chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js"
|
|
||||||
];
|
|
||||||
|
|
||||||
const SENDER_SCRIPT_URL = "https://www.gstatic.com/cv/js/sender/v1/cast_sender.js";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace the src property setter on <script> elements to
|
* Replace the src property setter on <script> elements to
|
||||||
* intercept the new value.
|
* intercept the new value.
|
||||||
@@ -34,8 +29,8 @@ Reflect.defineProperty(
|
|||||||
, get
|
, get
|
||||||
|
|
||||||
, set: exportFunction(function (value) {
|
, set: exportFunction(function (value) {
|
||||||
if (EXT_SENDER_SCRIPT_URLS.includes(value)) {
|
if (CAST_SCRIPT_URLS.includes(value)) {
|
||||||
return set.call(this, SENDER_SCRIPT_URL);
|
return set.call(this, CAST_LOADER_SCRIPT_URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return set.call(this, value);
|
return set.call(this, value);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import * as cast from "./cast";
|
import * as cast from "./cast";
|
||||||
|
|
||||||
|
import { CAST_FRAMEWORK_SCRIPT_URL } from "../endpoints";
|
||||||
import { loadScript } from "../lib/utils";
|
import { loadScript } from "../lib/utils";
|
||||||
import { onMessage } from "./messageBridge";
|
import { onMessage } from "./messageBridge";
|
||||||
|
|
||||||
@@ -12,12 +13,10 @@ if (!_window.chrome) {
|
|||||||
_window.chrome = {};
|
_window.chrome = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create page-accessible API object
|
||||||
_window.chrome.cast = cast;
|
_window.chrome.cast = cast;
|
||||||
|
|
||||||
|
|
||||||
const CAST_FRAMEWORK_SCRIPT_URL =
|
|
||||||
"https://www.gstatic.com/cast/sdk/libs/sender/1.0/cast_framework.js";
|
|
||||||
|
|
||||||
let bridgeInfo: any;
|
let bridgeInfo: any;
|
||||||
let isFramework = false;
|
let isFramework = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user