Consume Eve surfaces through provider advertisement
This commit is contained in:
parent
c8c2cc2c55
commit
a9b3f2c45d
8 changed files with 126 additions and 45 deletions
|
|
@ -348,6 +348,18 @@ export type AetheriaEveSurfaceRequest = {
|
|||
recordKey?: string;
|
||||
};
|
||||
|
||||
export type EveProviderAdvertisement = {
|
||||
providerId: string;
|
||||
title: string;
|
||||
kind: string;
|
||||
surfaces: Array<{
|
||||
surfaceId: string;
|
||||
key: string;
|
||||
transport: string;
|
||||
status: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export type AetheriaEveCommandRequest = {
|
||||
providerId?: string;
|
||||
surfaceId?: string;
|
||||
|
|
@ -416,6 +428,7 @@ export type AetheriaRtsApi = {
|
|||
surfaceCatalog(): Promise<CultMeshSurfaceCatalogDiagnostic>;
|
||||
surfaceCatalogIndex(): Promise<CultMeshSurfaceCatalogIndexDiagnostic>;
|
||||
eveSurface(request: AetheriaEveSurfaceRequest): Promise<AetheriaMenuSurfaceDocument>;
|
||||
eveProviderAdvertisement(): Promise<EveProviderAdvertisement>;
|
||||
submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
windowControl(action: "minimize" | "maximize" | "close"): Promise<void>;
|
||||
health(): Promise<unknown>;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
renderEveSurface,
|
||||
EveBrowserProviderHost,
|
||||
type EveCommandIntent,
|
||||
type EveProviderSurfaceAdvertisement,
|
||||
type EveEmbeddedDocumentRequest,
|
||||
type EveSurfaceComponent,
|
||||
} from "../node_modules/@gamecult/eve-browser-lowering/dist/index.js";
|
||||
|
|
@ -20,9 +21,6 @@ declare global {
|
|||
|
||||
const host = requiredElement<HTMLElement>("#eve-surface-host");
|
||||
const statusEl = requiredElement<HTMLElement>("#status");
|
||||
let latestEveSurfaceKey = "";
|
||||
let renderDaemonEveSurfaceNow: (() => Promise<void>) | null = null;
|
||||
let eveSurfacePoll: number | null = null;
|
||||
|
||||
function requiredElement<TElement extends Element>(selector: string): TElement {
|
||||
const element = document.querySelector<TElement>(selector);
|
||||
|
|
@ -40,40 +38,28 @@ function setStatus(text: string): void {
|
|||
async function showDaemonEveSurface(): Promise<void> {
|
||||
document.body.classList.add("eve-game-mode");
|
||||
host.setAttribute("aria-label", "Aetheria daemon Eve surface");
|
||||
const requestedSurfaceId = new URLSearchParams(location.search).get("surface") || "";
|
||||
const providerHost = new EveBrowserProviderHost(host, {
|
||||
providerAdvertisement: () => window.aetheriaRts.eveProviderAdvertisement(),
|
||||
surface: surface => window.aetheriaRts.eveSurface(surfaceRequest(surface)),
|
||||
submitCommand: submitEveCommand,
|
||||
resolveDocument: resolveEveDocument,
|
||||
resolveAssetUrl: resolveAetheriaAssetUrl,
|
||||
}, {
|
||||
body: document.body,
|
||||
clientId: "eve-electron-client",
|
||||
pollMs: 250,
|
||||
requestedSurfaceId,
|
||||
source: "CultMesh provider",
|
||||
statusElement: statusEl,
|
||||
});
|
||||
await providerHost.start();
|
||||
wireWindowControls();
|
||||
new MutationObserver(wireWindowControls).observe(host, { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
const renderLatest = async () => {
|
||||
try {
|
||||
const surface = await window.aetheriaRts.eveSurface({
|
||||
recordKey: "eve:surface:aetheria.daemon.game",
|
||||
});
|
||||
const surfaceKey = `${surface.providerId}:${surface.surface.id}:${surface.version}:${surface.updatedAtUtc}`;
|
||||
if (surfaceKey === latestEveSurfaceKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
latestEveSurfaceKey = surfaceKey;
|
||||
renderEveSurface(surface, host, {
|
||||
body: document.body,
|
||||
assetUrlResolver: resolveAetheriaAssetUrl,
|
||||
clientId: "aetheria-electron-client",
|
||||
commandSink: intent => submitEveCommand(intent),
|
||||
documentResolver: resolveEveDocument,
|
||||
source: "Aetheria Daemon",
|
||||
statusElement: statusEl,
|
||||
});
|
||||
wireWindowControls();
|
||||
} catch (error) {
|
||||
setStatus(error instanceof Error ? error.message : "Aetheria daemon Eve surface unavailable.");
|
||||
}
|
||||
};
|
||||
|
||||
renderDaemonEveSurfaceNow = renderLatest;
|
||||
await renderLatest();
|
||||
if (eveSurfacePoll == null) {
|
||||
eveSurfacePoll = window.setInterval(() => {
|
||||
void renderLatest();
|
||||
}, 250);
|
||||
}
|
||||
function surfaceRequest(surface: EveProviderSurfaceAdvertisement): { surfaceId?: string; recordKey?: string } {
|
||||
return surface.key ? { recordKey: surface.key } : { surfaceId: surface.surfaceId };
|
||||
}
|
||||
|
||||
async function resolveEveDocument(
|
||||
|
|
@ -158,12 +144,6 @@ async function submitEveCommand(intent: EveCommandIntent): Promise<void> {
|
|||
payload: intent.payload,
|
||||
});
|
||||
setStatus(`${intent.command}: ${receipt.accepted ? "submitted" : "rejected"}`);
|
||||
latestEveSurfaceKey = "";
|
||||
if (renderDaemonEveSurfaceNow) {
|
||||
window.setTimeout(() => {
|
||||
void renderDaemonEveSurfaceNow?.();
|
||||
}, 120);
|
||||
}
|
||||
} catch (error) {
|
||||
setStatus(error instanceof Error ? error.message : `Failed to submit ${intent.command}.`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,8 @@ import {
|
|||
|
||||
const connectionId = 0x43554c54;
|
||||
const eveSurfaceSchemaId = "gamecult.eve.surface.v1";
|
||||
const eveProviderAdvertisementSchemaId = "gamecult.eve.provider_advertisement.v1";
|
||||
const eveProviderAdvertisementRecordKey = "eve:provider:aetheria";
|
||||
const defaultEveSurfaceRecordKey = "eve:surface:aetheria.daemon.game";
|
||||
const cultMeshCdnAssetBlobSchemaId = "gamecult.cultmesh.cdn.asset_blob.v1";
|
||||
|
||||
|
|
@ -383,6 +385,27 @@ export class AetheriaCultMeshClient {
|
|||
return normalizeEveSurfaceDocument(await document.latest(this.queryContext()));
|
||||
}
|
||||
|
||||
public async eveProviderAdvertisement(): Promise<import("./aetheria-rts-generated-bindings.js").EveProviderAdvertisement> {
|
||||
const document = CultMesh.documentFromPublication(
|
||||
{
|
||||
kind: "peer-snapshot",
|
||||
peer: () => this.peer(),
|
||||
endpoint: this.resolvedRudpEndpoint(),
|
||||
},
|
||||
eveProviderAdvertisementSchemaId,
|
||||
eveProviderAdvertisementRecordKey,
|
||||
{
|
||||
documentId: eveProviderAdvertisementRecordKey,
|
||||
routeHint: this.queryVerse.context.routeHint,
|
||||
sourceId: eveProviderAdvertisementRecordKey,
|
||||
timeoutMs: 1500,
|
||||
pollMs: 50,
|
||||
messageIdPrefix: `${this.runtimeId}:eve-provider`,
|
||||
},
|
||||
);
|
||||
return normalizeEveProviderAdvertisement(await document.latest(this.queryContext()));
|
||||
}
|
||||
|
||||
public async submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt> {
|
||||
const issuedAtUtc = request?.issuedAtUtc || new Date().toISOString();
|
||||
const commandId = `${this.runtimeId}:eve:${Date.now().toString(36)}:${Math.random().toString(36).slice(2)}`;
|
||||
|
|
@ -930,6 +953,20 @@ function eveSurfaceRecordKey(request: AetheriaEveSurfaceRequest): string {
|
|||
return surfaceId ? `eve:surface:${surfaceId}` : defaultEveSurfaceRecordKey;
|
||||
}
|
||||
|
||||
function normalizeEveProviderAdvertisement(document: unknown): import("./aetheria-rts-generated-bindings.js").EveProviderAdvertisement {
|
||||
return {
|
||||
providerId: stringOr(readField(document, "providerId", 1), ""),
|
||||
title: stringOr(readField(document, "title", 8), ""),
|
||||
kind: stringOr(readField(document, "kind", 9), ""),
|
||||
surfaces: arrayValue(readField(document, "surfaces", 14)).map(surface => ({
|
||||
surfaceId: stringOr(readField(surface, "surfaceId", 1), ""),
|
||||
key: stringOr(readField(surface, "key", 2), ""),
|
||||
transport: stringOr(readField(surface, "transport", 3), "cultmesh"),
|
||||
status: stringOr(readField(surface, "status", 4), "available"),
|
||||
})).filter(surface => surface.surfaceId && surface.key),
|
||||
};
|
||||
}
|
||||
|
||||
function normalizeEveSurfaceDocument(document: unknown): AetheriaMenuSurfaceDocument {
|
||||
const portableSlots = Array.isArray(document) &&
|
||||
typeof document[1] === "string" &&
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ export const AetheriaRtsIpcChannels = {
|
|||
surfaceCatalog: "aetheria-rts:surface-catalog",
|
||||
surfaceCatalogIndex: "aetheria-rts:surface-catalog-index",
|
||||
eveSurface: "aetheria-rts:eve-surface",
|
||||
eveProviderAdvertisement: "eve:provider-advertisement",
|
||||
submitEveCommand: "aetheria-rts:submit-eve-command",
|
||||
windowControl: "aetheria-rts:window-control",
|
||||
health: "aetheria-rts:health",
|
||||
|
|
@ -1959,6 +1960,18 @@ export type AetheriaEveSurfaceRequest = {
|
|||
recordKey?: string;
|
||||
};
|
||||
|
||||
export type EveProviderAdvertisement = {
|
||||
providerId: string;
|
||||
title: string;
|
||||
kind: string;
|
||||
surfaces: Array<{
|
||||
surfaceId: string;
|
||||
key: string;
|
||||
transport: string;
|
||||
status: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export type AetheriaEveCommandRequest = {
|
||||
providerId?: string;
|
||||
surfaceId?: string;
|
||||
|
|
@ -2027,6 +2040,7 @@ export type AetheriaRtsMainClient = {
|
|||
setMoveVector(request: AetheriaRuntimeSetMoveVectorRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
setTarget(request: AetheriaRuntimeSetTargetRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
eveSurface(request: AetheriaEveSurfaceRequest): Promise<AetheriaMenuSurfaceDocument>;
|
||||
eveProviderAdvertisement(): Promise<EveProviderAdvertisement>;
|
||||
submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
surfaceCatalogDiagnostics(): CultMeshSurfaceCatalogDiagnostic;
|
||||
surfaceCatalogIndexDiagnostics(): CultMeshSurfaceCatalogIndexDiagnostic;
|
||||
|
|
@ -2076,6 +2090,8 @@ export function registerAetheriaRtsIpcHandlers(
|
|||
getClient().setTarget(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveSurface, async (_event, request: AetheriaEveSurfaceRequest) =>
|
||||
getClient().eveSurface(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveProviderAdvertisement, async () =>
|
||||
getClient().eveProviderAdvertisement());
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.submitEveCommand, async (_event, request: AetheriaEveCommandRequest) =>
|
||||
getClient().submitEveCommand(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.surfaceCatalog, () => getClient().surfaceCatalogDiagnostics());
|
||||
|
|
|
|||
|
|
@ -83,7 +83,9 @@ app.whenReady().then(async () => {
|
|||
|
||||
showStartup("Launching Aetheria Starbridge", "Waiting for the daemon CultMesh frame.");
|
||||
await aetheriaClient.waitForFrame(30000);
|
||||
await mainWindow.loadFile(rendererIndex);
|
||||
await mainWindow.loadFile(rendererIndex, {
|
||||
query: { surface: process.env.EVE_SURFACE_ID || "aetheria.daemon.game" },
|
||||
});
|
||||
if (electronSmoke) {
|
||||
const result = await runElectronSmoke(mainWindow);
|
||||
writeElectronSmokeResult({ ok: true, result });
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ const channels = {
|
|||
surfaceCatalog: "aetheria-rts:surface-catalog",
|
||||
surfaceCatalogIndex: "aetheria-rts:surface-catalog-index",
|
||||
eveSurface: "aetheria-rts:eve-surface",
|
||||
eveProviderAdvertisement: "eve:provider-advertisement",
|
||||
submitEveCommand: "aetheria-rts:submit-eve-command",
|
||||
windowControl: "aetheria-rts:window-control",
|
||||
health: "aetheria-rts:health",
|
||||
|
|
@ -57,6 +58,7 @@ contextBridge.exposeInMainWorld("aetheriaRts", {
|
|||
surfaceCatalog: () => ipcRenderer.invoke(channels.surfaceCatalog),
|
||||
surfaceCatalogIndex: () => ipcRenderer.invoke(channels.surfaceCatalogIndex),
|
||||
eveSurface: request => ipcRenderer.invoke(channels.eveSurface, request),
|
||||
eveProviderAdvertisement: request => ipcRenderer.invoke(channels.eveProviderAdvertisement, request),
|
||||
submitEveCommand: request => ipcRenderer.invoke(channels.submitEveCommand, request),
|
||||
windowControl: request => ipcRenderer.invoke(channels.windowControl, request),
|
||||
health: () => ipcRenderer.invoke(channels.health),
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ const ipcChannels = [
|
|||
["surfaceCatalog", "aetheria-rts:surface-catalog"],
|
||||
["surfaceCatalogIndex", "aetheria-rts:surface-catalog-index"],
|
||||
["eveSurface", "aetheria-rts:eve-surface"],
|
||||
["eveProviderAdvertisement", "eve:provider-advertisement"],
|
||||
["submitEveCommand", "aetheria-rts:submit-eve-command"],
|
||||
["windowControl", "aetheria-rts:window-control"],
|
||||
["health", "aetheria-rts:health"],
|
||||
|
|
@ -485,6 +486,18 @@ export type AetheriaEveSurfaceRequest = {
|
|||
recordKey?: string;
|
||||
};
|
||||
|
||||
export type EveProviderAdvertisement = {
|
||||
providerId: string;
|
||||
title: string;
|
||||
kind: string;
|
||||
surfaces: Array<{
|
||||
surfaceId: string;
|
||||
key: string;
|
||||
transport: string;
|
||||
status: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export type AetheriaEveCommandRequest = {
|
||||
providerId?: string;
|
||||
surfaceId?: string;
|
||||
|
|
@ -553,6 +566,7 @@ export type AetheriaRtsMainClient = {
|
|||
setMoveVector(request: AetheriaRuntimeSetMoveVectorRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
setTarget(request: AetheriaRuntimeSetTargetRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
eveSurface(request: AetheriaEveSurfaceRequest): Promise<AetheriaMenuSurfaceDocument>;
|
||||
eveProviderAdvertisement(): Promise<EveProviderAdvertisement>;
|
||||
submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
surfaceCatalogDiagnostics(): CultMeshSurfaceCatalogDiagnostic;
|
||||
surfaceCatalogIndexDiagnostics(): CultMeshSurfaceCatalogIndexDiagnostic;
|
||||
|
|
@ -602,6 +616,8 @@ export function registerAetheriaRtsIpcHandlers(
|
|||
getClient().setTarget(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveSurface, async (_event, request: AetheriaEveSurfaceRequest) =>
|
||||
getClient().eveSurface(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.eveProviderAdvertisement, async () =>
|
||||
getClient().eveProviderAdvertisement());
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.submitEveCommand, async (_event, request: AetheriaEveCommandRequest) =>
|
||||
getClient().submitEveCommand(request));
|
||||
ipcMain.handle(AetheriaRtsIpcChannels.surfaceCatalog, () => getClient().surfaceCatalogDiagnostics());
|
||||
|
|
@ -1148,6 +1164,18 @@ export type AetheriaEveSurfaceRequest = {
|
|||
recordKey?: string;
|
||||
};
|
||||
|
||||
export type EveProviderAdvertisement = {
|
||||
providerId: string;
|
||||
title: string;
|
||||
kind: string;
|
||||
surfaces: Array<{
|
||||
surfaceId: string;
|
||||
key: string;
|
||||
transport: string;
|
||||
status: string;
|
||||
}>;
|
||||
};
|
||||
|
||||
export type AetheriaEveCommandRequest = {
|
||||
providerId?: string;
|
||||
surfaceId?: string;
|
||||
|
|
@ -1216,6 +1244,7 @@ export type AetheriaRtsApi = {
|
|||
surfaceCatalog(): Promise<CultMeshSurfaceCatalogDiagnostic>;
|
||||
surfaceCatalogIndex(): Promise<CultMeshSurfaceCatalogIndexDiagnostic>;
|
||||
eveSurface(request: AetheriaEveSurfaceRequest): Promise<AetheriaMenuSurfaceDocument>;
|
||||
eveProviderAdvertisement(): Promise<EveProviderAdvertisement>;
|
||||
submitEveCommand(request: AetheriaEveCommandRequest): Promise<AetheriaRuntimeDaemonCommandReceipt>;
|
||||
windowControl(action: "minimize" | "maximize" | "close"): Promise<void>;
|
||||
health(): Promise<unknown>;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ if (-not (Get-Content wwwroot\index.html -Raw).Contains('eve-surface-host')) {
|
|||
}
|
||||
|
||||
$appText = Get-Content wwwroot\app.js -Raw
|
||||
if (-not $appText.Contains('window.aetheriaRts.eveSurface') -or
|
||||
if (-not $appText.Contains('window.aetheriaRts.eveProviderAdvertisement') -or
|
||||
-not $appText.Contains('EveBrowserProviderHost') -or
|
||||
$appText.Contains('eve:surface:aetheria.daemon.game') -or
|
||||
$appText.Contains('legacyViewportMode') -or
|
||||
$appText.Contains('mainMenuSurface') -or
|
||||
$appText.Contains('main-menu-mode')) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue