mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 01:59:58 +00:00
Add stop action to receiver selectors
This commit is contained in:
@@ -6,13 +6,16 @@ import { Message
|
||||
, SendMessageCallback } from "./types";
|
||||
|
||||
|
||||
const NS_CONNECTION = "urn:x-cast:com.google.cast.tp.connection";
|
||||
const NS_HEARTBEAT = "urn:x-cast:com.google.cast.tp.heartbeat";
|
||||
const NS_RECEIVER = "urn:x-cast:com.google.cast.receiver";
|
||||
export const NS_CONNECTION = "urn:x-cast:com.google.cast.tp.connection";
|
||||
export const NS_HEARTBEAT = "urn:x-cast:com.google.cast.tp.heartbeat";
|
||||
export const NS_RECEIVER = "urn:x-cast:com.google.cast.receiver";
|
||||
|
||||
export default class Session {
|
||||
public channelMap = new Map<string, Channel>();
|
||||
|
||||
public host: string;
|
||||
public port: number;
|
||||
|
||||
private sendMessageCallback: SendMessageCallback;
|
||||
private sessionId: number;
|
||||
private referenceId: string;
|
||||
@@ -38,6 +41,9 @@ export default class Session {
|
||||
, referenceId: string
|
||||
, sendMessageCallback: SendMessageCallback) {
|
||||
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
|
||||
this.sessionId = sessionId;
|
||||
this.referenceId = referenceId;
|
||||
this.sendMessageCallback = sendMessageCallback;
|
||||
@@ -176,6 +182,10 @@ export default class Session {
|
||||
}
|
||||
}
|
||||
|
||||
public stop () {
|
||||
this.clientConnection!.send({ type: "STOP" });
|
||||
}
|
||||
|
||||
private sendMessage (subject: string, data: any = {}) {
|
||||
this.sendMessageCallback({
|
||||
subject
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
import { Channel, Client } from "castv2";
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
const NS_CONNECTION = "urn:x-cast:com.google.cast.tp.connection";
|
||||
const NS_HEARTBEAT = "urn:x-cast:com.google.cast.tp.heartbeat";
|
||||
const NS_RECEIVER = "urn:x-cast:com.google.cast.receiver";
|
||||
import { NS_CONNECTION
|
||||
, NS_HEARTBEAT
|
||||
, NS_RECEIVER } from "./Session";
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,11 +16,16 @@ import { DecodeTransform
|
||||
|
||||
import { ReceiverStatus } from "./castTypes";
|
||||
|
||||
import { Message } from "./types";
|
||||
import { Message, Receiver } from "./types";
|
||||
|
||||
import { __applicationName
|
||||
, __applicationVersion } from "../../package.json";
|
||||
|
||||
import { Channel, Client } from "castv2";
|
||||
import { NS_CONNECTION
|
||||
, NS_HEARTBEAT
|
||||
, NS_RECEIVER } from "./Session";
|
||||
|
||||
|
||||
// Increase listener limit
|
||||
events.EventEmitter.defaultMaxListeners = 50;
|
||||
@@ -86,7 +91,9 @@ process.on("SIGTERM", () => {
|
||||
receiverSelectorApp.kill();
|
||||
}
|
||||
|
||||
browser.stop();
|
||||
if (browser) {
|
||||
browser.stop();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -175,6 +182,24 @@ async function handleMessage (message: Message) {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "bridge:/stopReceiverApp": {
|
||||
const receiver: Receiver = message.data.receiver;
|
||||
const client = new Client();
|
||||
|
||||
client.connect({ host: receiver.host, port: receiver.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 });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,9 +240,13 @@ function handleReceiverSelectorMessage (message: Message) {
|
||||
|
||||
receiverSelectorApp.stdout!.setEncoding("utf8");
|
||||
receiverSelectorApp.stdout!.on("data", data => {
|
||||
const parsedData = JSON.parse(data);
|
||||
|
||||
sendMessage({
|
||||
subject: "main:/receiverSelector/selected"
|
||||
, data: JSON.parse(data)
|
||||
subject: !parsedData.mediaType
|
||||
? "main:/receiverSelector/stop"
|
||||
: "main:/receiverSelector/selected"
|
||||
, data: parsedData
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
"use strict";
|
||||
|
||||
import { ReceiverStatus } from "./castTypes";
|
||||
|
||||
export interface Message {
|
||||
subject: string;
|
||||
data?: any;
|
||||
_id?: string;
|
||||
}
|
||||
|
||||
export interface Receiver {
|
||||
host: string;
|
||||
friendlyName: string;
|
||||
id: string;
|
||||
port: number;
|
||||
status?: ReceiverStatus;
|
||||
}
|
||||
|
||||
export type SendMessageCallback = (message: Message) => void;
|
||||
|
||||
Reference in New Issue
Block a user