@air-jam/sdk 0.1.4 → 0.9.0
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 +488 -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 +13 -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 +363 -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 +28 -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 +1565 -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 +122 -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-2432OL7L.js +193 -0
- package/dist/chunk-2432OL7L.js.map +1 -0
- package/dist/chunk-2J65FXEP.js +41 -0
- package/dist/chunk-2J65FXEP.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-BE6Z4SIT.js +65 -0
- package/dist/chunk-BE6Z4SIT.js.map +1 -0
- package/dist/chunk-CQUG24WX.js +249 -0
- package/dist/chunk-CQUG24WX.js.map +1 -0
- package/dist/chunk-D3X4MN4U.js +288 -0
- package/dist/chunk-D3X4MN4U.js.map +1 -0
- package/dist/chunk-EVZJA6RN.js +140 -0
- package/dist/chunk-EVZJA6RN.js.map +1 -0
- package/dist/chunk-HFWRZVZ3.js +1438 -0
- package/dist/chunk-HFWRZVZ3.js.map +1 -0
- package/dist/chunk-IKKDONQL.js +1 -0
- package/dist/chunk-IKKDONQL.js.map +1 -0
- package/dist/chunk-JTF47B56.js +1 -0
- package/dist/chunk-JTF47B56.js.map +1 -0
- package/dist/chunk-LIXPF4P6.js +22 -0
- package/dist/chunk-LIXPF4P6.js.map +1 -0
- package/dist/chunk-MKBASO6X.js +216 -0
- package/dist/chunk-MKBASO6X.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-NU5W6VAV.js +126 -0
- package/dist/chunk-NU5W6VAV.js.map +1 -0
- package/dist/chunk-TGRTEWYV.js +195 -0
- package/dist/chunk-TGRTEWYV.js.map +1 -0
- package/dist/chunk-VDRNNGHX.js +184 -0
- package/dist/chunk-VDRNNGHX.js.map +1 -0
- package/dist/chunk-VN5LDWVN.js +32 -0
- package/dist/chunk-VN5LDWVN.js.map +1 -0
- package/dist/chunk-W2VK36RO.js +11 -0
- package/dist/chunk-W2VK36RO.js.map +1 -0
- package/dist/chunk-X24K52DG.js +12 -0
- package/dist/chunk-X24K52DG.js.map +1 -0
- package/dist/chunk-XLUWV45V.js +25 -0
- package/dist/chunk-XLUWV45V.js.map +1 -0
- package/dist/chunk-Y4RAPKKB.js +238 -0
- package/dist/chunk-Y4RAPKKB.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 +8507 -3523
- 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 +4890 -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 +2609 -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/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 +2827 -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 +1718 -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 +149 -11
- 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/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
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
2
|
-
import { X } from "lucide-react";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
|
|
5
|
-
import { cn } from "../../utils/cn";
|
|
6
|
-
|
|
7
|
-
const Dialog = DialogPrimitive.Root;
|
|
8
|
-
|
|
9
|
-
const DialogTrigger = DialogPrimitive.Trigger;
|
|
10
|
-
|
|
11
|
-
const DialogPortal = DialogPrimitive.Portal;
|
|
12
|
-
|
|
13
|
-
const DialogClose = DialogPrimitive.Close;
|
|
14
|
-
|
|
15
|
-
const DialogOverlay = React.forwardRef<
|
|
16
|
-
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
17
|
-
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
|
18
|
-
>(({ className, ...props }, ref) => (
|
|
19
|
-
<DialogPrimitive.Overlay
|
|
20
|
-
ref={ref}
|
|
21
|
-
className={cn(
|
|
22
|
-
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-99999 bg-black/80",
|
|
23
|
-
className,
|
|
24
|
-
)}
|
|
25
|
-
{...props}
|
|
26
|
-
/>
|
|
27
|
-
));
|
|
28
|
-
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|
29
|
-
|
|
30
|
-
const DialogContent = React.forwardRef<
|
|
31
|
-
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
32
|
-
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
|
33
|
-
>(({ className, children, ...props }, ref) => (
|
|
34
|
-
<DialogPortal>
|
|
35
|
-
<div className="dark">
|
|
36
|
-
<DialogOverlay />
|
|
37
|
-
<DialogPrimitive.Content
|
|
38
|
-
ref={ref}
|
|
39
|
-
className={cn(
|
|
40
|
-
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] fixed top-[50%] left-[50%] z-99999 w-full translate-x-[-50%] translate-y-[-50%] gap-4 rounded-xl border border-white p-6 shadow-lg duration-200",
|
|
41
|
-
className,
|
|
42
|
-
)}
|
|
43
|
-
{...props}
|
|
44
|
-
>
|
|
45
|
-
{children}
|
|
46
|
-
<DialogPrimitive.Close className="text-foreground ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none">
|
|
47
|
-
<X className="h-4 w-4" />
|
|
48
|
-
<span className="sr-only">Close</span>
|
|
49
|
-
</DialogPrimitive.Close>
|
|
50
|
-
</DialogPrimitive.Content>
|
|
51
|
-
</div>
|
|
52
|
-
</DialogPortal>
|
|
53
|
-
));
|
|
54
|
-
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
|
55
|
-
|
|
56
|
-
const DialogHeader = ({
|
|
57
|
-
className,
|
|
58
|
-
...props
|
|
59
|
-
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
60
|
-
<div
|
|
61
|
-
className={cn(
|
|
62
|
-
"flex flex-col space-y-1.5 text-center sm:text-left",
|
|
63
|
-
className,
|
|
64
|
-
)}
|
|
65
|
-
{...props}
|
|
66
|
-
/>
|
|
67
|
-
);
|
|
68
|
-
DialogHeader.displayName = "DialogHeader";
|
|
69
|
-
|
|
70
|
-
const DialogFooter = ({
|
|
71
|
-
className,
|
|
72
|
-
...props
|
|
73
|
-
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
74
|
-
<div
|
|
75
|
-
className={cn(
|
|
76
|
-
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
|
|
77
|
-
className,
|
|
78
|
-
)}
|
|
79
|
-
{...props}
|
|
80
|
-
/>
|
|
81
|
-
);
|
|
82
|
-
DialogFooter.displayName = "DialogFooter";
|
|
83
|
-
|
|
84
|
-
const DialogTitle = React.forwardRef<
|
|
85
|
-
React.ElementRef<typeof DialogPrimitive.Title>,
|
|
86
|
-
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
|
87
|
-
>(({ className, ...props }, ref) => (
|
|
88
|
-
<DialogPrimitive.Title
|
|
89
|
-
ref={ref}
|
|
90
|
-
className={cn(
|
|
91
|
-
"text-lg leading-none font-semibold tracking-tight",
|
|
92
|
-
className,
|
|
93
|
-
)}
|
|
94
|
-
{...props}
|
|
95
|
-
/>
|
|
96
|
-
));
|
|
97
|
-
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
|
98
|
-
|
|
99
|
-
const DialogDescription = React.forwardRef<
|
|
100
|
-
React.ElementRef<typeof DialogPrimitive.Description>,
|
|
101
|
-
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
|
102
|
-
>(({ className, ...props }, ref) => (
|
|
103
|
-
<DialogPrimitive.Description
|
|
104
|
-
ref={ref}
|
|
105
|
-
className={cn("text-muted-foreground text-sm", className)}
|
|
106
|
-
{...props}
|
|
107
|
-
/>
|
|
108
|
-
));
|
|
109
|
-
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
|
110
|
-
|
|
111
|
-
export {
|
|
112
|
-
Dialog,
|
|
113
|
-
DialogClose,
|
|
114
|
-
DialogContent,
|
|
115
|
-
DialogDescription,
|
|
116
|
-
DialogFooter,
|
|
117
|
-
DialogHeader,
|
|
118
|
-
DialogOverlay,
|
|
119
|
-
DialogPortal,
|
|
120
|
-
DialogTitle,
|
|
121
|
-
DialogTrigger,
|
|
122
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
|
|
4
|
-
import { cn } from "../../utils/cn";
|
|
5
|
-
|
|
6
|
-
function Tabs({
|
|
7
|
-
className,
|
|
8
|
-
...props
|
|
9
|
-
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
|
|
10
|
-
return (
|
|
11
|
-
<TabsPrimitive.Root
|
|
12
|
-
data-slot="tabs"
|
|
13
|
-
className={cn("flex flex-col gap-2", className)}
|
|
14
|
-
{...props}
|
|
15
|
-
/>
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function TabsList({
|
|
20
|
-
className,
|
|
21
|
-
...props
|
|
22
|
-
}: React.ComponentProps<typeof TabsPrimitive.List>) {
|
|
23
|
-
return (
|
|
24
|
-
<TabsPrimitive.List
|
|
25
|
-
data-slot="tabs-list"
|
|
26
|
-
className={cn(
|
|
27
|
-
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
|
28
|
-
className,
|
|
29
|
-
)}
|
|
30
|
-
{...props}
|
|
31
|
-
/>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function TabsTrigger({
|
|
36
|
-
className,
|
|
37
|
-
...props
|
|
38
|
-
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
|
|
39
|
-
return (
|
|
40
|
-
<TabsPrimitive.Trigger
|
|
41
|
-
data-slot="tabs-trigger"
|
|
42
|
-
className={cn(
|
|
43
|
-
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
44
|
-
className,
|
|
45
|
-
)}
|
|
46
|
-
{...props}
|
|
47
|
-
/>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function TabsContent({
|
|
52
|
-
className,
|
|
53
|
-
...props
|
|
54
|
-
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
|
|
55
|
-
return (
|
|
56
|
-
<TabsPrimitive.Content
|
|
57
|
-
data-slot="tabs-content"
|
|
58
|
-
className={cn("flex-1 outline-none", className)}
|
|
59
|
-
{...props}
|
|
60
|
-
/>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { Tabs, TabsContent, TabsList, TabsTrigger };
|
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { useStore } from "zustand";
|
|
3
|
-
import { useShallow } from "zustand/react/shallow";
|
|
4
|
-
import { useAirJamContext } from "../context/air-jam-context";
|
|
5
|
-
import type { AirJamSocket } from "../context/socket-manager";
|
|
6
|
-
import type {
|
|
7
|
-
ConnectionStatus,
|
|
8
|
-
ControllerInputPayload,
|
|
9
|
-
ControllerStateMessage,
|
|
10
|
-
GameState,
|
|
11
|
-
PlayerProfile,
|
|
12
|
-
RoomCode,
|
|
13
|
-
SignalPayload,
|
|
14
|
-
} from "../protocol";
|
|
15
|
-
import {
|
|
16
|
-
controllerInputSchema,
|
|
17
|
-
controllerJoinSchema,
|
|
18
|
-
controllerSystemSchema,
|
|
19
|
-
roomCodeSchema,
|
|
20
|
-
} from "../protocol";
|
|
21
|
-
import { generateControllerId } from "../utils/ids";
|
|
22
|
-
import { detectRunMode } from "../utils/mode";
|
|
23
|
-
|
|
24
|
-
interface AirJamShellOptions {
|
|
25
|
-
/** Room ID to join */
|
|
26
|
-
roomId?: string;
|
|
27
|
-
/** Player nickname */
|
|
28
|
-
nickname?: string;
|
|
29
|
-
/** Controller ID (auto-generated if not provided) */
|
|
30
|
-
controllerId?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface AirJamShellApi {
|
|
34
|
-
roomId: RoomCode | null;
|
|
35
|
-
controllerId: string | null;
|
|
36
|
-
connectionStatus: ConnectionStatus;
|
|
37
|
-
lastError?: string;
|
|
38
|
-
activeUrl: string | null;
|
|
39
|
-
players: PlayerProfile[];
|
|
40
|
-
gameState: GameState;
|
|
41
|
-
sendInput: (input: ControllerInputPayload) => boolean;
|
|
42
|
-
sendSystemCommand: (command: "exit" | "ready" | "toggle_pause") => void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const getRoomFromLocation = (): string | null => {
|
|
46
|
-
if (typeof window === "undefined") {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const params = new URLSearchParams(window.location.search);
|
|
50
|
-
const code = params.get("room");
|
|
51
|
-
return code ? code.toUpperCase() : null;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// Throttling variables for logging
|
|
55
|
-
let lastSendInputLogTime = 0;
|
|
56
|
-
let lastSendInputFailLogTime = 0;
|
|
57
|
-
|
|
58
|
-
export const useAirJamShell = (
|
|
59
|
-
options: AirJamShellOptions = {},
|
|
60
|
-
): AirJamShellApi => {
|
|
61
|
-
// Get context
|
|
62
|
-
const { store, getSocket } = useAirJamContext();
|
|
63
|
-
|
|
64
|
-
const nicknameRef = useRef(options.nickname ?? "Arcade Shell");
|
|
65
|
-
|
|
66
|
-
// Parse room ID
|
|
67
|
-
const parsedRoomId = useMemo<RoomCode | null>(() => {
|
|
68
|
-
const code = options.roomId ?? getRoomFromLocation();
|
|
69
|
-
if (!code) return null;
|
|
70
|
-
try {
|
|
71
|
-
return roomCodeSchema.parse(code.toUpperCase());
|
|
72
|
-
} catch {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
}, [options.roomId]);
|
|
76
|
-
|
|
77
|
-
// Generate or use provided controller ID
|
|
78
|
-
const controllerId = useMemo<string>(() => {
|
|
79
|
-
if (options.controllerId) return options.controllerId;
|
|
80
|
-
if (typeof window !== "undefined") {
|
|
81
|
-
const params = new URLSearchParams(window.location.search);
|
|
82
|
-
const urlControllerId = params.get("controllerId");
|
|
83
|
-
if (urlControllerId) return urlControllerId;
|
|
84
|
-
}
|
|
85
|
-
return generateControllerId();
|
|
86
|
-
}, [options.controllerId]);
|
|
87
|
-
|
|
88
|
-
const [activeUrl, setActiveUrl] = useState<string | null>(null);
|
|
89
|
-
|
|
90
|
-
// Subscribe to store state
|
|
91
|
-
const connectionState = useStore(
|
|
92
|
-
store,
|
|
93
|
-
useShallow((state) => ({
|
|
94
|
-
connectionStatus: state.connectionStatus,
|
|
95
|
-
lastError: state.lastError,
|
|
96
|
-
controllerId: state.controllerId,
|
|
97
|
-
players: state.players,
|
|
98
|
-
gameState: state.gameState,
|
|
99
|
-
})),
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
// Get socket from context
|
|
103
|
-
const socket: AirJamSocket | null = useMemo(
|
|
104
|
-
() => (parsedRoomId ? getSocket("controller") : null),
|
|
105
|
-
[parsedRoomId, getSocket],
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
// Automatically listen for haptic signals
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
if (!socket) return;
|
|
111
|
-
|
|
112
|
-
const handleSignal = (signal: SignalPayload) => {
|
|
113
|
-
if (signal.type !== "HAPTIC") return;
|
|
114
|
-
|
|
115
|
-
// Browser compatibility check
|
|
116
|
-
if (typeof navigator === "undefined" || !navigator.vibrate) return;
|
|
117
|
-
|
|
118
|
-
// TypeScript now knows payload is HapticSignalPayload
|
|
119
|
-
const payload = signal.payload;
|
|
120
|
-
|
|
121
|
-
switch (payload.pattern) {
|
|
122
|
-
case "light":
|
|
123
|
-
navigator.vibrate(10);
|
|
124
|
-
break;
|
|
125
|
-
case "medium":
|
|
126
|
-
navigator.vibrate(30);
|
|
127
|
-
break;
|
|
128
|
-
case "heavy":
|
|
129
|
-
navigator.vibrate([50, 20, 50]); // Pulse
|
|
130
|
-
break;
|
|
131
|
-
case "success":
|
|
132
|
-
navigator.vibrate([10, 30, 10]);
|
|
133
|
-
break;
|
|
134
|
-
case "failure":
|
|
135
|
-
navigator.vibrate([50, 50, 50, 50]);
|
|
136
|
-
break;
|
|
137
|
-
case "custom":
|
|
138
|
-
if (Array.isArray(payload.sequence)) {
|
|
139
|
-
navigator.vibrate(payload.sequence);
|
|
140
|
-
} else if (typeof payload.sequence === "number") {
|
|
141
|
-
navigator.vibrate(payload.sequence);
|
|
142
|
-
}
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
socket.on("server:signal", handleSignal);
|
|
148
|
-
return () => {
|
|
149
|
-
socket.off("server:signal", handleSignal);
|
|
150
|
-
};
|
|
151
|
-
}, [socket]);
|
|
152
|
-
|
|
153
|
-
// Main connection effect
|
|
154
|
-
useEffect(() => {
|
|
155
|
-
const storeState = store.getState();
|
|
156
|
-
storeState.setMode(detectRunMode());
|
|
157
|
-
storeState.setRole("controller");
|
|
158
|
-
storeState.setRoomId(parsedRoomId);
|
|
159
|
-
storeState.setStatus(parsedRoomId ? "connecting" : "idle");
|
|
160
|
-
storeState.setError(undefined);
|
|
161
|
-
|
|
162
|
-
if (!parsedRoomId || !socket || !controllerId) {
|
|
163
|
-
storeState.setStatus("idle");
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
storeState.setControllerId(controllerId);
|
|
168
|
-
|
|
169
|
-
const handleConnect = (): void => {
|
|
170
|
-
store.getState().setStatus("connected");
|
|
171
|
-
|
|
172
|
-
const payload = controllerJoinSchema.parse({
|
|
173
|
-
roomId: parsedRoomId,
|
|
174
|
-
controllerId,
|
|
175
|
-
nickname: nicknameRef.current || undefined,
|
|
176
|
-
});
|
|
177
|
-
socket.emit("controller:join", payload, (ack) => {
|
|
178
|
-
const storeState = store.getState();
|
|
179
|
-
if (!ack.ok) {
|
|
180
|
-
storeState.setError(ack.message ?? "Unable to join room");
|
|
181
|
-
storeState.setStatus("disconnected");
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (ack.controllerId) {
|
|
185
|
-
storeState.setControllerId(ack.controllerId);
|
|
186
|
-
}
|
|
187
|
-
storeState.setStatus("connected");
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const handleDisconnect = (): void => {
|
|
192
|
-
store.getState().setStatus("disconnected");
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const handleLoadUi = (payload: { url: string }): void => {
|
|
196
|
-
setActiveUrl(payload.url);
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const handleUnloadUi = (): void => {
|
|
200
|
-
setActiveUrl(null);
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
const handleWelcome = (payload: {
|
|
204
|
-
controllerId: string;
|
|
205
|
-
roomId: RoomCode;
|
|
206
|
-
player?: PlayerProfile;
|
|
207
|
-
}): void => {
|
|
208
|
-
const storeState = store.getState();
|
|
209
|
-
const storeRoomId = storeState.roomId;
|
|
210
|
-
if (
|
|
211
|
-
storeRoomId &&
|
|
212
|
-
payload.roomId.toUpperCase() !== storeRoomId.toUpperCase()
|
|
213
|
-
) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (!storeRoomId && payload.roomId) {
|
|
217
|
-
storeState.setRoomId(payload.roomId);
|
|
218
|
-
}
|
|
219
|
-
if (payload.player) {
|
|
220
|
-
storeState.upsertPlayer(payload.player);
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
const handleState = (payload: ControllerStateMessage): void => {
|
|
225
|
-
if (payload.roomId !== parsedRoomId) return;
|
|
226
|
-
|
|
227
|
-
const storeState = store.getState();
|
|
228
|
-
if (payload.state.gameState) {
|
|
229
|
-
storeState.setGameState(payload.state.gameState);
|
|
230
|
-
}
|
|
231
|
-
if (payload.state.message !== undefined) {
|
|
232
|
-
storeState.setStateMessage(payload.state.message);
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
const handleError = (payload: { message: string }): void => {
|
|
237
|
-
store.getState().setError(payload.message);
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
// Bridge logic for iframe communication
|
|
241
|
-
const handleMessage = (event: MessageEvent) => {
|
|
242
|
-
const storeState = store.getState();
|
|
243
|
-
const data = event.data;
|
|
244
|
-
if (data?.type === "AIRJAM_INPUT") {
|
|
245
|
-
const input = data.payload as ControllerInputPayload;
|
|
246
|
-
const payload = controllerInputSchema.safeParse({
|
|
247
|
-
roomId: parsedRoomId,
|
|
248
|
-
controllerId: storeState.controllerId,
|
|
249
|
-
input,
|
|
250
|
-
});
|
|
251
|
-
if (payload.success) {
|
|
252
|
-
socket.emit("controller:input", payload.data);
|
|
253
|
-
}
|
|
254
|
-
} else if (data?.type === "AIRJAM_READY") {
|
|
255
|
-
// Child is ready
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
socket.on("connect", handleConnect);
|
|
260
|
-
socket.on("disconnect", handleDisconnect);
|
|
261
|
-
socket.on("server:welcome", handleWelcome);
|
|
262
|
-
socket.on("server:state", handleState);
|
|
263
|
-
|
|
264
|
-
socket.on("client:loadUi", handleLoadUi);
|
|
265
|
-
socket.on("client:unloadUi", handleUnloadUi);
|
|
266
|
-
socket.on("server:error", handleError);
|
|
267
|
-
|
|
268
|
-
window.addEventListener("message", handleMessage);
|
|
269
|
-
|
|
270
|
-
// Connect the socket
|
|
271
|
-
socket.connect();
|
|
272
|
-
|
|
273
|
-
return () => {
|
|
274
|
-
socket.off("connect", handleConnect);
|
|
275
|
-
socket.off("disconnect", handleDisconnect);
|
|
276
|
-
socket.off("server:welcome", handleWelcome);
|
|
277
|
-
socket.off("server:state", handleState);
|
|
278
|
-
socket.off("client:loadUi", handleLoadUi);
|
|
279
|
-
socket.off("client:unloadUi", handleUnloadUi);
|
|
280
|
-
socket.off("server:error", handleError);
|
|
281
|
-
window.removeEventListener("message", handleMessage);
|
|
282
|
-
};
|
|
283
|
-
}, [parsedRoomId, socket, controllerId, store]);
|
|
284
|
-
|
|
285
|
-
const sendInput = useCallback(
|
|
286
|
-
(input: ControllerInputPayload): boolean => {
|
|
287
|
-
const storeState = store.getState();
|
|
288
|
-
const now = Date.now();
|
|
289
|
-
|
|
290
|
-
// Only log when there's actual user input (not just the loop sending zeros)
|
|
291
|
-
const hasActiveInput =
|
|
292
|
-
input.action === true ||
|
|
293
|
-
(typeof input.vector === "object" &&
|
|
294
|
-
input.vector !== null &&
|
|
295
|
-
(Math.abs((input.vector as { x?: number; y?: number }).x ?? 0) >
|
|
296
|
-
0.01 ||
|
|
297
|
-
Math.abs((input.vector as { x?: number; y?: number }).y ?? 0) >
|
|
298
|
-
0.01));
|
|
299
|
-
|
|
300
|
-
// Throttled logging - only log active input, once per second max
|
|
301
|
-
if (
|
|
302
|
-
hasActiveInput &&
|
|
303
|
-
(!lastSendInputLogTime || now - lastSendInputLogTime > 1000)
|
|
304
|
-
) {
|
|
305
|
-
lastSendInputLogTime = now;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (!parsedRoomId || !storeState.controllerId || !socket) {
|
|
309
|
-
if (
|
|
310
|
-
!lastSendInputFailLogTime ||
|
|
311
|
-
now - lastSendInputFailLogTime > 1000
|
|
312
|
-
) {
|
|
313
|
-
lastSendInputFailLogTime = now;
|
|
314
|
-
}
|
|
315
|
-
storeState.setError("Not connected to a room");
|
|
316
|
-
return false;
|
|
317
|
-
}
|
|
318
|
-
if (!socket.connected) {
|
|
319
|
-
if (
|
|
320
|
-
!lastSendInputFailLogTime ||
|
|
321
|
-
now - lastSendInputFailLogTime > 1000
|
|
322
|
-
) {
|
|
323
|
-
lastSendInputFailLogTime = now;
|
|
324
|
-
}
|
|
325
|
-
return false;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (typeof input !== "object" || input === null || Array.isArray(input)) {
|
|
329
|
-
storeState.setError("Input must be an object");
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const payload = controllerInputSchema.safeParse({
|
|
334
|
-
roomId: parsedRoomId,
|
|
335
|
-
controllerId: storeState.controllerId,
|
|
336
|
-
input,
|
|
337
|
-
});
|
|
338
|
-
if (!payload.success) {
|
|
339
|
-
storeState.setError(payload.error.message);
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
socket.emit("controller:input", payload.data);
|
|
344
|
-
return true;
|
|
345
|
-
},
|
|
346
|
-
[parsedRoomId, socket, store],
|
|
347
|
-
);
|
|
348
|
-
|
|
349
|
-
const sendSystemCommand = useCallback(
|
|
350
|
-
(command: "exit" | "ready" | "toggle_pause") => {
|
|
351
|
-
const storeState = store.getState();
|
|
352
|
-
|
|
353
|
-
if (!parsedRoomId || !storeState.controllerId || !socket) return;
|
|
354
|
-
if (!socket.connected) return;
|
|
355
|
-
|
|
356
|
-
const payload = controllerSystemSchema.safeParse({
|
|
357
|
-
roomId: parsedRoomId,
|
|
358
|
-
command,
|
|
359
|
-
});
|
|
360
|
-
|
|
361
|
-
if (payload.success) {
|
|
362
|
-
socket.emit("controller:system", payload.data);
|
|
363
|
-
}
|
|
364
|
-
},
|
|
365
|
-
[parsedRoomId, socket, store],
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
return {
|
|
369
|
-
roomId: parsedRoomId,
|
|
370
|
-
controllerId: connectionState.controllerId,
|
|
371
|
-
connectionStatus: connectionState.connectionStatus,
|
|
372
|
-
lastError: connectionState.lastError,
|
|
373
|
-
activeUrl,
|
|
374
|
-
players: connectionState.players,
|
|
375
|
-
gameState: connectionState.gameState,
|
|
376
|
-
sendInput,
|
|
377
|
-
sendSystemCommand,
|
|
378
|
-
};
|
|
379
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
DocumentWithFullscreen,
|
|
4
|
-
ElementWithFullscreen,
|
|
5
|
-
} from "../types/browser";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Hook to manage fullscreen state and transitions
|
|
9
|
-
* Supports standard and vendor-prefixed fullscreen APIs
|
|
10
|
-
*/
|
|
11
|
-
export const useFullscreen = () => {
|
|
12
|
-
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
13
|
-
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
const handleFullscreenChange = () => {
|
|
16
|
-
const doc = document as DocumentWithFullscreen;
|
|
17
|
-
setIsFullscreen(
|
|
18
|
-
!!(
|
|
19
|
-
document.fullscreenElement ||
|
|
20
|
-
doc.webkitFullscreenElement ||
|
|
21
|
-
doc.mozFullScreenElement ||
|
|
22
|
-
doc.msFullscreenElement
|
|
23
|
-
),
|
|
24
|
-
);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
document.addEventListener("fullscreenchange", handleFullscreenChange);
|
|
28
|
-
document.addEventListener("webkitfullscreenchange", handleFullscreenChange);
|
|
29
|
-
document.addEventListener("mozfullscreenchange", handleFullscreenChange);
|
|
30
|
-
document.addEventListener("msfullscreenchange", handleFullscreenChange);
|
|
31
|
-
|
|
32
|
-
return () => {
|
|
33
|
-
document.removeEventListener("fullscreenchange", handleFullscreenChange);
|
|
34
|
-
document.removeEventListener(
|
|
35
|
-
"webkitfullscreenchange",
|
|
36
|
-
handleFullscreenChange,
|
|
37
|
-
);
|
|
38
|
-
document.removeEventListener(
|
|
39
|
-
"mozfullscreenchange",
|
|
40
|
-
handleFullscreenChange,
|
|
41
|
-
);
|
|
42
|
-
document.removeEventListener(
|
|
43
|
-
"msfullscreenchange",
|
|
44
|
-
handleFullscreenChange,
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
}, []);
|
|
48
|
-
|
|
49
|
-
const exitFullscreen = useCallback(async () => {
|
|
50
|
-
try {
|
|
51
|
-
const doc = document as DocumentWithFullscreen;
|
|
52
|
-
if (
|
|
53
|
-
document.fullscreenElement ||
|
|
54
|
-
doc.webkitFullscreenElement ||
|
|
55
|
-
doc.mozFullScreenElement ||
|
|
56
|
-
doc.msFullscreenElement
|
|
57
|
-
) {
|
|
58
|
-
if (document.exitFullscreen) {
|
|
59
|
-
await document.exitFullscreen();
|
|
60
|
-
} else if (doc.webkitExitFullscreen) {
|
|
61
|
-
await doc.webkitExitFullscreen();
|
|
62
|
-
} else if (doc.mozCancelFullScreen) {
|
|
63
|
-
await doc.mozCancelFullScreen();
|
|
64
|
-
} else if (doc.msExitFullscreen) {
|
|
65
|
-
await doc.msExitFullscreen();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.error("Error exiting fullscreen:", error);
|
|
70
|
-
}
|
|
71
|
-
}, []);
|
|
72
|
-
|
|
73
|
-
const enterFullscreen = useCallback(async (element?: HTMLElement) => {
|
|
74
|
-
try {
|
|
75
|
-
const elem = (element ||
|
|
76
|
-
document.documentElement) as ElementWithFullscreen;
|
|
77
|
-
if (elem.requestFullscreen) {
|
|
78
|
-
await elem.requestFullscreen();
|
|
79
|
-
} else if (elem.webkitRequestFullscreen) {
|
|
80
|
-
await elem.webkitRequestFullscreen();
|
|
81
|
-
} else if (elem.mozRequestFullScreen) {
|
|
82
|
-
await elem.mozRequestFullScreen();
|
|
83
|
-
} else if (elem.msRequestFullscreen) {
|
|
84
|
-
await elem.msRequestFullscreen();
|
|
85
|
-
}
|
|
86
|
-
} catch (error) {
|
|
87
|
-
console.error("Error entering fullscreen:", error);
|
|
88
|
-
}
|
|
89
|
-
}, []);
|
|
90
|
-
|
|
91
|
-
const toggleFullscreen = useCallback(
|
|
92
|
-
async (element?: HTMLElement) => {
|
|
93
|
-
if (isFullscreen) {
|
|
94
|
-
await exitFullscreen();
|
|
95
|
-
} else {
|
|
96
|
-
await enterFullscreen(element);
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
[isFullscreen, exitFullscreen, enterFullscreen],
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
isFullscreen,
|
|
104
|
-
enterFullscreen,
|
|
105
|
-
exitFullscreen,
|
|
106
|
-
toggleFullscreen,
|
|
107
|
-
};
|
|
108
|
-
};
|