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"
, "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": {
"message": "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);
switch (info.menuItemId) {
case menuIdMediaCast: {
case menuIdCast: {
const selection = await ReceiverSelectorManager.getSelection(
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
if (!selection) {
break;
@@ -192,19 +205,6 @@ async function initMenus () {
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 { DEFAULT_MEDIA_RECEIVER_APP_ID } from "../../shim/cast/media/";
import { ReceiverSelector
, ReceiverSelectorType } from "./";
import { ReceiverSelection
@@ -53,7 +55,8 @@ async function getSelector () {
*/
async function getSelection (
contextTabId: number
, contextFrameId = 0)
, contextFrameId = 0
, withMediaSender = false)
: Promise<ReceiverSelection> {
return new Promise(async (resolve, reject) => {
@@ -77,7 +80,7 @@ async function getSelection (
}
// Enable app media type if initialized sender app is found
if (currentShim) {
if (currentShim || withMediaSender) {
defaultMediaType = ReceiverSelectorMediaType.App;
availableMediaTypes |= ReceiverSelectorMediaType.App;
}
@@ -96,7 +99,6 @@ async function getSelection (
availableMediaTypes &= ~ReceiverSelectorMediaType.File;
}
// Close an existing open selector
if (sharedSelector && sharedSelector.isOpen) {
sharedSelector.close();
@@ -128,7 +130,8 @@ async function getSelection (
Array.from(StatusManager.getReceivers())
, defaultMediaType
, availableMediaTypes
, currentShim?.requestedAppId);
, currentShim?.requestedAppId
?? (withMediaSender && DEFAULT_MEDIA_RECEIVER_APP_ID));
});
}

View File

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