-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(web): websocket events (#7152)
- Loading branch information
1 parent
bbf7a54
commit c84c0ba
Showing
10 changed files
with
134 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 10 additions & 7 deletions
17
web/src/lib/components/shared-components/update-panel.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
<script lang="ts"> | ||
import { websocketStore } from '$lib/stores/websocket'; | ||
import { websocketEvents } from '$lib/stores/websocket'; | ||
import type { AssetStore } from '$lib/stores/assets.store'; | ||
import { onMount } from 'svelte'; | ||
export let assetStore: AssetStore | null; | ||
websocketStore.onAssetUpdate.subscribe((asset) => { | ||
if (asset && asset.originalFileName && assetStore) { | ||
assetStore.updateAsset(asset, true); | ||
onMount(() => { | ||
return websocketEvents.on('on_asset_update', (asset) => { | ||
if (asset.originalFileName && assetStore) { | ||
assetStore.updateAsset(asset, true); | ||
assetStore.removeAsset(asset.id); // Update timeline | ||
assetStore.addAsset(asset); | ||
} | ||
assetStore.removeAsset(asset.id); // Update timeline | ||
assetStore.addAsset(asset); | ||
} | ||
}); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { | ||
DefaultEventsMap, | ||
EventsMap, | ||
ReservedOrUserEventNames, | ||
ReservedOrUserListener, | ||
} from '@socket.io/component-emitter'; | ||
import type { Socket } from 'socket.io-client'; | ||
|
||
export function createEventEmitter< | ||
ListenEvents extends EventsMap = DefaultEventsMap, | ||
EmitEvents extends EventsMap = ListenEvents, | ||
ReservedEvents extends EventsMap = NonNullable<unknown>, | ||
>(socket: Socket<ListenEvents, EmitEvents>) { | ||
function on<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( | ||
ev: Ev, | ||
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>, | ||
) { | ||
socket.on(ev, listener); | ||
return () => { | ||
socket.off(ev, listener); | ||
}; | ||
} | ||
|
||
function once<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( | ||
ev: Ev, | ||
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>, | ||
) { | ||
socket.once(ev, listener); | ||
return () => { | ||
socket.off(ev, listener); | ||
}; | ||
} | ||
|
||
function off<Ev extends ReservedOrUserEventNames<ReservedEvents, ListenEvents>>( | ||
ev: Ev, | ||
listener: ReservedOrUserListener<ReservedEvents, ListenEvents, Ev>, | ||
) { | ||
socket.off(ev, listener); | ||
} | ||
|
||
return { on, once, off }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters