mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 10:09:59 +00:00
Improve session stopping
This commit is contained in:
@@ -26,7 +26,7 @@ export default class CastClient {
|
|||||||
|
|
||||||
// Platform messaging
|
// Platform messaging
|
||||||
private receiverChannel?: Channel;
|
private receiverChannel?: Channel;
|
||||||
private receiverRequestId = 0;
|
private receiverRequestId = Math.floor(Math.random() * 1e6);
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected sourceId = "sender-0",
|
protected sourceId = "sender-0",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { sendMessage } from "../../lib/nativeMessaging";
|
|||||||
import { Message } from "../../messaging";
|
import { Message } from "../../messaging";
|
||||||
|
|
||||||
import Session from "./Session";
|
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>();
|
const sessions = new Map<string, Session>();
|
||||||
@@ -112,29 +112,12 @@ export function handleCastMessage(message: Message) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case "bridge:stopCastApp": {
|
case "bridge:stopCastSession": {
|
||||||
const { host, port } = message.data.receiverDevice;
|
const { receiverDevice } = message.data;
|
||||||
const client = new castv2.Client();
|
|
||||||
|
|
||||||
client.connect({ host, port }, () => {
|
const client = new CastClient();
|
||||||
const sourceId = "sender-0";
|
client.connect(receiverDevice.host). then(() => {
|
||||||
const destinationId = "receiver-0";
|
(client.sendReceiverMessage as any)({ type: "STOP" });
|
||||||
|
|
||||||
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 });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -63,7 +63,9 @@ type MessageDefinitions = {
|
|||||||
messageData: object | string;
|
messageData: object | string;
|
||||||
messageId: string;
|
messageId: string;
|
||||||
};
|
};
|
||||||
"bridge:stopCastApp": { receiverDevice: ReceiverDevice };
|
"bridge:stopCastSession": {
|
||||||
|
receiverDevice: ReceiverDevice;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getInfo uses the old :/ form for compat with old bridge
|
* 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);
|
const receiverDevice = this.receiverDevices.get(receiverDeviceId);
|
||||||
if (receiverDevice) {
|
if (receiverDevice) {
|
||||||
this.bridgePort.postMessage({
|
this.bridgePort.postMessage({
|
||||||
subject: "bridge:stopCastApp",
|
subject: "bridge:stopCastSession",
|
||||||
data: { receiverDevice }
|
data: { receiverDevice }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,7 +200,6 @@ async function getSelection(
|
|||||||
"stop",
|
"stop",
|
||||||
storeListener("stop", async ev => {
|
storeListener("stop", async ev => {
|
||||||
logger.info("Stopping receiver app...", ev.detail);
|
logger.info("Stopping receiver app...", ev.detail);
|
||||||
|
|
||||||
receiverDevices.stopReceiverApp(ev.detail.receiver.id);
|
receiverDevices.stopReceiverApp(ev.detail.receiver.id);
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
|
|||||||
@@ -102,7 +102,9 @@ type AppMessageDefinitions = {
|
|||||||
messageData: object | string;
|
messageData: object | string;
|
||||||
messageId: string;
|
messageId: string;
|
||||||
};
|
};
|
||||||
"bridge:stopCastApp": { receiverDevice: ReceiverDevice };
|
"bridge:stopCastSession": {
|
||||||
|
receiverDevice: ReceiverDevice;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getInfo uses the old :/ form for compat with old bridge
|
* getInfo uses the old :/ form for compat with old bridge
|
||||||
|
|||||||
Reference in New Issue
Block a user