Fix media casting handling unified receiver selector

This commit is contained in:
hensm
2020-01-14 05:02:59 +00:00
parent a2c4e972c7
commit c522343eb8
4 changed files with 28 additions and 19 deletions

View File

@@ -13,6 +13,10 @@
"message": "this site's app" "message": "this site's app"
, "description": "Receiver selector media type <option> text for current site's sender application." , "description": "Receiver selector media type <option> text for current site's sender application."
} }
, "popupMediaTypeAppMedia": {
"message": "this media"
, "description": "Receiver selector media type <option> text for media casting."
}
, "popupMediaTypeTab": { , "popupMediaTypeTab": {
"message": "Tab" "message": "Tab"
, "description": "Receiver selector media type <option> text for current tab." , "description": "Receiver selector media type <option> text for current tab."

View File

@@ -153,10 +153,23 @@ async function initMenus () {
const availableMediaTypes = getMediaTypesForPageUrl(info.pageUrl); const availableMediaTypes = getMediaTypesForPageUrl(info.pageUrl);
switch (info.menuItemId) { switch (info.menuItemId) {
case menuIdMediaCast: { case menuIdCast: {
const selection = await ReceiverSelectorManager.getSelection( const selection = await ReceiverSelectorManager.getSelection(
tab.id, info.frameId); tab.id, info.frameId);
loadSender({
tabId: tab.id
, frameId: info.frameId
, selection
});
break;
}
case menuIdMediaCast: {
const selection = await ReceiverSelectorManager.getSelection(
tab.id, info.frameId, true);
// Selection cancelled // Selection cancelled
if (!selection) { if (!selection) {
break; break;
@@ -192,19 +205,6 @@ async function initMenus () {
break; break;
} }
case menuIdCast: {
const selection = await ReceiverSelectorManager.getSelection(
tab.id, info.frameId);
loadSender({
tabId: tab.id
, frameId: info.frameId
, selection
});
break;
}
} }
}); });

View File

@@ -7,6 +7,8 @@ import StatusManager from "../StatusManager";
import { getMediaTypesForPageUrl } from "../../lib/utils"; import { getMediaTypesForPageUrl } from "../../lib/utils";
import { DEFAULT_MEDIA_RECEIVER_APP_ID } from "../../shim/cast/media/";
import { ReceiverSelector import { ReceiverSelector
, ReceiverSelectorType } from "./"; , ReceiverSelectorType } from "./";
import { ReceiverSelection import { ReceiverSelection
@@ -53,7 +55,8 @@ async function getSelector () {
*/ */
async function getSelection ( async function getSelection (
contextTabId: number contextTabId: number
, contextFrameId = 0) , contextFrameId = 0
, withMediaSender = false)
: Promise<ReceiverSelection> { : Promise<ReceiverSelection> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
@@ -77,7 +80,7 @@ async function getSelection (
} }
// Enable app media type if initialized sender app is found // Enable app media type if initialized sender app is found
if (currentShim) { if (currentShim || withMediaSender) {
defaultMediaType = ReceiverSelectorMediaType.App; defaultMediaType = ReceiverSelectorMediaType.App;
availableMediaTypes |= ReceiverSelectorMediaType.App; availableMediaTypes |= ReceiverSelectorMediaType.App;
} }
@@ -96,7 +99,6 @@ async function getSelection (
availableMediaTypes &= ~ReceiverSelectorMediaType.File; availableMediaTypes &= ~ReceiverSelectorMediaType.File;
} }
// Close an existing open selector // Close an existing open selector
if (sharedSelector && sharedSelector.isOpen) { if (sharedSelector && sharedSelector.isOpen) {
sharedSelector.close(); sharedSelector.close();
@@ -128,7 +130,8 @@ async function getSelection (
Array.from(StatusManager.getReceivers()) Array.from(StatusManager.getReceivers())
, defaultMediaType , defaultMediaType
, availableMediaTypes , availableMediaTypes
, currentShim?.requestedAppId); , currentShim?.requestedAppId
?? (withMediaSender && DEFAULT_MEDIA_RECEIVER_APP_ID));
}); });
} }

View File

@@ -1,5 +1,7 @@
"use strict"; "use strict";
const _ = browser.i18n.getMessage;
/** /**
* TODO: Just keep a list of IDs and cache names from the Google API: * TODO: Just keep a list of IDs and cache names from the Google API:
* https://clients3.google.com/cast/chromecast/device/app?a=[appId] * https://clients3.google.com/cast/chromecast/device/app?a=[appId]
@@ -19,5 +21,5 @@ export default {
, "CD7B9F59": "Global Player Live" , "CD7B9F59": "Global Player Live"
, "B3DCF968": "Twitch" , "B3DCF968": "Twitch"
, "B88B034A": "Dailymotion" , "B88B034A": "Dailymotion"
, "CC1AD845": "TEST" , "CC1AD845": _("popupMediaTypeAppMedia")
} as Record<string, string>; } as Record<string, string>;