mirror of
https://github.com/immich-app/immich.git
synced 2026-02-28 01:29:04 +03:00
feat: image editing (#24155)
This commit is contained in:
@@ -31,6 +31,7 @@ export interface Events {
|
||||
on_notification: (notification: NotificationDto) => void;
|
||||
|
||||
AppRestartV1: (event: AppRestartEvent) => void;
|
||||
AssetEditReadyV1: (data: { assetId: string }) => void;
|
||||
}
|
||||
|
||||
const websocket: Socket<Events> = io({
|
||||
@@ -73,3 +74,25 @@ export const openWebsocketConnection = () => {
|
||||
export const closeWebsocketConnection = () => {
|
||||
websocket.disconnect();
|
||||
};
|
||||
|
||||
export const waitForWebsocketEvent = <T extends keyof Events>(
|
||||
event: T,
|
||||
predicate?: (...args: Parameters<Events[T]>) => boolean,
|
||||
timeout: number = 10_000,
|
||||
): Promise<Parameters<Events[T]>> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// @ts-expect-error: The typings are weird on this?
|
||||
const cleanup = websocketEvents.on(event, (...args: Parameters<Events[T]>) => {
|
||||
if (!predicate || predicate(...args)) {
|
||||
cleanup();
|
||||
clearTimeout(timer);
|
||||
resolve(args);
|
||||
}
|
||||
});
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
cleanup();
|
||||
reject(new Error(`Timeout waiting for event: ${String(event)}`));
|
||||
}, timeout);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user