mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 08:39:59 +00:00
Improve message names
This commit is contained in:
@@ -48,8 +48,8 @@ export default class Discovery {
|
||||
|
||||
constructor(opts: DiscoveryOptions) {
|
||||
/**
|
||||
* When a service is found, gather device info from service object and
|
||||
* TXT record, then send a `main:receiverDeviceUp` message.
|
||||
* When a service is found, gather device info from service
|
||||
* object and TXT record, then send a `main:deviceUp` message.
|
||||
*/
|
||||
this.browser.on("serviceUp", service => {
|
||||
// Filter invalid results
|
||||
@@ -69,7 +69,7 @@ export default class Discovery {
|
||||
});
|
||||
|
||||
/**
|
||||
* When a service is lost, send a `main:receiverDeviceDown` message with
|
||||
* When a service is lost, send a `main:deviceDown` message with
|
||||
* the service name as the `deviceId`.
|
||||
*/
|
||||
this.browser.on("serviceDown", service => {
|
||||
|
||||
@@ -39,7 +39,7 @@ messaging.on("message", (message: Message) => {
|
||||
discovery = new Discovery({
|
||||
onDeviceFound(device) {
|
||||
messaging.sendMessage({
|
||||
subject: "main:receiverDeviceUp",
|
||||
subject: "main:deviceUp",
|
||||
data: {
|
||||
deviceId: device.id,
|
||||
deviceInfo: device
|
||||
@@ -80,7 +80,7 @@ messaging.on("message", (message: Message) => {
|
||||
},
|
||||
onDeviceDown(deviceId) {
|
||||
messaging.sendMessage({
|
||||
subject: "main:receiverDeviceDown",
|
||||
subject: "main:deviceDown",
|
||||
data: { deviceId }
|
||||
});
|
||||
|
||||
|
||||
@@ -48,12 +48,12 @@ type MessageDefinitions = {
|
||||
* Sent to extension from the bridge whenever a receiver device is
|
||||
* found.
|
||||
*/
|
||||
"main:receiverDeviceUp": { deviceId: string; deviceInfo: ReceiverDevice };
|
||||
"main:deviceUp": { deviceId: string; deviceInfo: ReceiverDevice };
|
||||
/**
|
||||
* Sent to extension from the bridge whenever a previously found
|
||||
* receiver device is lost.
|
||||
*/
|
||||
"main:receiverDeviceDown": { deviceId: string };
|
||||
"main:deviceDown": { deviceId: string };
|
||||
|
||||
/**
|
||||
* Sent to the extension from the bridge whenever a
|
||||
|
||||
@@ -233,25 +233,25 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
/** Handles messages from the popup extension page. */
|
||||
private onPopupMessage(message: Message) {
|
||||
switch (message.subject) {
|
||||
case "receiverSelector:selected":
|
||||
case "main:receiverSelected":
|
||||
this.wasReceiverSelected = true;
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("selected", { detail: message.data })
|
||||
);
|
||||
break;
|
||||
|
||||
case "receiverSelector:stop":
|
||||
case "main:receiverStopped":
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("stop", { detail: message.data })
|
||||
);
|
||||
break;
|
||||
|
||||
case "receiverSelector:receiverMessage":
|
||||
case "main:sendReceiverMessage":
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("receiverMessage", { detail: message.data })
|
||||
);
|
||||
break;
|
||||
case "receiverSelector:mediaMessage":
|
||||
case "main:sendMediaMessage":
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("mediaMessage", { detail: message.data })
|
||||
);
|
||||
|
||||
@@ -134,7 +134,7 @@ export default new (class extends TypedEventTarget<EventMap> {
|
||||
|
||||
private onBridgeMessage = (message: Message) => {
|
||||
switch (message.subject) {
|
||||
case "main:receiverDeviceUp": {
|
||||
case "main:deviceUp": {
|
||||
const { deviceId, deviceInfo } = message.data;
|
||||
|
||||
this.receiverDevices.set(deviceId, deviceInfo);
|
||||
@@ -147,7 +147,7 @@ export default new (class extends TypedEventTarget<EventMap> {
|
||||
break;
|
||||
}
|
||||
|
||||
case "main:receiverDeviceDown": {
|
||||
case "main:deviceDown": {
|
||||
const { deviceId } = message.data;
|
||||
|
||||
if (this.receiverDevices.has(deviceId)) {
|
||||
|
||||
@@ -54,16 +54,17 @@ type ExtMessageDefinitions = {
|
||||
};
|
||||
"popup:close": undefined;
|
||||
|
||||
"receiverSelector:selected": ReceiverSelection;
|
||||
"receiverSelector:stop": { deviceId: string };
|
||||
"receiverSelector:receiverMessage": ReceiverSelectorReceiverMessage;
|
||||
"receiverSelector:mediaMessage": ReceiverSelectorMediaMessage;
|
||||
"main:receiverSelected": ReceiverSelection;
|
||||
"main:receiverStopped": { deviceId: string };
|
||||
"main:sendReceiverMessage": ReceiverSelectorReceiverMessage;
|
||||
"main:sendMediaMessage": ReceiverSelectorMediaMessage;
|
||||
|
||||
"main:selectReceiver": {
|
||||
sessionRequest: SessionRequest;
|
||||
};
|
||||
"cast:selectReceiver/selected": ReceiverSelection;
|
||||
"cast:selectReceiver/cancelled": undefined;
|
||||
|
||||
"cast:receiverStoppedAction": { deviceId: string };
|
||||
|
||||
"main:closeReceiverSelector": undefined;
|
||||
@@ -107,12 +108,12 @@ type AppMessageDefinitions = {
|
||||
* Sent to extension from the bridge whenever a receiver device is
|
||||
* found.
|
||||
*/
|
||||
"main:receiverDeviceUp": { deviceId: string; deviceInfo: ReceiverDevice };
|
||||
"main:deviceUp": { deviceId: string; deviceInfo: ReceiverDevice };
|
||||
/**
|
||||
* Sent to extension from the bridge whenever a previously found
|
||||
* receiver device is lost.
|
||||
*/
|
||||
"main:receiverDeviceDown": { deviceId: string };
|
||||
"main:deviceDown": { deviceId: string };
|
||||
|
||||
/**
|
||||
* Sent to the extension from the bridge whenever a
|
||||
|
||||
@@ -343,7 +343,7 @@
|
||||
isConnecting = true;
|
||||
|
||||
port?.postMessage({
|
||||
subject: "receiverSelector:selected",
|
||||
subject: "main:receiverSelected",
|
||||
data: {
|
||||
receiverDevice,
|
||||
mediaType
|
||||
@@ -353,7 +353,7 @@
|
||||
|
||||
function onReceiverStop(receiverDevice: ReceiverDevice) {
|
||||
port?.postMessage({
|
||||
subject: "receiverSelector:receiverMessage",
|
||||
subject: "main:sendReceiverMessage",
|
||||
data: {
|
||||
deviceId: receiverDevice.id,
|
||||
message: { requestId: 0, type: "STOP" }
|
||||
@@ -361,7 +361,7 @@
|
||||
});
|
||||
|
||||
port?.postMessage({
|
||||
subject: "receiverSelector:stop",
|
||||
subject: "main:receiverStopped",
|
||||
data: { deviceId: receiverDevice.id }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
};
|
||||
|
||||
port?.postMessage({
|
||||
subject: "receiverSelector:receiverMessage",
|
||||
subject: "main:sendReceiverMessage",
|
||||
data: { deviceId: device.id, message }
|
||||
});
|
||||
}
|
||||
@@ -68,7 +68,7 @@
|
||||
};
|
||||
|
||||
port?.postMessage({
|
||||
subject: "receiverSelector:mediaMessage",
|
||||
subject: "main:sendMediaMessage",
|
||||
data: { deviceId: device.id, message }
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user