mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-10 09:39:58 +00:00
52 lines
1.3 KiB
TypeScript
Executable File
52 lines
1.3 KiB
TypeScript
Executable File
"use strict";
|
|
|
|
import messaging, { Message } from "./messaging";
|
|
|
|
import { handleCastMessage } from "./components/cast";
|
|
import { startDiscovery, stopDiscovery } from "./components/discovery";
|
|
import { startMediaServer, stopMediaServer } from "./components/mediaServer";
|
|
|
|
import { applicationVersion } from "../../config.json";
|
|
|
|
process.on("SIGTERM", () => {
|
|
stopDiscovery();
|
|
stopMediaServer();
|
|
});
|
|
|
|
/**
|
|
* Handle incoming messages from the extension and forward
|
|
* them to the appropriate handlers.
|
|
*
|
|
* Initializes the counterpart objects and is responsible
|
|
* for managing existing ones.
|
|
*/
|
|
messaging.on("message", (message: Message) => {
|
|
switch (message.subject) {
|
|
case "bridge:getInfo":
|
|
case "bridge:/getInfo": {
|
|
messaging.send(applicationVersion);
|
|
break;
|
|
}
|
|
|
|
case "bridge:startDiscovery": {
|
|
startDiscovery(message.data);
|
|
break;
|
|
}
|
|
|
|
// Media server
|
|
case "bridge:startMediaServer": {
|
|
const { filePath, port } = message.data;
|
|
startMediaServer(filePath, port);
|
|
break;
|
|
}
|
|
case "bridge:stopMediaServer": {
|
|
stopMediaServer();
|
|
break;
|
|
}
|
|
|
|
default: {
|
|
handleCastMessage(message);
|
|
}
|
|
}
|
|
});
|