Document extension messages and remove unnecessary messages/message data

This commit is contained in:
hensm
2022-08-26 21:22:52 +01:00
parent 5b8a55a2de
commit fa953dda63
7 changed files with 44 additions and 38 deletions

View File

@@ -67,7 +67,8 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
private wasReceiverSelected = false;
private appId?: string;
private pageInfo?: ReceiverSelectorPageInfo;
pageInfo?: ReceiverSelectorPageInfo;
constructor() {
super();

View File

@@ -93,7 +93,7 @@ export default new (class {
instance.contentPort.postMessage({
subject: "cast:initialized",
data: await bridge.getInfo()
data: { isAvailable: (await bridge.getInfo()).isVersionCompatible }
});
return instance;
@@ -197,12 +197,26 @@ export default new (class {
) {
// Intercept messages to store relevant info
switch (message.subject) {
case "cast:sessionCreated":
case "cast:sessionCreated": {
// Close after session is created
const selector = ReceiverSelector.sharedInstance;
if (
selector.isOpen &&
// If selector context is the same as the instance context
selector.pageInfo?.tabId === instance.contentTabId &&
selector.pageInfo?.frameId === instance.contentFrameId &&
// If selector is supposed to close
(await options.get("receiverSelectorWaitForConnection"))
) {
selector.close();
}
instance.session = {
deviceId: message.data.receiverId,
sessionId: message.data.sessionId
};
break;
}
}
instance.contentPort.postMessage(message);
@@ -296,23 +310,6 @@ export default new (class {
break;
}
/**
* TODO: If we're closing a selector, make sure it's the
* same one that caused the session creation.
*/
case "main:closeReceiverSelector": {
const selector = ReceiverSelector.sharedInstance;
const shouldClose = await options.get(
"receiverSelectorWaitForConnection"
);
if (selector.isOpen && shouldClose) {
selector.close();
}
break;
}
}
}