diff --git a/ext/src/_locales/en/messages.json b/ext/src/_locales/en/messages.json index f39fe64..7284ccb 100755 --- a/ext/src/_locales/en/messages.json +++ b/ext/src/_locales/en/messages.json @@ -355,6 +355,15 @@ "description": "Media stop on unload checkbox label." }, + "optionsMediaMirroringEnabled": { + "message": "Enable media mirroring", + "description": "Media mirroring enabled checkbox label." + }, + "optionsMediaMirroringEnabledDescription": { + "message": "Use a screen mirroring connection as a fallback to cast certain kinds of video content.", + "description": "Media mirroring enabled option description." + }, + "optionsLocalMediaCategoryName": { "message": "Local media casting", "description": "Options page local media category title." diff --git a/ext/src/background/castManager.ts b/ext/src/background/castManager.ts index c877c49..42c6128 100644 --- a/ext/src/background/castManager.ts +++ b/ext/src/background/castManager.ts @@ -398,6 +398,12 @@ const castManager = new (class { } try { + const mirroringAppId = await options.get("mirroringAppId"); + const requestedMediaType = + sessionRequest.appId === mirroringAppId + ? ReceiverSelectorMediaType.Screen + : ReceiverSelectorMediaType.App; + const selection = await getReceiverSelection({ castInstance: instance }); @@ -416,7 +422,7 @@ const castManager = new (class { * been changed, we need to cancel the current * sender and switch it out for the right one. */ - if (selection.mediaType !== ReceiverSelectorMediaType.App) { + if (selection.mediaType !== requestedMediaType) { instance.contentPort.postMessage({ subject: "cast:sessionRequestCancelled" }); diff --git a/ext/src/background/menus.ts b/ext/src/background/menus.ts index 7ed3149..902b0c5 100644 --- a/ext/src/background/menus.ts +++ b/ext/src/background/menus.ts @@ -29,7 +29,7 @@ const whitelistChildMenuPatterns = new Map(); export async function initMenus() { logger.info("init (menus)"); - const opts = await options.getAll(); + let opts = await options.getAll(); // Global "Cast..." menu item menuIdCast = browser.menus.create({ @@ -39,15 +39,25 @@ export async function initMenus() { icons: { "16": "icons/icon.svg" } // browser_action context }); + function createCastMediaMenu() { + let targetUrlPatterns: Optional; + if (!opts.mediaMirroringEnabled) { + targetUrlPatterns = opts.localMediaEnabled + ? URL_PATTERNS_ALL + : URL_PATTERNS_REMOTE; + } + + return browser.menus.create({ + id: "media", + contexts: ["audio", "video", "image"], + title: _("contextCast"), + visible: opts.mediaEnabled, + targetUrlPatterns: targetUrlPatterns + }); + } + //