diff --git a/app/src/bridge/components/cast/client.ts b/app/src/bridge/components/cast/client.ts index ad32e59..d5a848a 100644 --- a/app/src/bridge/components/cast/client.ts +++ b/app/src/bridge/components/cast/client.ts @@ -26,7 +26,7 @@ export default class CastClient { // Platform messaging private receiverChannel?: Channel; - private receiverRequestId = 0; + private receiverRequestId = Math.floor(Math.random() * 1e6); constructor( protected sourceId = "sender-0", diff --git a/app/src/bridge/components/cast/index.ts b/app/src/bridge/components/cast/index.ts index c6aa771..e6f3b04 100644 --- a/app/src/bridge/components/cast/index.ts +++ b/app/src/bridge/components/cast/index.ts @@ -6,7 +6,7 @@ import { sendMessage } from "../../lib/nativeMessaging"; import { Message } from "../../messaging"; import Session from "./Session"; -import { NS_CONNECTION, NS_RECEIVER } from "./client"; +import CastClient, { NS_CONNECTION, NS_RECEIVER } from "./client"; const sessions = new Map(); @@ -112,29 +112,12 @@ export function handleCastMessage(message: Message) { break; } - case "bridge:stopCastApp": { - const { host, port } = message.data.receiverDevice; - const client = new castv2.Client(); + case "bridge:stopCastSession": { + const { receiverDevice } = message.data; - client.connect({ host, port }, () => { - const sourceId = "sender-0"; - const destinationId = "receiver-0"; - - const clientConnection = client.createChannel( - sourceId, - destinationId, - NS_CONNECTION, - "JSON" - ); - const clientReceiver = client.createChannel( - sourceId, - destinationId, - NS_RECEIVER, - "JSON" - ); - - clientConnection.send({ type: "CONNECT" }); - clientReceiver.send({ type: "STOP", requestId: 1 }); + const client = new CastClient(); + client.connect(receiverDevice.host). then(() => { + (client.sendReceiverMessage as any)({ type: "STOP" }); }); break; diff --git a/app/src/bridge/messaging.ts b/app/src/bridge/messaging.ts index 9739f28..7119606 100644 --- a/app/src/bridge/messaging.ts +++ b/app/src/bridge/messaging.ts @@ -63,7 +63,9 @@ type MessageDefinitions = { messageData: object | string; messageId: string; }; - "bridge:stopCastApp": { receiverDevice: ReceiverDevice }; + "bridge:stopCastSession": { + receiverDevice: ReceiverDevice; + }; /** * getInfo uses the old :/ form for compat with old bridge diff --git a/ext/src/background/receiverDevices.ts b/ext/src/background/receiverDevices.ts index d54a01a..e5c1c6d 100644 --- a/ext/src/background/receiverDevices.ts +++ b/ext/src/background/receiverDevices.ts @@ -73,7 +73,7 @@ export default new (class extends TypedEventTarget { const receiverDevice = this.receiverDevices.get(receiverDeviceId); if (receiverDevice) { this.bridgePort.postMessage({ - subject: "bridge:stopCastApp", + subject: "bridge:stopCastSession", data: { receiverDevice } }); } diff --git a/ext/src/background/receiverSelector/ReceiverSelectorManager.ts b/ext/src/background/receiverSelector/ReceiverSelectorManager.ts index abd2712..a84456a 100644 --- a/ext/src/background/receiverSelector/ReceiverSelectorManager.ts +++ b/ext/src/background/receiverSelector/ReceiverSelectorManager.ts @@ -200,7 +200,6 @@ async function getSelection( "stop", storeListener("stop", async ev => { logger.info("Stopping receiver app...", ev.detail); - receiverDevices.stopReceiverApp(ev.detail.receiver.id); resolve({ diff --git a/ext/src/messaging.ts b/ext/src/messaging.ts index 8d46871..f0ae407 100644 --- a/ext/src/messaging.ts +++ b/ext/src/messaging.ts @@ -102,7 +102,9 @@ type AppMessageDefinitions = { messageData: object | string; messageId: string; }; - "bridge:stopCastApp": { receiverDevice: ReceiverDevice }; + "bridge:stopCastSession": { + receiverDevice: ReceiverDevice; + }; /** * getInfo uses the old :/ form for compat with old bridge