Skip to content

Commit

Permalink
remove airplay
Browse files Browse the repository at this point in the history
  • Loading branch information
an-lee committed Jun 25, 2023
1 parent 2f42d74 commit fdeb788
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 550 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
"webpack-shell-plugin-next": "^2.3.1"
},
"dependencies": {
"airplay": "^0.0.3",
"airplayer": "github:webtorrent/airplayer#fix-security",
"chromecast-api": "^0.4.0",
"daisyui": "^3.1.6",
"dlnacasts2": "https://github.com/an-lee/dlnacasts2",
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Torrent from "./main/torrent";
import MPV from "./main/mpv";
import ipcHandlers from "./main/ipc-handlers";
import log from "electron-log";
import process from "process";

const mpv = new MPV();
const torrent = new Torrent();
Expand Down Expand Up @@ -67,6 +68,10 @@ const createWindow = () => {
return { action: "deny" };
}
});

process.on("uncaughtException", (error) => {
log.error(error);
});
};

// This method will be called when Electron has finished
Expand Down
32 changes: 9 additions & 23 deletions src/main/cast.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import log from "electron-log";
import { AirplayDevice, ChromecastDevice, DlnaDevice } from "./devices";
import { ChromecastDevice, DlnaDevice } from "./devices";
import ip from "ip";
import SubtitlesServer from "./subtitles-server";
const subtitlesServer = new SubtitlesServer();
Expand All @@ -8,15 +8,13 @@ const ChromecastAPI = require("chromecast-api");
export default class Cast {
public chromecast: any;
public dlnacast: any;
public airplay: any;
public devices: any[] = [];
public device: any = null;

init() {
log.info("cast-init");
this.chromecast = new ChromecastAPI();
this.dlnacast = require("dlnacasts2")();
this.airplay = require("airplayer")();
}

update() {
Expand All @@ -25,7 +23,7 @@ export default class Cast {

this.chromecast.update();
this.chromecast.devices.forEach((device: any) => {
log.info("found chromecast:", device.name, device.host)
log.info("found chromecast:", device.name, device.host);
_devices.push({
protocol: "chromecast",
name: device.name,
Expand All @@ -36,7 +34,7 @@ export default class Cast {

this.dlnacast.update();
this.dlnacast.players.forEach((device: any) => {
log.info("found dlna:", device.name, device.host)
log.info("found dlna:", device.name, device.host);
_devices.push({
protocol: "dlna",
name: device.name,
Expand All @@ -45,17 +43,6 @@ export default class Cast {
});
});

this.airplay.update();
this.airplay.players.forEach((device: any) => {
log.info("found airplay:", device.name, device.host)
_devices.push({
protocol: "airplay",
name: device.name,
friendlyName: device.name || device.serverInfo.model,
host: device.host,
});
});

this.devices = _devices;
return this.devices;
}
Expand Down Expand Up @@ -83,9 +70,6 @@ export default class Cast {
} else if (device.protocol === "dlna") {
const player = this.dlnacast.players.find((d: any) => d.host === host);
this.device = new DlnaDevice(player);
} else if (device.protocol === "airplay") {
const player = this.airplay.players.find((d: any) => d.host === host);
this.device = new AirplayDevice(player);
}
if (!this.device) throw new Error("Device not found");

Expand All @@ -97,10 +81,12 @@ export default class Cast {
}

serveSubtitles(subtitles: any[]) {
subtitles.forEach(async (sub, index) => {
const url = await subtitlesServer.serve(sub.url);
subtitles[index].url = url?.replace("localhost", ip.address());
});
subtitles
.filter((sub) => sub.url)
.forEach(async (sub, index) => {
const url = await subtitlesServer.serve(sub.url);
subtitles[index].url = url?.replace("localhost", ip.address());
});
subtitles = subtitles.filter((sub) => sub.url);

if (subtitles.length === 0) return null;
Expand Down
46 changes: 0 additions & 46 deletions src/main/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,49 +132,3 @@ export class DlnaDevice extends GenericDevice {
}
}
}

// Airplay
export class AirplayDevice extends GenericDevice {
play(media: CastMedia) {
log.debug("airplay play:", media.url, media.options?.startTime);
this.device.play(media.url, media.options?.startTime || 0);

this.clearDeviceInterval();
this.interval = setInterval(() => {
this.device.playbackInfo((err: any, _: any, status: any) => {
if (err) return;
this.status = {
playerState: status.rate > 0 ? "PLAYING" : "PAUSED",
currentTime: status.position,
};
log.debug("airplay player fetch status:", status.position);
});
}, 1000);
}

pause() {
try {
this.device.pause();
} catch (err) {
log.error("ariplay pause error:", err);
}
}

resume() {
try {
this.device.resume();
} catch (err) {
log.error("ariplay resume error:", err);
}
}

async stop() {
try {
await this.device.stop();
this.status = {};
} catch (err) {
log.error("airplay stop error:", err);
}
this.clearDeviceInterval();
}
}
Loading

0 comments on commit fdeb788

Please sign in to comment.