Improve session stopping

This commit is contained in:
hensm
2022-03-15 10:32:17 +00:00
parent 3c175a740d
commit 5120a3a7ab
6 changed files with 14 additions and 28 deletions

View File

@@ -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",

View File

@@ -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;

View File

@@ -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