mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
Add autodiscovery for Jellyfin servers (#1146)
* Add autodiscovery for Jellyfin servers * Remove debugging aids you didn't see anything * Fix linter errors * Send a discovery packet to localhost too
This commit is contained in:
parent
bca4a14f2e
commit
e344adfeed
6 changed files with 237 additions and 91 deletions
23
src/preload/autodiscover.ts
Normal file
23
src/preload/autodiscover.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { electronAPI } from '@electron-toolkit/preload';
|
||||
import { contextBridge } from 'electron';
|
||||
|
||||
import { autodiscover } from './autodiscover';
|
||||
import { browser } from './browser';
|
||||
import { discordRpc } from './discord-rpc';
|
||||
import { ipc } from './ipc';
|
||||
|
|
@ -13,6 +14,7 @@ import { utils } from './utils';
|
|||
|
||||
// Custom APIs for renderer
|
||||
const api = {
|
||||
autodiscover,
|
||||
browser,
|
||||
discordRpc,
|
||||
ipc,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue