Implement receiver action listeners

This commit is contained in:
hensm
2020-01-26 16:05:27 +00:00
parent 741379ca72
commit c676184898
7 changed files with 187 additions and 79 deletions

View File

@@ -11,7 +11,8 @@ import { getMediaTypesForPageUrl, stringify } from "../lib/utils";
import { CAST_FRAMEWORK_LOADER_SCRIPT_URL
, CAST_LOADER_SCRIPT_URL } from "../lib/endpoints";
import { ReceiverSelectorMediaType } from "./receiverSelector";
import { ReceiverSelectionActionType
, ReceiverSelectorMediaType } from "./receiverSelector";
import ReceiverSelectorManager
from "./receiverSelector/ReceiverSelectorManager";
@@ -200,32 +201,41 @@ async function initMenus () {
break;
}
/**
* If the selected media type is App, that refers to the
* media sender in this context, so load media sender.
*/
if (selection.mediaType === ReceiverSelectorMediaType.App) {
await browser.tabs.executeScript(tab.id, {
code: stringify`
window.receiver = ${selection.receiver};
window.mediaUrl = ${info.srcUrl};
window.targetElementId = ${info.targetElementId};
`
, frameId: info.frameId
});
switch (selection.actionType) {
case ReceiverSelectionActionType.Cast: {
/**
* If the selected media type is App, that refers to the
* media sender in this context, so load media sender.
*/
if (selection.mediaType ===
ReceiverSelectorMediaType.App) {
await browser.tabs.executeScript(tab.id, {
file: "senders/media/bundle.js"
, frameId: info.frameId
});
} else {
await browser.tabs.executeScript(tab.id, {
code: stringify`
window.receiver = ${selection.receiver};
window.mediaUrl = ${info.srcUrl};
window.targetElementId = ${
info.targetElementId};
`
, frameId: info.frameId
});
// Handle other responses
loadSender({
tabId: tab.id
, frameId: info.frameId
, selection
});
await browser.tabs.executeScript(tab.id, {
file: "senders/media/bundle.js"
, frameId: info.frameId
});
} else {
// Handle other responses
loadSender({
tabId: tab.id
, frameId: info.frameId
, selection
});
}
break;
}
}
break;