mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 04:50:12 +02:00
e344adfeed
* Add autodiscovery for Jellyfin servers * Remove debugging aids you didn't see anything * Fix linter errors * Send a discovery packet to localhost too
24 lines
599 B
TypeScript
24 lines
599 B
TypeScript
import { ipcRenderer } from 'electron';
|
|
|
|
import { DiscoveredServerItem } from '../shared/types/types';
|
|
|
|
const discover = (onReply: (server: DiscoveredServerItem) => void): Promise<void> => {
|
|
const { port1: local, port2: remote } = new MessageChannel();
|
|
|
|
ipcRenderer.postMessage('autodiscover-ping', {}, [remote]);
|
|
|
|
local.onmessage = (ev) => {
|
|
onReply(ev.data);
|
|
};
|
|
|
|
return new Promise<void>((resolve) => {
|
|
local.addEventListener('close', () => resolve());
|
|
});
|
|
};
|
|
|
|
export const autodiscover = {
|
|
discover,
|
|
};
|
|
|
|
export type AutoDiscover = typeof autodiscover;
|