Open justjam2013 opened 1 month ago
Noticed that startStreaming
also sets an exit callback, so code update:
private async endStreaming(streamExit: boolean = false): Promise<boolean> {
try {
...
if (!streamExit) {
await this.killProcess(this.streaming.pid);
}
this.streaming = null;
} catch (err) {
this.logger.error(`[${this.streamerName}] Error while trying to stop: ${err}`);
this.streaming = null;
}
return Promise.resolve(true);
}
then:
public async playFile(filePath: string, volume: number): Promise<boolean> {
...
this.streaming.on('exit', async (code, signal) => {
this.logger.info(`[${this.streamerName}] streaming exit: code ${code} signal ${signal}`);
await this.endStreaming(true);
});
...
return true;
}
and:
private async startStreaming(
streamUrl: string,
streamName: string,
volume: number,
heartbeat: (source: string, heartbeatFailed: () => Promise<void>) => Promise<void>,
heartbeatFailed: () => Promise<void>,
): Promise<boolean> {
...
this.streaming.on('exit', async (code, signal) => {
this.logger.info(`[${this.streamerName}] streaming exit: code ${code} signal ${signal}`);
await this.endStreaming(true);
});
...
return true;
}
Installed version of homebridge-homepod-radio:
v3.0.0 - latest
Seeing the following error in HomeBridge log:
[9/29/2024, 10:35:07 PM] [HomepodRadioPlatform] [File Play Button] Error while trying to stop: Error: Command failed: kill -9 322466 /bin/sh: 1: kill: No such process
This happens because when a file is played,
playFile
spawns a child process and sets a callback for when the child exits. When the child process terminates, it callsendStreaming
, which callskillProcess
with the PID of the child process which has already exited. Thereforekill -9 ${procId}
will always fail to find a process with that PID./src/lib/airplayDevice.ts
This could be fixed by passing a boolean flag to
endStreaming()
and only kill the subprocess if it's not a file stream:And calling