📜 Makes data sync more seamless

This commit is contained in:
Rune Harlyk
2024-02-23 13:43:23 +01:00
parent 04c3603254
commit 99a185ac82
9 changed files with 228 additions and 134 deletions
+5
View File
@@ -2,6 +2,7 @@ import { isConnected, socketData } from '$lib/stores';
import { Result, Ok } from '$lib/utilities';
import { resultService } from '$lib/services';
import { type WebSocketJsonMsg } from '$lib/models';
import type { Writable } from 'svelte/store';
type WebsocketOutData = string | ArrayBufferLike | Blob | ArrayBufferView;
@@ -37,6 +38,10 @@ class SocketService {
return Result.err('The connection is not open');
}
public addPublisher(store: Writable<WebsocketOutData>, type?: string) {
store.subscribe((data) => this.send(type ? JSON.stringify({ type, data }) : data));
}
private handleConnected(): void {
isConnected.set(true);
}