@air-jam/sdk 0.1.4 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +627 -57
- package/dist/agent-tooling-BSMGBix9.d.cts +123 -0
- package/dist/agent-tooling-BSMGBix9.d.ts +123 -0
- package/dist/agent-tooling.cjs +83 -0
- package/dist/agent-tooling.cjs.map +1 -0
- package/dist/agent-tooling.d.cts +2 -0
- package/dist/agent-tooling.d.ts +2 -0
- package/dist/agent-tooling.js +17 -0
- package/dist/agent-tooling.js.map +1 -0
- package/dist/arcade/bridge/controller.cjs +749 -0
- package/dist/arcade/bridge/controller.cjs.map +1 -0
- package/dist/arcade/bridge/controller.d.cts +85 -0
- package/dist/arcade/bridge/controller.d.ts +85 -0
- package/dist/arcade/bridge/controller.js +33 -0
- package/dist/arcade/bridge/controller.js.map +1 -0
- package/dist/arcade/bridge/host.cjs +421 -0
- package/dist/arcade/bridge/host.cjs.map +1 -0
- package/dist/arcade/bridge/host.d.cts +73 -0
- package/dist/arcade/bridge/host.d.ts +73 -0
- package/dist/arcade/bridge/host.js +25 -0
- package/dist/arcade/bridge/host.js.map +1 -0
- package/dist/arcade/bridge/iframe.cjs +453 -0
- package/dist/arcade/bridge/iframe.cjs.map +1 -0
- package/dist/arcade/bridge/iframe.d.cts +80 -0
- package/dist/arcade/bridge/iframe.d.ts +80 -0
- package/dist/arcade/bridge/iframe.js +28 -0
- package/dist/arcade/bridge/iframe.js.map +1 -0
- package/dist/arcade/bridge.cjs +1067 -0
- package/dist/arcade/bridge.cjs.map +1 -0
- package/dist/arcade/bridge.d.cts +11 -0
- package/dist/arcade/bridge.d.ts +11 -0
- package/dist/arcade/bridge.js +76 -0
- package/dist/arcade/bridge.js.map +1 -0
- package/dist/arcade/host.cjs +481 -0
- package/dist/arcade/host.cjs.map +1 -0
- package/dist/arcade/host.d.cts +19 -0
- package/dist/arcade/host.d.ts +19 -0
- package/dist/arcade/host.js +14 -0
- package/dist/arcade/host.js.map +1 -0
- package/dist/arcade/surface.cjs +113 -0
- package/dist/arcade/surface.cjs.map +1 -0
- package/dist/arcade/surface.d.cts +14 -0
- package/dist/arcade/surface.d.ts +14 -0
- package/dist/arcade/surface.js +27 -0
- package/dist/arcade/surface.js.map +1 -0
- package/dist/arcade/url.cjs +544 -0
- package/dist/arcade/url.cjs.map +1 -0
- package/dist/arcade/url.d.cts +68 -0
- package/dist/arcade/url.d.ts +68 -0
- package/dist/arcade/url.js +29 -0
- package/dist/arcade/url.js.map +1 -0
- package/dist/arcade-runtime-url-BW-MUAOY.d.cts +28 -0
- package/dist/arcade-runtime-url-l8qj01Pg.d.ts +28 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.cts +16 -0
- package/dist/arcade-surface-identity-CQxDpn_w.d.ts +16 -0
- package/dist/arcade.cjs +1737 -0
- package/dist/arcade.cjs.map +1 -0
- package/dist/arcade.d.cts +18 -0
- package/dist/arcade.d.ts +18 -0
- package/dist/arcade.js +123 -0
- package/dist/arcade.js.map +1 -0
- package/dist/capabilities.cjs +39 -0
- package/dist/capabilities.cjs.map +1 -0
- package/dist/capabilities.d.cts +31 -0
- package/dist/capabilities.d.ts +31 -0
- package/dist/capabilities.js +12 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/chunk-32NYL7XI.js +539 -0
- package/dist/chunk-32NYL7XI.js.map +1 -0
- package/dist/chunk-3USU7GY2.js +54 -0
- package/dist/chunk-3USU7GY2.js.map +1 -0
- package/dist/chunk-7UXSWCZZ.js +32 -0
- package/dist/chunk-7UXSWCZZ.js.map +1 -0
- package/dist/chunk-BE6Z4SIT.js +65 -0
- package/dist/chunk-BE6Z4SIT.js.map +1 -0
- package/dist/chunk-CABEUV65.js +184 -0
- package/dist/chunk-CABEUV65.js.map +1 -0
- package/dist/chunk-CEJ5RFSG.js +288 -0
- package/dist/chunk-CEJ5RFSG.js.map +1 -0
- package/dist/chunk-EDRQIOCV.js +25 -0
- package/dist/chunk-EDRQIOCV.js.map +1 -0
- package/dist/chunk-EVZJA6RN.js +140 -0
- package/dist/chunk-EVZJA6RN.js.map +1 -0
- package/dist/chunk-FAT2KJ3K.js +238 -0
- package/dist/chunk-FAT2KJ3K.js.map +1 -0
- package/dist/chunk-IKKDONQL.js +1 -0
- package/dist/chunk-IKKDONQL.js.map +1 -0
- package/dist/chunk-JEHV5C2X.js +249 -0
- package/dist/chunk-JEHV5C2X.js.map +1 -0
- package/dist/chunk-JO2HR5PV.js +43 -0
- package/dist/chunk-JO2HR5PV.js.map +1 -0
- package/dist/chunk-JTF47B56.js +1 -0
- package/dist/chunk-JTF47B56.js.map +1 -0
- package/dist/chunk-KXAFI5OP.js +193 -0
- package/dist/chunk-KXAFI5OP.js.map +1 -0
- package/dist/chunk-LIXPF4P6.js +22 -0
- package/dist/chunk-LIXPF4P6.js.map +1 -0
- package/dist/chunk-MPDMJIX5.js +1 -0
- package/dist/chunk-MPDMJIX5.js.map +1 -0
- package/dist/chunk-NCL6WJCL.js +91 -0
- package/dist/chunk-NCL6WJCL.js.map +1 -0
- package/dist/chunk-NUJBMV3O.js +1435 -0
- package/dist/chunk-NUJBMV3O.js.map +1 -0
- package/dist/chunk-TGRTEWYV.js +195 -0
- package/dist/chunk-TGRTEWYV.js.map +1 -0
- package/dist/chunk-UWJOIVON.js +369 -0
- package/dist/chunk-UWJOIVON.js.map +1 -0
- package/dist/chunk-VKBMZHMQ.js +216 -0
- package/dist/chunk-VKBMZHMQ.js.map +1 -0
- package/dist/chunk-W2VK36RO.js +11 -0
- package/dist/chunk-W2VK36RO.js.map +1 -0
- package/dist/chunk-W3YA5BWR.js +126 -0
- package/dist/chunk-W3YA5BWR.js.map +1 -0
- package/dist/chunk-X24K52DG.js +12 -0
- package/dist/chunk-X24K52DG.js.map +1 -0
- package/dist/chunk-YXHH3MQT.js +230 -0
- package/dist/chunk-YXHH3MQT.js.map +1 -0
- package/dist/chunk-ZLPL2R3R.js +183 -0
- package/dist/chunk-ZLPL2R3R.js.map +1 -0
- package/dist/chunk-ZTQ5SP4H.js +9 -0
- package/dist/chunk-ZTQ5SP4H.js.map +1 -0
- package/dist/controller-Bod8YYr1.d.cts +172 -0
- package/dist/controller-DxVchfiA.d.ts +172 -0
- package/dist/dev-log-events-CVAM29hx.d.cts +123 -0
- package/dist/dev-log-events-CVAM29hx.d.ts +123 -0
- package/dist/handshake-CC_LrK5g.d.cts +31 -0
- package/dist/handshake-CC_LrK5g.d.ts +31 -0
- package/dist/host-8hmq_Sgc.d.cts +109 -0
- package/dist/host-Cw-N6e-5.d.ts +109 -0
- package/dist/index.cjs +8730 -3426
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +676 -1070
- package/dist/index.d.ts +676 -1070
- package/dist/index.js +4892 -3196
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs +114 -0
- package/dist/metadata.cjs.map +1 -0
- package/dist/metadata.d.cts +95 -0
- package/dist/metadata.d.ts +95 -0
- package/dist/metadata.js +83 -0
- package/dist/metadata.js.map +1 -0
- package/dist/notices-CnGaaS8B.d.ts +38 -0
- package/dist/notices-NyDM5Mtz.d.cts +38 -0
- package/dist/platform-machine.cjs +425 -0
- package/dist/platform-machine.cjs.map +1 -0
- package/dist/platform-machine.d.cts +1183 -0
- package/dist/platform-machine.d.ts +1183 -0
- package/dist/platform-machine.js +309 -0
- package/dist/platform-machine.js.map +1 -0
- package/dist/platform-settings-cuor3i11.d.cts +48 -0
- package/dist/platform-settings-cuor3i11.d.ts +48 -0
- package/dist/prefabs.cjs +36 -0
- package/dist/prefabs.cjs.map +1 -0
- package/dist/prefabs.d.cts +49 -0
- package/dist/prefabs.d.ts +49 -0
- package/dist/prefabs.js +8 -0
- package/dist/prefabs.js.map +1 -0
- package/dist/preview.cjs +2620 -0
- package/dist/preview.cjs.map +1 -0
- package/dist/preview.d.cts +155 -0
- package/dist/preview.d.ts +155 -0
- package/dist/preview.js +1671 -0
- package/dist/preview.js.map +1 -0
- package/dist/protocol.cjs +621 -54
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +76 -240
- package/dist/protocol.d.ts +76 -240
- package/dist/protocol.js +100 -2
- package/dist/protocol.js.map +1 -1
- package/dist/realtime-client-Cu8yVJFw.d.cts +15 -0
- package/dist/realtime-client-Cu8yVJFw.d.ts +15 -0
- package/dist/release.cjs +143 -0
- package/dist/release.cjs.map +1 -0
- package/dist/release.d.cts +64 -0
- package/dist/release.d.ts +64 -0
- package/dist/release.js +43 -0
- package/dist/release.js.map +1 -0
- package/dist/runtime-topology.cjs +405 -0
- package/dist/runtime-topology.cjs.map +1 -0
- package/dist/runtime-topology.d.cts +59 -0
- package/dist/runtime-topology.d.ts +59 -0
- package/dist/runtime-topology.js +31 -0
- package/dist/runtime-topology.js.map +1 -0
- package/dist/standard-match-phase-BucA5dYo.d.ts +44 -0
- package/dist/standard-match-phase-U2ra8J-0.d.cts +44 -0
- package/dist/sync-B6QsNrXz.d.cts +125 -0
- package/dist/sync-B6QsNrXz.d.ts +125 -0
- package/dist/ui.cjs +3061 -0
- package/dist/ui.cjs.map +1 -0
- package/dist/ui.d.cts +320 -0
- package/dist/ui.d.ts +320 -0
- package/dist/ui.js +1719 -0
- package/dist/ui.js.map +1 -0
- package/dist/url-policy-C89zxgw9.d.cts +9 -0
- package/dist/url-policy-C89zxgw9.d.ts +9 -0
- package/package.json +155 -10
- package/src/agent/agent-action.ts +304 -0
- package/src/agent/agent-contract.ts +180 -0
- package/src/agent-tooling.ts +20 -0
- package/src/arcade/bridge/controller.ts +15 -0
- package/src/arcade/bridge/host.ts +12 -0
- package/src/arcade/bridge/iframe.ts +61 -0
- package/src/arcade/bridge.ts +3 -0
- package/src/arcade/host.ts +1 -0
- package/src/arcade/surface.ts +4 -0
- package/src/arcade/url.ts +60 -0
- package/src/arcade.ts +4 -0
- package/src/audio/audio-manager.ts +162 -171
- package/src/audio/hooks.tsx +218 -97
- package/src/audio/index.ts +1 -1
- package/src/audio/music.tsx +139 -0
- package/src/capabilities/manifest.ts +71 -0
- package/src/capabilities.ts +12 -0
- package/src/components/connection-status-pill.tsx +55 -0
- package/src/components/controller-player-name-field.tsx +119 -0
- package/src/components/controller-primary-action.tsx +58 -0
- package/src/components/host-mute-button.tsx +49 -0
- package/src/components/join-qr-overlay.tsx +133 -0
- package/src/components/join-url-action-buttons.tsx +95 -0
- package/src/components/join-url-controls.tsx +58 -0
- package/src/components/join-url-field.tsx +52 -0
- package/src/components/lifecycle-action-group.tsx +129 -0
- package/src/components/player-avatar-strip.tsx +65 -0
- package/src/components/player-avatar.tsx +42 -13
- package/src/components/room-qr-code.tsx +125 -0
- package/src/components/runtime-shell-header.tsx +37 -0
- package/src/components/shell-classes.ts +19 -0
- package/src/components/surface-orientation-layout.ts +60 -0
- package/src/components/surface-viewport-layout.ts +268 -0
- package/src/components/surface-viewport.tsx +314 -0
- package/src/components/ui/button.tsx +4 -6
- package/src/components/ui/slider.tsx +1 -1
- package/src/components/volume-controls.tsx +65 -6
- package/src/context/air-jam-context.tsx +209 -161
- package/src/context/index.ts +2 -2
- package/src/context/session-providers.tsx +77 -0
- package/src/context/session-scope.ts +64 -0
- package/src/context/socket-manager.ts +6 -24
- package/src/contracts/v2/bridge.ts +261 -0
- package/src/contracts/v2/handshake.ts +40 -0
- package/src/contracts/v2/index.ts +2 -0
- package/src/dev/browser-log-sink.ts +912 -0
- package/src/diagnostics.ts +128 -0
- package/src/events.ts +7 -34
- package/src/hooks/internal/use-controller-runtime-api.ts +875 -0
- package/src/hooks/internal/use-host-runtime-api.ts +1051 -0
- package/src/hooks/internal/use-runtime-control-contract.ts +15 -0
- package/src/hooks/internal/use-runtime-inspection-contract.ts +16 -0
- package/src/hooks/internal/use-runtime-observability-contract.ts +24 -0
- package/src/hooks/use-air-jam-controller.ts +155 -475
- package/src/hooks/use-air-jam-host.ts +156 -485
- package/src/hooks/use-connection-status.ts +8 -0
- package/src/hooks/use-controller-lifecycle-intents.ts +27 -0
- package/src/hooks/use-controller-lifecycle-permissions.ts +36 -0
- package/src/hooks/use-controller-shell-status.ts +40 -0
- package/src/hooks/use-controller-tick.ts +65 -0
- package/src/hooks/use-controller-toasts.ts +116 -0
- package/src/hooks/use-get-input.ts +8 -5
- package/src/hooks/use-host-arcade-restore.ts +30 -0
- package/src/hooks/use-host-join-controls.ts +152 -0
- package/src/hooks/use-host-tick.ts +171 -0
- package/src/hooks/use-input-writer.ts +83 -0
- package/src/hooks/use-lifecycle-action-group-model.ts +98 -0
- package/src/hooks/use-players.ts +12 -0
- package/src/hooks/use-room.ts +22 -0
- package/src/hooks/use-send-signal.ts +6 -2
- package/src/index.ts +205 -31
- package/src/internal/input-manager.ts +195 -215
- package/src/lifecycle/index.ts +9 -0
- package/src/lifecycle/standard-match-phase.ts +32 -0
- package/src/metadata/manifest.ts +152 -0
- package/src/metadata.ts +12 -0
- package/src/platform-machine.ts +475 -0
- package/src/prefabs/types.ts +82 -0
- package/src/prefabs.ts +12 -0
- package/src/preview/host-workspace.tsx +59 -0
- package/src/preview/identity.ts +66 -0
- package/src/preview/layout.ts +223 -0
- package/src/preview/manager.ts +577 -0
- package/src/preview/messages.ts +26 -0
- package/src/preview/ownership.ts +81 -0
- package/src/preview/url.ts +117 -0
- package/src/preview/window.tsx +490 -0
- package/src/preview/workspace.tsx +678 -0
- package/src/preview.ts +42 -0
- package/src/protocol/arcade-platform-actions.ts +29 -0
- package/src/protocol/controller.ts +187 -0
- package/src/protocol/core.ts +23 -0
- package/src/protocol/dev-log-events.ts +222 -0
- package/src/protocol/errors.ts +21 -0
- package/src/protocol/host-grant.ts +185 -0
- package/src/protocol/host.ts +138 -0
- package/src/protocol/notices.ts +43 -0
- package/src/protocol/signals.ts +38 -0
- package/src/protocol/socket-events.ts +154 -0
- package/src/protocol/sync.ts +121 -0
- package/src/protocol/url-policy.ts +63 -0
- package/src/protocol.ts +12 -386
- package/src/qrcode.d.ts +16 -0
- package/src/release.ts +99 -0
- package/src/runtime/air-jam-config.ts +287 -0
- package/src/runtime/air-jam-error-boundary.tsx +672 -0
- package/src/runtime/arcade-bridge-request-surface.ts +15 -0
- package/src/runtime/arcade-runtime-url.ts +95 -0
- package/src/runtime/arcade-surface-identity.ts +16 -0
- package/src/runtime/contracts/control.ts +68 -0
- package/src/runtime/contracts/inspection.ts +165 -0
- package/src/runtime/contracts/observability.ts +94 -0
- package/src/runtime/controller-bridge.ts +451 -0
- package/src/runtime/controller-identity.ts +132 -0
- package/src/runtime/controller-presentation.ts +24 -0
- package/src/runtime/controller-realtime-client.ts +591 -0
- package/src/runtime/create-air-jam-app.tsx +260 -0
- package/src/runtime/dev-runtime-events.ts +36 -0
- package/src/runtime/embedded-runtime-adapters.ts +68 -0
- package/src/runtime/host-bridge.ts +388 -0
- package/src/runtime/host-realtime-client.ts +550 -0
- package/src/runtime/iframe-bridge.ts +135 -0
- package/src/runtime/realtime-client.ts +20 -0
- package/src/runtime/router-basename.ts +25 -0
- package/src/runtime/runtime-owner-contexts.tsx +4 -0
- package/src/runtime/runtime-session-params.ts +169 -0
- package/src/runtime/sdk-version.ts +6 -0
- package/src/runtime/session-runtimes.tsx +188 -0
- package/src/runtime/validate-arcade-bridge-attach.ts +14 -0
- package/src/runtime-control.ts +10 -0
- package/src/runtime-inspection.ts +14 -0
- package/src/runtime-observability.ts +9 -0
- package/src/runtime-topology.ts +569 -0
- package/src/settings/platform-settings-bridge.ts +336 -0
- package/src/settings/platform-settings-runtime.tsx +387 -0
- package/src/settings/platform-settings.ts +288 -0
- package/src/state/connection-store.ts +80 -12
- package/src/store/air-jam-store-domain-constants.ts +4 -0
- package/src/store/create-air-jam-store.ts +1094 -227
- package/src/styles.css +4 -38
- package/src/ui.ts +29 -0
- package/src/utils/is-rpc-serializable.ts +56 -0
- package/src/utils/player-avatar-url.ts +48 -0
- package/src/utils/url-builder.ts +7 -0
- package/dist/.tsbuildinfo +0 -1
- package/dist/chunk-B5DURUWT.js +0 -80
- package/dist/chunk-B5DURUWT.js.map +0 -1
- package/src/AirJamClient.ts +0 -224
- package/src/audio/volume-store.ts +0 -124
- package/src/components/controller-shell.tsx +0 -346
- package/src/components/host-shell.tsx +0 -520
- package/src/components/qr-scanner-dialog.tsx +0 -373
- package/src/components/ui/alert.tsx +0 -66
- package/src/components/ui/avatar.tsx +0 -46
- package/src/components/ui/badge.tsx +0 -47
- package/src/components/ui/card.tsx +0 -92
- package/src/components/ui/dialog.tsx +0 -122
- package/src/components/ui/tabs.tsx +0 -64
- package/src/hooks/use-air-jam-shell.ts +0 -379
- package/src/hooks/use-fullscreen.ts +0 -108
|
@@ -0,0 +1,672 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Check,
|
|
3
|
+
Copy,
|
|
4
|
+
Maximize2,
|
|
5
|
+
Minimize2,
|
|
6
|
+
RefreshCw,
|
|
7
|
+
RotateCcw,
|
|
8
|
+
} from "lucide-react";
|
|
9
|
+
import type { CSSProperties, ErrorInfo, JSX, ReactNode } from "react";
|
|
10
|
+
import { Component, useCallback, useEffect, useRef, useState } from "react";
|
|
11
|
+
import { emitAirJamDiagnostic } from "../diagnostics";
|
|
12
|
+
import { AIRJAM_DEV_LOG_EVENTS } from "../protocol";
|
|
13
|
+
import { emitAirJamDevRuntimeEvent } from "./dev-runtime-events";
|
|
14
|
+
|
|
15
|
+
export type AirJamRuntimeRole = "host" | "controller";
|
|
16
|
+
|
|
17
|
+
interface AirJamRuntimeErrorContext {
|
|
18
|
+
role: AirJamRuntimeRole;
|
|
19
|
+
roomId?: string;
|
|
20
|
+
appId?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface AirJamErrorFallbackRenderProps extends AirJamRuntimeErrorContext {
|
|
24
|
+
error: Error;
|
|
25
|
+
reset: () => void;
|
|
26
|
+
reload: () => void;
|
|
27
|
+
isEmbedded: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type AirJamErrorFallbackRenderer = (
|
|
31
|
+
props: AirJamErrorFallbackRenderProps,
|
|
32
|
+
) => JSX.Element;
|
|
33
|
+
|
|
34
|
+
export interface AirJamErrorBoundaryProps extends AirJamRuntimeErrorContext {
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
renderFallback?: AirJamErrorFallbackRenderer;
|
|
37
|
+
onError?: (
|
|
38
|
+
error: Error,
|
|
39
|
+
errorInfo: ErrorInfo,
|
|
40
|
+
context: AirJamRuntimeErrorContext,
|
|
41
|
+
) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface AirJamErrorBoundaryState {
|
|
45
|
+
error: Error | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const toError = (value: unknown): Error => {
|
|
49
|
+
if (value instanceof Error) {
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
if (typeof value === "string") {
|
|
53
|
+
return new Error(value);
|
|
54
|
+
}
|
|
55
|
+
return new Error("Unknown runtime error");
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const isEmbeddedRuntime = (): boolean =>
|
|
59
|
+
typeof window !== "undefined" &&
|
|
60
|
+
typeof window.parent !== "undefined" &&
|
|
61
|
+
window.parent !== window;
|
|
62
|
+
|
|
63
|
+
const roleLabel = (role: AirJamRuntimeRole): string =>
|
|
64
|
+
role === "host" ? "Host runtime" : "Controller runtime";
|
|
65
|
+
|
|
66
|
+
const mono =
|
|
67
|
+
"ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, monospace";
|
|
68
|
+
|
|
69
|
+
const errorSurface = {
|
|
70
|
+
bg: "#0a0a0a",
|
|
71
|
+
panel: "#141414",
|
|
72
|
+
panelBorder: "rgba(255, 255, 255, 0.08)",
|
|
73
|
+
inset: "#0c0c0c",
|
|
74
|
+
insetBorder: "rgba(255, 255, 255, 0.06)",
|
|
75
|
+
text: "#fafafa",
|
|
76
|
+
muted: "#a3a3a3",
|
|
77
|
+
dim: "#737373",
|
|
78
|
+
zOverlay: 2147483000,
|
|
79
|
+
} as const;
|
|
80
|
+
|
|
81
|
+
const iconSize = 16;
|
|
82
|
+
|
|
83
|
+
const createErrorDigest = (error: Error): string => {
|
|
84
|
+
const input = `${error.name}:${error.message}:${error.stack ?? ""}`;
|
|
85
|
+
let hash = 0;
|
|
86
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
87
|
+
hash = (hash * 31 + input.charCodeAt(index)) >>> 0;
|
|
88
|
+
}
|
|
89
|
+
return hash.toString(16).padStart(8, "0");
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const copyTextToClipboard = async (text: string): Promise<void> => {
|
|
93
|
+
if (
|
|
94
|
+
typeof navigator !== "undefined" &&
|
|
95
|
+
navigator.clipboard &&
|
|
96
|
+
typeof navigator.clipboard.writeText === "function"
|
|
97
|
+
) {
|
|
98
|
+
await navigator.clipboard.writeText(text);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (typeof document === "undefined") {
|
|
103
|
+
throw new Error("Clipboard is unavailable");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const textarea = document.createElement("textarea");
|
|
107
|
+
textarea.value = text;
|
|
108
|
+
textarea.style.position = "fixed";
|
|
109
|
+
textarea.style.opacity = "0";
|
|
110
|
+
textarea.style.pointerEvents = "none";
|
|
111
|
+
document.body.appendChild(textarea);
|
|
112
|
+
textarea.focus();
|
|
113
|
+
textarea.select();
|
|
114
|
+
|
|
115
|
+
const succeeded =
|
|
116
|
+
typeof document.execCommand === "function"
|
|
117
|
+
? document.execCommand("copy")
|
|
118
|
+
: false;
|
|
119
|
+
|
|
120
|
+
document.body.removeChild(textarea);
|
|
121
|
+
|
|
122
|
+
if (!succeeded) {
|
|
123
|
+
throw new Error("Copy command failed");
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const createCopyPayload = ({
|
|
128
|
+
role,
|
|
129
|
+
roomId,
|
|
130
|
+
appId,
|
|
131
|
+
error,
|
|
132
|
+
digest,
|
|
133
|
+
isEmbedded,
|
|
134
|
+
}: {
|
|
135
|
+
role: AirJamRuntimeRole;
|
|
136
|
+
roomId?: string;
|
|
137
|
+
appId?: string;
|
|
138
|
+
error: Error;
|
|
139
|
+
digest: string;
|
|
140
|
+
isEmbedded: boolean;
|
|
141
|
+
}): string => {
|
|
142
|
+
const lines = [
|
|
143
|
+
"AirJam Runtime Error",
|
|
144
|
+
`Role: ${role}`,
|
|
145
|
+
`Digest: ${digest}`,
|
|
146
|
+
`Embedded: ${isEmbedded ? "yes" : "no"}`,
|
|
147
|
+
roomId ? `Room: ${roomId}` : null,
|
|
148
|
+
appId ? `App ID: ${appId}` : null,
|
|
149
|
+
`Error: ${error.message || "Unknown error"}`,
|
|
150
|
+
"",
|
|
151
|
+
"Stack:",
|
|
152
|
+
error.stack ?? "(no stack)",
|
|
153
|
+
].filter((line): line is string => line !== null);
|
|
154
|
+
|
|
155
|
+
return lines.join("\n");
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const btnRow: CSSProperties = {
|
|
159
|
+
display: "inline-flex",
|
|
160
|
+
alignItems: "center",
|
|
161
|
+
justifyContent: "center",
|
|
162
|
+
gap: "0.35rem",
|
|
163
|
+
borderRadius: "0.5rem",
|
|
164
|
+
padding: "0.5rem 0.75rem",
|
|
165
|
+
fontSize: "0.8125rem",
|
|
166
|
+
fontWeight: 600,
|
|
167
|
+
cursor: "pointer",
|
|
168
|
+
fontFamily:
|
|
169
|
+
"ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif",
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const DefaultFallback = ({
|
|
173
|
+
role,
|
|
174
|
+
roomId,
|
|
175
|
+
appId,
|
|
176
|
+
error,
|
|
177
|
+
reset,
|
|
178
|
+
reload,
|
|
179
|
+
isEmbedded,
|
|
180
|
+
}: AirJamErrorFallbackRenderProps): JSX.Element => {
|
|
181
|
+
const digest = createErrorDigest(error);
|
|
182
|
+
const [isMinimized, setIsMinimized] = useState(false);
|
|
183
|
+
const [copyState, setCopyState] = useState<"idle" | "copied" | "failed">(
|
|
184
|
+
"idle",
|
|
185
|
+
);
|
|
186
|
+
const copyResetTimeoutRef = useRef<number | null>(null);
|
|
187
|
+
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
return () => {
|
|
190
|
+
if (
|
|
191
|
+
copyResetTimeoutRef.current !== null &&
|
|
192
|
+
typeof window !== "undefined"
|
|
193
|
+
) {
|
|
194
|
+
window.clearTimeout(copyResetTimeoutRef.current);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}, []);
|
|
198
|
+
|
|
199
|
+
const scheduleCopyStatusReset = useCallback(() => {
|
|
200
|
+
if (typeof window === "undefined") {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (copyResetTimeoutRef.current !== null) {
|
|
204
|
+
window.clearTimeout(copyResetTimeoutRef.current);
|
|
205
|
+
}
|
|
206
|
+
copyResetTimeoutRef.current = window.setTimeout(() => {
|
|
207
|
+
setCopyState("idle");
|
|
208
|
+
copyResetTimeoutRef.current = null;
|
|
209
|
+
}, 1800);
|
|
210
|
+
}, []);
|
|
211
|
+
|
|
212
|
+
const handleCopy = useCallback(async () => {
|
|
213
|
+
try {
|
|
214
|
+
await copyTextToClipboard(
|
|
215
|
+
createCopyPayload({
|
|
216
|
+
role,
|
|
217
|
+
roomId,
|
|
218
|
+
appId,
|
|
219
|
+
error,
|
|
220
|
+
isEmbedded,
|
|
221
|
+
digest,
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
setCopyState("copied");
|
|
225
|
+
scheduleCopyStatusReset();
|
|
226
|
+
} catch {
|
|
227
|
+
setCopyState("failed");
|
|
228
|
+
scheduleCopyStatusReset();
|
|
229
|
+
}
|
|
230
|
+
}, [appId, digest, error, isEmbedded, role, roomId, scheduleCopyStatusReset]);
|
|
231
|
+
|
|
232
|
+
const copyButtonLabel =
|
|
233
|
+
copyState === "copied"
|
|
234
|
+
? "Copied"
|
|
235
|
+
: copyState === "failed"
|
|
236
|
+
? "Copy failed"
|
|
237
|
+
: "Copy details";
|
|
238
|
+
|
|
239
|
+
const CopyGlyph =
|
|
240
|
+
copyState === "copied" ? (
|
|
241
|
+
<Check size={iconSize} strokeWidth={2} aria-hidden />
|
|
242
|
+
) : (
|
|
243
|
+
<Copy size={iconSize} strokeWidth={2} aria-hidden />
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
if (isMinimized) {
|
|
247
|
+
return (
|
|
248
|
+
<>
|
|
249
|
+
<div
|
|
250
|
+
aria-hidden
|
|
251
|
+
style={{
|
|
252
|
+
position: "fixed",
|
|
253
|
+
inset: 0,
|
|
254
|
+
zIndex: errorSurface.zOverlay,
|
|
255
|
+
background: "rgba(10, 10, 10, 0.72)",
|
|
256
|
+
}}
|
|
257
|
+
/>
|
|
258
|
+
<div
|
|
259
|
+
style={{
|
|
260
|
+
position: "fixed",
|
|
261
|
+
bottom: "1rem",
|
|
262
|
+
right: "1rem",
|
|
263
|
+
zIndex: errorSurface.zOverlay + 1,
|
|
264
|
+
maxWidth: "min(22rem, calc(100vw - 2rem))",
|
|
265
|
+
borderRadius: "0.625rem",
|
|
266
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
267
|
+
background: errorSurface.panel,
|
|
268
|
+
boxShadow: "0 16px 48px rgba(0, 0, 0, 0.55)",
|
|
269
|
+
padding: "0.75rem 0.85rem",
|
|
270
|
+
}}
|
|
271
|
+
>
|
|
272
|
+
<div
|
|
273
|
+
style={{
|
|
274
|
+
display: "flex",
|
|
275
|
+
alignItems: "flex-start",
|
|
276
|
+
justifyContent: "space-between",
|
|
277
|
+
gap: "0.5rem",
|
|
278
|
+
}}
|
|
279
|
+
>
|
|
280
|
+
<div style={{ minWidth: 0 }}>
|
|
281
|
+
<div
|
|
282
|
+
style={{
|
|
283
|
+
fontSize: "0.6875rem",
|
|
284
|
+
fontWeight: 600,
|
|
285
|
+
letterSpacing: "0.02em",
|
|
286
|
+
color: errorSurface.dim,
|
|
287
|
+
textTransform: "uppercase",
|
|
288
|
+
}}
|
|
289
|
+
>
|
|
290
|
+
AirJam · runtime error
|
|
291
|
+
</div>
|
|
292
|
+
<div
|
|
293
|
+
style={{
|
|
294
|
+
marginTop: "0.25rem",
|
|
295
|
+
fontSize: "0.75rem",
|
|
296
|
+
color: errorSurface.muted,
|
|
297
|
+
fontFamily: mono,
|
|
298
|
+
lineHeight: 1.4,
|
|
299
|
+
wordBreak: "break-word",
|
|
300
|
+
}}
|
|
301
|
+
>
|
|
302
|
+
{role} · {digest}
|
|
303
|
+
</div>
|
|
304
|
+
</div>
|
|
305
|
+
<button
|
|
306
|
+
type="button"
|
|
307
|
+
onClick={() => setIsMinimized(false)}
|
|
308
|
+
aria-label="Expand error panel"
|
|
309
|
+
title="Expand error panel"
|
|
310
|
+
style={{
|
|
311
|
+
...btnRow,
|
|
312
|
+
flexShrink: 0,
|
|
313
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
314
|
+
background: errorSurface.inset,
|
|
315
|
+
color: errorSurface.text,
|
|
316
|
+
padding: "0.4rem",
|
|
317
|
+
}}
|
|
318
|
+
>
|
|
319
|
+
<Maximize2 size={iconSize} strokeWidth={2} aria-hidden />
|
|
320
|
+
</button>
|
|
321
|
+
</div>
|
|
322
|
+
<div
|
|
323
|
+
style={{
|
|
324
|
+
marginTop: "0.65rem",
|
|
325
|
+
display: "flex",
|
|
326
|
+
flexWrap: "wrap",
|
|
327
|
+
gap: "0.4rem",
|
|
328
|
+
}}
|
|
329
|
+
>
|
|
330
|
+
<button
|
|
331
|
+
type="button"
|
|
332
|
+
onClick={() => {
|
|
333
|
+
void handleCopy();
|
|
334
|
+
}}
|
|
335
|
+
style={{
|
|
336
|
+
...btnRow,
|
|
337
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
338
|
+
background: "transparent",
|
|
339
|
+
color: errorSurface.muted,
|
|
340
|
+
}}
|
|
341
|
+
>
|
|
342
|
+
{CopyGlyph}
|
|
343
|
+
{copyButtonLabel}
|
|
344
|
+
</button>
|
|
345
|
+
<button
|
|
346
|
+
type="button"
|
|
347
|
+
onClick={reload}
|
|
348
|
+
style={{
|
|
349
|
+
...btnRow,
|
|
350
|
+
border: "none",
|
|
351
|
+
background: errorSurface.text,
|
|
352
|
+
color: errorSurface.bg,
|
|
353
|
+
}}
|
|
354
|
+
>
|
|
355
|
+
<RefreshCw size={iconSize} strokeWidth={2} aria-hidden />
|
|
356
|
+
Reload
|
|
357
|
+
</button>
|
|
358
|
+
</div>
|
|
359
|
+
</div>
|
|
360
|
+
</>
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return (
|
|
365
|
+
<div
|
|
366
|
+
style={{
|
|
367
|
+
minHeight: "100vh",
|
|
368
|
+
width: "100%",
|
|
369
|
+
display: "flex",
|
|
370
|
+
alignItems: "center",
|
|
371
|
+
justifyContent: "center",
|
|
372
|
+
background: errorSurface.bg,
|
|
373
|
+
padding: "1.5rem 1rem",
|
|
374
|
+
boxSizing: "border-box",
|
|
375
|
+
}}
|
|
376
|
+
>
|
|
377
|
+
<div
|
|
378
|
+
style={{
|
|
379
|
+
position: "relative",
|
|
380
|
+
width: "100%",
|
|
381
|
+
maxWidth: "42rem",
|
|
382
|
+
borderRadius: "0.625rem",
|
|
383
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
384
|
+
background: errorSurface.panel,
|
|
385
|
+
boxShadow: "0 24px 64px rgba(0, 0, 0, 0.45)",
|
|
386
|
+
padding: "1.25rem 1.35rem",
|
|
387
|
+
boxSizing: "border-box",
|
|
388
|
+
}}
|
|
389
|
+
>
|
|
390
|
+
<button
|
|
391
|
+
type="button"
|
|
392
|
+
onClick={() => setIsMinimized(true)}
|
|
393
|
+
aria-label="Minimize error panel"
|
|
394
|
+
title="Minimize error panel"
|
|
395
|
+
style={{
|
|
396
|
+
...btnRow,
|
|
397
|
+
position: "absolute",
|
|
398
|
+
top: "0.85rem",
|
|
399
|
+
right: "0.85rem",
|
|
400
|
+
padding: "0.4rem",
|
|
401
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
402
|
+
background: errorSurface.inset,
|
|
403
|
+
color: errorSurface.muted,
|
|
404
|
+
}}
|
|
405
|
+
>
|
|
406
|
+
<Minimize2 size={iconSize} strokeWidth={2} aria-hidden />
|
|
407
|
+
</button>
|
|
408
|
+
|
|
409
|
+
<div
|
|
410
|
+
style={{
|
|
411
|
+
fontSize: "0.6875rem",
|
|
412
|
+
fontWeight: 500,
|
|
413
|
+
letterSpacing: "0.04em",
|
|
414
|
+
color: errorSurface.dim,
|
|
415
|
+
textTransform: "uppercase",
|
|
416
|
+
paddingRight: "2.5rem",
|
|
417
|
+
}}
|
|
418
|
+
>
|
|
419
|
+
AirJam · runtime error · {role}
|
|
420
|
+
</div>
|
|
421
|
+
|
|
422
|
+
<h1
|
|
423
|
+
style={{
|
|
424
|
+
marginTop: "0.65rem",
|
|
425
|
+
marginBottom: 0,
|
|
426
|
+
fontSize: "1.25rem",
|
|
427
|
+
lineHeight: 1.25,
|
|
428
|
+
fontWeight: 600,
|
|
429
|
+
color: errorSurface.text,
|
|
430
|
+
fontFamily:
|
|
431
|
+
"ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif",
|
|
432
|
+
}}
|
|
433
|
+
>
|
|
434
|
+
Something went wrong
|
|
435
|
+
</h1>
|
|
436
|
+
|
|
437
|
+
<p
|
|
438
|
+
style={{
|
|
439
|
+
marginTop: "0.45rem",
|
|
440
|
+
marginBottom: 0,
|
|
441
|
+
fontSize: "0.8125rem",
|
|
442
|
+
color: errorSurface.muted,
|
|
443
|
+
lineHeight: 1.45,
|
|
444
|
+
}}
|
|
445
|
+
>
|
|
446
|
+
{roleLabel(role)} hit an error. Details below.
|
|
447
|
+
</p>
|
|
448
|
+
|
|
449
|
+
<div
|
|
450
|
+
style={{
|
|
451
|
+
marginTop: "1rem",
|
|
452
|
+
border: `1px solid ${errorSurface.insetBorder}`,
|
|
453
|
+
borderRadius: "0.5rem",
|
|
454
|
+
background: errorSurface.inset,
|
|
455
|
+
padding: "0.75rem 0.85rem",
|
|
456
|
+
fontSize: "0.75rem",
|
|
457
|
+
color: errorSurface.muted,
|
|
458
|
+
fontFamily: mono,
|
|
459
|
+
lineHeight: 1.5,
|
|
460
|
+
wordBreak: "break-word",
|
|
461
|
+
}}
|
|
462
|
+
>
|
|
463
|
+
<div>
|
|
464
|
+
<span style={{ color: errorSurface.dim }}>Digest </span>
|
|
465
|
+
{digest}
|
|
466
|
+
</div>
|
|
467
|
+
{roomId ? (
|
|
468
|
+
<div style={{ marginTop: "0.35rem" }}>
|
|
469
|
+
<span style={{ color: errorSurface.dim }}>Room </span>
|
|
470
|
+
{roomId}
|
|
471
|
+
</div>
|
|
472
|
+
) : null}
|
|
473
|
+
<div style={{ marginTop: "0.35rem" }}>
|
|
474
|
+
<span style={{ color: errorSurface.dim }}>Error </span>
|
|
475
|
+
{error.message || "Unknown error"}
|
|
476
|
+
</div>
|
|
477
|
+
</div>
|
|
478
|
+
|
|
479
|
+
<details
|
|
480
|
+
style={{
|
|
481
|
+
marginTop: "0.75rem",
|
|
482
|
+
fontSize: "0.75rem",
|
|
483
|
+
color: errorSurface.muted,
|
|
484
|
+
}}
|
|
485
|
+
>
|
|
486
|
+
<summary
|
|
487
|
+
style={{
|
|
488
|
+
cursor: "pointer",
|
|
489
|
+
fontWeight: 500,
|
|
490
|
+
color: errorSurface.muted,
|
|
491
|
+
listStyle: "none",
|
|
492
|
+
}}
|
|
493
|
+
>
|
|
494
|
+
Stack trace
|
|
495
|
+
</summary>
|
|
496
|
+
<pre
|
|
497
|
+
style={{
|
|
498
|
+
marginTop: "0.5rem",
|
|
499
|
+
marginBottom: 0,
|
|
500
|
+
overflowX: "auto",
|
|
501
|
+
whiteSpace: "pre-wrap",
|
|
502
|
+
wordBreak: "break-word",
|
|
503
|
+
border: `1px solid ${errorSurface.insetBorder}`,
|
|
504
|
+
borderRadius: "0.45rem",
|
|
505
|
+
background: errorSurface.inset,
|
|
506
|
+
padding: "0.65rem 0.75rem",
|
|
507
|
+
color: errorSurface.muted,
|
|
508
|
+
fontFamily: mono,
|
|
509
|
+
fontSize: "0.6875rem",
|
|
510
|
+
lineHeight: 1.45,
|
|
511
|
+
}}
|
|
512
|
+
>
|
|
513
|
+
{error.stack ?? error.message}
|
|
514
|
+
</pre>
|
|
515
|
+
</details>
|
|
516
|
+
|
|
517
|
+
<div
|
|
518
|
+
style={{
|
|
519
|
+
marginTop: "1.1rem",
|
|
520
|
+
display: "flex",
|
|
521
|
+
flexWrap: "wrap",
|
|
522
|
+
alignItems: "center",
|
|
523
|
+
gap: "0.45rem",
|
|
524
|
+
}}
|
|
525
|
+
>
|
|
526
|
+
<button
|
|
527
|
+
type="button"
|
|
528
|
+
onClick={reload}
|
|
529
|
+
style={{
|
|
530
|
+
...btnRow,
|
|
531
|
+
border: "none",
|
|
532
|
+
background: errorSurface.text,
|
|
533
|
+
color: errorSurface.bg,
|
|
534
|
+
}}
|
|
535
|
+
>
|
|
536
|
+
<RefreshCw size={iconSize} strokeWidth={2} aria-hidden />
|
|
537
|
+
Reload
|
|
538
|
+
</button>
|
|
539
|
+
<button
|
|
540
|
+
type="button"
|
|
541
|
+
onClick={reset}
|
|
542
|
+
style={{
|
|
543
|
+
...btnRow,
|
|
544
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
545
|
+
background: "transparent",
|
|
546
|
+
color: errorSurface.text,
|
|
547
|
+
}}
|
|
548
|
+
>
|
|
549
|
+
<RotateCcw size={iconSize} strokeWidth={2} aria-hidden />
|
|
550
|
+
Try again
|
|
551
|
+
</button>
|
|
552
|
+
<button
|
|
553
|
+
type="button"
|
|
554
|
+
onClick={() => {
|
|
555
|
+
void handleCopy();
|
|
556
|
+
}}
|
|
557
|
+
style={{
|
|
558
|
+
...btnRow,
|
|
559
|
+
border: `1px solid ${errorSurface.panelBorder}`,
|
|
560
|
+
background: "transparent",
|
|
561
|
+
color: errorSurface.muted,
|
|
562
|
+
}}
|
|
563
|
+
>
|
|
564
|
+
{CopyGlyph}
|
|
565
|
+
{copyButtonLabel}
|
|
566
|
+
</button>
|
|
567
|
+
</div>
|
|
568
|
+
|
|
569
|
+
{isEmbedded ? (
|
|
570
|
+
<p
|
|
571
|
+
style={{
|
|
572
|
+
marginTop: "0.85rem",
|
|
573
|
+
marginBottom: 0,
|
|
574
|
+
fontSize: "0.6875rem",
|
|
575
|
+
color: errorSurface.dim,
|
|
576
|
+
lineHeight: 1.4,
|
|
577
|
+
fontFamily: mono,
|
|
578
|
+
}}
|
|
579
|
+
>
|
|
580
|
+
Embedded: if reload loops, exit and relaunch from the Arcade shell.
|
|
581
|
+
</p>
|
|
582
|
+
) : null}
|
|
583
|
+
</div>
|
|
584
|
+
</div>
|
|
585
|
+
);
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
export class AirJamErrorBoundary extends Component<
|
|
589
|
+
AirJamErrorBoundaryProps,
|
|
590
|
+
AirJamErrorBoundaryState
|
|
591
|
+
> {
|
|
592
|
+
public state: AirJamErrorBoundaryState = {
|
|
593
|
+
error: null,
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
static getDerivedStateFromError(error: unknown): AirJamErrorBoundaryState {
|
|
597
|
+
return {
|
|
598
|
+
error: toError(error),
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
|
|
603
|
+
const { role, roomId, appId, onError } = this.props;
|
|
604
|
+
const details = {
|
|
605
|
+
role,
|
|
606
|
+
roomId,
|
|
607
|
+
appId,
|
|
608
|
+
name: error.name,
|
|
609
|
+
message: error.message,
|
|
610
|
+
stack: error.stack,
|
|
611
|
+
componentStack: errorInfo.componentStack,
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
emitAirJamDiagnostic({
|
|
615
|
+
code: "AJ_RUNTIME_RENDER_CRASH",
|
|
616
|
+
severity: "error",
|
|
617
|
+
message: `[AirJam] ${role} runtime crashed during render.`,
|
|
618
|
+
details,
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
emitAirJamDevRuntimeEvent({
|
|
622
|
+
event: AIRJAM_DEV_LOG_EVENTS.browser.runtime,
|
|
623
|
+
level: "error",
|
|
624
|
+
message: `AirJam ${role} runtime crashed during render`,
|
|
625
|
+
role,
|
|
626
|
+
roomId,
|
|
627
|
+
code: "AJ_RUNTIME_RENDER_CRASH",
|
|
628
|
+
data: details,
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
onError?.(error, errorInfo, {
|
|
632
|
+
role,
|
|
633
|
+
roomId,
|
|
634
|
+
appId,
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
private handleReset = (): void => {
|
|
639
|
+
this.setState({ error: null });
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
private handleReload = (): void => {
|
|
643
|
+
if (typeof window !== "undefined") {
|
|
644
|
+
window.location.reload();
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
render(): JSX.Element {
|
|
649
|
+
const { error } = this.state;
|
|
650
|
+
const { children, role, roomId, appId, renderFallback } = this.props;
|
|
651
|
+
|
|
652
|
+
if (!error) {
|
|
653
|
+
return <>{children}</>;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
const fallbackProps: AirJamErrorFallbackRenderProps = {
|
|
657
|
+
role,
|
|
658
|
+
roomId,
|
|
659
|
+
appId,
|
|
660
|
+
error,
|
|
661
|
+
reset: this.handleReset,
|
|
662
|
+
reload: this.handleReload,
|
|
663
|
+
isEmbedded: isEmbeddedRuntime(),
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
if (renderFallback) {
|
|
667
|
+
return renderFallback(fallbackProps);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
return <DefaultFallback {...fallbackProps} />;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ArcadeSurfaceRuntimeIdentity } from "./arcade-surface-identity";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true when the iframe surface identity does not match the parent's active surface.
|
|
5
|
+
*/
|
|
6
|
+
export const isArcadeSurfaceMismatch = (
|
|
7
|
+
active: ArcadeSurfaceRuntimeIdentity,
|
|
8
|
+
request: ArcadeSurfaceRuntimeIdentity,
|
|
9
|
+
): boolean => {
|
|
10
|
+
return (
|
|
11
|
+
request.epoch !== active.epoch ||
|
|
12
|
+
request.kind !== active.kind ||
|
|
13
|
+
request.gameId !== active.gameId
|
|
14
|
+
);
|
|
15
|
+
};
|