mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 16:49:58 +00:00
Improve session stopping
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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<string, Session>();
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -73,7 +73,7 @@ export default new (class extends TypedEventTarget<EventMap> {
|
||||
const receiverDevice = this.receiverDevices.get(receiverDeviceId);
|
||||
if (receiverDevice) {
|
||||
this.bridgePort.postMessage({
|
||||
subject: "bridge:stopCastApp",
|
||||
subject: "bridge:stopCastSession",
|
||||
data: { receiverDevice }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user