Move all Google endpoint URLs to a separate module

This commit is contained in:
hensm
2019-06-14 19:27:15 +01:00
parent e53b220cfc
commit 2c1fb64680
6 changed files with 67 additions and 35 deletions

View File

@@ -1,7 +1,7 @@
"use strict";
import Timeout from "./Timeout";
import { Capability } from "../enums";
import Timeout from "./Timeout";
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.SessionRequest
@@ -15,5 +15,5 @@ export default class SessionRequest {
Capability.VIDEO_OUT
, Capability.AUDIO_OUT ]
, public requestSessionTimeout: number
= (new Timeout).requestSession) {}
= (new Timeout()).requestSession) {}
}

View File

@@ -2,9 +2,9 @@
// https://developers.google.com/cast/docs/reference/chrome/chrome.cast.Timeout
export default class Timeout {
leaveSession = 3000;
requestSession = 60000;
sendCustomMessage = 3000;
setReceiverVolume = 3000;
stopSession = 3000;
public leaveSession = 3000;
public requestSession = 60000;
public sendCustomMessage = 3000;
public setReceiverVolume = 3000;
public stopSession = 3000;
}

View File

@@ -1,20 +1,15 @@
"use strict";
import { CAST_LOADER_SCRIPT_URL
, CAST_SCRIPT_URLS } from "../endpoints";
const _window = (window.wrappedJSObject as any);
_window.chrome = 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
* intercept the new value.
@@ -34,8 +29,8 @@ Reflect.defineProperty(
, get
, set: exportFunction(function (value) {
if (EXT_SENDER_SCRIPT_URLS.includes(value)) {
return set.call(this, SENDER_SCRIPT_URL);
if (CAST_SCRIPT_URLS.includes(value)) {
return set.call(this, CAST_LOADER_SCRIPT_URL);
}
return set.call(this, value);

View File

@@ -2,6 +2,7 @@
import * as cast from "./cast";
import { CAST_FRAMEWORK_SCRIPT_URL } from "../endpoints";
import { loadScript } from "../lib/utils";
import { onMessage } from "./messageBridge";
@@ -12,12 +13,10 @@ if (!_window.chrome) {
_window.chrome = {};
}
// Create page-accessible API object
_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 isFramework = false;