Implement roadmap phases 1 through 8
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import type { WorldDelta, WorldSnapshot } from "./contracts";
|
||||
|
||||
export interface WorldStreamScope {
|
||||
scopeKind?: string;
|
||||
systemId?: string | null;
|
||||
bubbleId?: string | null;
|
||||
}
|
||||
|
||||
export async function fetchWorldSnapshot(signal?: AbortSignal) {
|
||||
const response = await fetch("/api/world", { signal });
|
||||
if (!response.ok) {
|
||||
@@ -15,8 +21,22 @@ export function openWorldStream(
|
||||
onOpen?: () => void;
|
||||
onError?: () => void;
|
||||
},
|
||||
scope?: WorldStreamScope,
|
||||
) {
|
||||
const stream = new EventSource(`/api/world/stream?afterSequence=${afterSequence}`);
|
||||
const query = new URLSearchParams({
|
||||
afterSequence: String(afterSequence),
|
||||
});
|
||||
if (scope?.scopeKind) {
|
||||
query.set("scopeKind", scope.scopeKind);
|
||||
}
|
||||
if (scope?.systemId) {
|
||||
query.set("systemId", scope.systemId);
|
||||
}
|
||||
if (scope?.bubbleId) {
|
||||
query.set("bubbleId", scope.bubbleId);
|
||||
}
|
||||
|
||||
const stream = new EventSource(`/api/world/stream?${query.toString()}`);
|
||||
stream.addEventListener("open", () => handlers.onOpen?.());
|
||||
stream.addEventListener("error", () => handlers.onError?.());
|
||||
stream.addEventListener("world-delta", (event) => {
|
||||
|
||||
Reference in New Issue
Block a user