mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(web,server): web socket auth (for web) (#4632)
This commit is contained in:
parent
3021eca8e5
commit
0fb1d33f17
5 changed files with 39 additions and 24 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import type { AssetResponseDto, ServerVersionResponseDto } from '@api';
|
||||
import { io } from 'socket.io-client';
|
||||
import { Socket, io } from 'socket.io-client';
|
||||
import { writable } from 'svelte/store';
|
||||
import { loadConfig } from './server-config.store';
|
||||
|
||||
|
|
@ -20,9 +20,15 @@ export const websocketStore = {
|
|||
onRelease: writable<ReleaseEvent>(),
|
||||
};
|
||||
|
||||
let websocket: Socket | null = null;
|
||||
|
||||
export const openWebsocketConnection = () => {
|
||||
try {
|
||||
const websocket = io('', {
|
||||
if (websocket) {
|
||||
return;
|
||||
}
|
||||
|
||||
websocket = io('', {
|
||||
path: '/api/socket.io',
|
||||
reconnection: true,
|
||||
forceNew: true,
|
||||
|
|
@ -40,9 +46,14 @@ export const openWebsocketConnection = () => {
|
|||
.on('on_config_update', () => loadConfig())
|
||||
.on('on_new_release', (data) => websocketStore.onRelease.set(data))
|
||||
.on('error', (e) => console.log('Websocket Error', e));
|
||||
|
||||
return () => websocket?.close();
|
||||
} catch (e) {
|
||||
console.log('Cannot connect to websocket ', e);
|
||||
}
|
||||
};
|
||||
|
||||
export const closeWebsocketConnection = () => {
|
||||
if (websocket) {
|
||||
websocket.close();
|
||||
}
|
||||
websocket = null;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue