@displayxr/inline3d 1.29.0 → 1.31.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/CHANGELOG.md +187 -0
- package/README.md +9 -5
- package/call.d.ts +318 -238
- package/camera.d.ts +257 -0
- package/dist/call.js +17 -12
- package/index.d.ts +56 -0
- package/js/call/capture.js +4 -212
- package/js/call/disparity.js +4 -432
- package/js/call/element.js +14 -10
- package/js/call/options.js +132 -0
- package/js/call/signaling.js +66 -9
- package/js/call/ui.js +106 -9
- package/js/call/wire.js +8 -153
- package/js/camera/capture.js +220 -0
- package/js/camera/converge.js +82 -0
- package/js/camera/disparity.js +432 -0
- package/js/camera/geometry.js +80 -0
- package/js/camera/metadata.js +398 -0
- package/js/inline3d-call.js +435 -320
- package/js/inline3d-camera.js +678 -0
- package/js/inline3d-model-playcanvas.js +1 -0
- package/js/inline3d-model.js +1 -0
- package/js/inline3d-splat-deferred.js +153 -0
- package/js/inline3d-splat-pc-entry.js +45 -0
- package/js/inline3d-splat-playcanvas.js +14 -3
- package/js/inline3d-splat.js +3 -145
- package/js/inline3d-viewer-ease.js +360 -0
- package/js/inline3d-viewer.js +15 -4
- package/js/inline3d.js +13 -0
- package/model.d.ts +8 -1
- package/package.json +22 -2
- package/splat-playcanvas.d.ts +4 -0
- package/splat.d.ts +8 -1
- package/viewer.d.ts +9 -0
package/js/call/signaling.js
CHANGED
|
@@ -53,6 +53,18 @@ export async function roomKey(room) {
|
|
|
53
53
|
*/
|
|
54
54
|
export const DXR_SIGNAL_DEFAULT = 'wss://dxr-signal.displayxr.workers.dev';
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Every host the hosted server answers on. The SAME Worker serves all of them (rooms are shared),
|
|
58
|
+
* so the adapter fails over between them when one cannot be reached: the first entry is tried
|
|
59
|
+
* first. `signal.displayxr.org` is the target of the domain move (RFC 0003 §5g); the workers.dev
|
|
60
|
+
* host stays an alias through the transition. Only applies to the hosted default — a self-hosted
|
|
61
|
+
* URL is tried as given (pass `aliases` to add your own fallbacks).
|
|
62
|
+
*/
|
|
63
|
+
export const DXR_SIGNAL_ALIASES = Object.freeze([DXR_SIGNAL_DEFAULT, 'wss://signal.displayxr.org']);
|
|
64
|
+
|
|
65
|
+
/** Join-time error codes from the server that mean "do not retry with the same inputs". */
|
|
66
|
+
const FATAL_JOIN_CODES = ['bad-room', 'bad-id', 'bad-version', 'bad-key', 'origin-not-allowed', 'blocked'];
|
|
67
|
+
|
|
56
68
|
export function dxrSignaling(url = DXR_SIGNAL_DEFAULT, opts = {}) {
|
|
57
69
|
if (!url || typeof url !== 'string') {
|
|
58
70
|
throw codedError(
|
|
@@ -60,16 +72,21 @@ export function dxrSignaling(url = DXR_SIGNAL_DEFAULT, opts = {}) {
|
|
|
60
72
|
'dxrSignaling(url): url must be a ws:// or wss:// string (omit it for the hosted DisplayXR server)'
|
|
61
73
|
);
|
|
62
74
|
}
|
|
63
|
-
const
|
|
75
|
+
const strip = (u) => String(u).replace(/\/+$/, '');
|
|
76
|
+
const base = strip(url);
|
|
64
77
|
const WS = opts.WebSocket || globalThis.WebSocket;
|
|
65
78
|
const pingMs = opts.pingMs || 20000;
|
|
79
|
+
const extra = Array.isArray(opts.aliases) ? opts.aliases.filter((a) => typeof a === 'string' && a).map(strip) : DXR_SIGNAL_ALIASES.includes(base) ? [...DXR_SIGNAL_ALIASES] : [];
|
|
80
|
+
const bases = [base, ...extra.filter((b) => b !== base)];
|
|
81
|
+
let baseIdx = 0;
|
|
66
82
|
|
|
67
83
|
return {
|
|
68
84
|
name: 'dxr',
|
|
69
85
|
url: base,
|
|
70
86
|
async join(room, hooks) {
|
|
71
87
|
const key = await roomKey(room);
|
|
72
|
-
const
|
|
88
|
+
const query = `k=${key}${typeof opts.key === 'string' && opts.key ? `&key=${encodeURIComponent(opts.key)}` : ''}`;
|
|
89
|
+
const endpointAt = (i) => `${bases[i]}/v1/connect?${query}`;
|
|
73
90
|
let ws = null;
|
|
74
91
|
let left = false;
|
|
75
92
|
let attempt = 0;
|
|
@@ -77,11 +94,15 @@ export function dxrSignaling(url = DXR_SIGNAL_DEFAULT, opts = {}) {
|
|
|
77
94
|
let known = new Set();
|
|
78
95
|
let queue = [];
|
|
79
96
|
|
|
80
|
-
|
|
97
|
+
// One open() tries every alias once (in order from the last one that worked) before it
|
|
98
|
+
// reports `signaling-unreachable`; a host that cannot be reached is skipped, not waited on.
|
|
99
|
+
const open = (isReconnect) => openAt(isReconnect, bases.length);
|
|
100
|
+
const openAt = (isReconnect, triesLeft) =>
|
|
81
101
|
new Promise((resolve, reject) => {
|
|
82
102
|
let settled = false;
|
|
83
103
|
let joined = false;
|
|
84
|
-
|
|
104
|
+
let opened = false;
|
|
105
|
+
const sock = new WS(endpointAt(baseIdx));
|
|
85
106
|
ws = sock;
|
|
86
107
|
const fail = (err) => {
|
|
87
108
|
if (!settled) {
|
|
@@ -95,6 +116,7 @@ export function dxrSignaling(url = DXR_SIGNAL_DEFAULT, opts = {}) {
|
|
|
95
116
|
}
|
|
96
117
|
};
|
|
97
118
|
sock.onopen = () => {
|
|
119
|
+
opened = true;
|
|
98
120
|
sock.send(JSON.stringify({ t: 'join', v: 1, room, id: hooks.id, max: hooks.maxPeers }));
|
|
99
121
|
};
|
|
100
122
|
sock.onmessage = (ev) => {
|
|
@@ -121,17 +143,42 @@ export function dxrSignaling(url = DXR_SIGNAL_DEFAULT, opts = {}) {
|
|
|
121
143
|
} else known = new Set(peers);
|
|
122
144
|
settled = true;
|
|
123
145
|
joined = true;
|
|
124
|
-
resolve({
|
|
146
|
+
resolve({
|
|
147
|
+
id: msg.id,
|
|
148
|
+
peers,
|
|
149
|
+
iceServers: Array.isArray(msg.iceServers) ? msg.iceServers : undefined,
|
|
150
|
+
max: msg.max,
|
|
151
|
+
// Hosted-service fields (RFC 0003 §5): the tier this session was admitted as,
|
|
152
|
+
// its key id, and the TURN decision — `turn.reason === 'cap'` is the SDK's
|
|
153
|
+
// `turn-cap`. A server that predates them sends none; nothing here is required.
|
|
154
|
+
tier: msg.tier === 'key' ? 'key' : 'anon',
|
|
155
|
+
key: typeof msg.key === 'string' ? msg.key : undefined,
|
|
156
|
+
turn: msg.turn && typeof msg.turn === 'object' ? msg.turn : undefined,
|
|
157
|
+
});
|
|
125
158
|
break;
|
|
126
159
|
}
|
|
127
160
|
case 'full':
|
|
128
161
|
left = true;
|
|
129
162
|
fail(codedError('room-full', `this call is full (${msg.max} participants)`));
|
|
130
163
|
break;
|
|
164
|
+
case 'expired': {
|
|
165
|
+
// The room's lifetime is up (hosted limits): no reconnect — the call reports it.
|
|
166
|
+
left = true;
|
|
167
|
+
clearInterval(pingTimer);
|
|
168
|
+
const e = codedError('expired', 'this room has reached its lifetime on the signalling server');
|
|
169
|
+
if (!settled) fail(e);
|
|
170
|
+
else hooks.onDisconnect?.(e);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
131
173
|
case 'error':
|
|
132
|
-
if (!settled &&
|
|
174
|
+
if (!settled && FATAL_JOIN_CODES.includes(msg.code)) {
|
|
133
175
|
left = true;
|
|
134
176
|
fail(codedError(msg.code, msg.message || msg.code));
|
|
177
|
+
} else if (!settled && (msg.code === 'rate-limited' || msg.code === 'quota')) {
|
|
178
|
+
// Refused by a limit, not by the inputs: a reconnect may retry after `retryMs`.
|
|
179
|
+
const e = codedError(msg.code, msg.message || msg.code);
|
|
180
|
+
/** @type {any} */ (e).retryMs = msg.retryMs > 0 ? msg.retryMs : 0;
|
|
181
|
+
fail(e);
|
|
135
182
|
} else if (!settled && msg.code === 'id-taken') {
|
|
136
183
|
// A reconnect raced the server noticing the old socket close: retry shortly.
|
|
137
184
|
fail(codedError('id-taken', 'peer id still held; retrying'));
|
|
@@ -154,7 +201,16 @@ export function dxrSignaling(url = DXR_SIGNAL_DEFAULT, opts = {}) {
|
|
|
154
201
|
break;
|
|
155
202
|
}
|
|
156
203
|
};
|
|
157
|
-
sock.onerror = () =>
|
|
204
|
+
sock.onerror = () => {
|
|
205
|
+
if (!opened && !settled && triesLeft > 1) {
|
|
206
|
+
// This host is unreachable: fail over to the next alias right away.
|
|
207
|
+
settled = true;
|
|
208
|
+
baseIdx = (baseIdx + 1) % bases.length;
|
|
209
|
+
openAt(isReconnect, triesLeft - 1).then(resolve, reject);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
fail(codedError('signaling-unreachable', `cannot reach ${bases[baseIdx]}`));
|
|
213
|
+
};
|
|
158
214
|
sock.onclose = () => {
|
|
159
215
|
clearInterval(pingTimer);
|
|
160
216
|
fail(codedError('signaling-closed', 'signalling closed before joining'));
|
|
@@ -172,11 +228,12 @@ export function dxrSignaling(url = DXR_SIGNAL_DEFAULT, opts = {}) {
|
|
|
172
228
|
const tryAgain = () => {
|
|
173
229
|
if (left) return;
|
|
174
230
|
open(true).catch((err) => {
|
|
175
|
-
if (left || (err && err.code === 'room-full')) {
|
|
231
|
+
if (left || (err && (err.code === 'room-full' || FATAL_JOIN_CODES.includes(err.code)))) {
|
|
176
232
|
hooks.onDisconnect?.(err);
|
|
177
233
|
return;
|
|
178
234
|
}
|
|
179
|
-
|
|
235
|
+
// A `rate-limited` / `quota` refusal says when to come back; never sooner.
|
|
236
|
+
setTimeout(tryAgain, Math.max(backoffMs(attempt++, { baseMs: 500, maxMs: 15000 }), (err && err.retryMs) || 0));
|
|
180
237
|
});
|
|
181
238
|
};
|
|
182
239
|
setTimeout(tryAgain, backoffMs(attempt++, { baseMs: 300, maxMs: 15000 }));
|
package/js/call/ui.js
CHANGED
|
@@ -15,6 +15,16 @@
|
|
|
15
15
|
// 4. Hidden chrome is `display: none`, never `opacity: 0`.
|
|
16
16
|
// 5. The one full-tile element is the opaque COVER held until `handle.firstWoven` (rule 5 of the
|
|
17
17
|
// woven-canvas rules), cut — never faded — when it resolves.
|
|
18
|
+
//
|
|
19
|
+
// THE THEMING API (RFC 0003 §2, C2) is three things, and the class names are none of them:
|
|
20
|
+
// - CSS custom properties on the host: --dxr-accent, --dxr-ink, --dxr-shell, --dxr-danger,
|
|
21
|
+
// --dxr-radius (chrome only, never a tile), --dxr-font. `theme` in JS sets the same ones.
|
|
22
|
+
// - `part` names on the chrome: bar, invite, badge, plate, lobby, banner, self, tile, grid.
|
|
23
|
+
// The chrome is LIGHT DOM (a woven canvas must live in the document's own tree), so they are
|
|
24
|
+
// reached as `dxr-call [part="bar"]` rather than `::part(bar)`; the names are the contract.
|
|
25
|
+
// - `theme.strings`: every string the chrome shows, by key (CALL_STRINGS) — also localisation.
|
|
26
|
+
// The woven-canvas constraints are enforced here, not documented: every variable styles chrome
|
|
27
|
+
// only, so no theme can reach a tile.
|
|
18
28
|
|
|
19
29
|
/** Named accents, shared with ./player (same names, same colours). */
|
|
20
30
|
export const CALL_ACCENTS = Object.freeze({
|
|
@@ -29,14 +39,97 @@ export const CALL_ACCENTS = Object.freeze({
|
|
|
29
39
|
});
|
|
30
40
|
export const resolveCallAccent = (a) => (typeof a === 'string' && CALL_ACCENTS[a.toLowerCase()]) || a;
|
|
31
41
|
|
|
42
|
+
/** The CSS custom properties `theme` writes (key → property). `tileAspect` / `strings` are not CSS. */
|
|
43
|
+
export const THEME_VARS = Object.freeze({ accent: '--dxr-accent', ink: '--dxr-ink', shell: '--dxr-shell', danger: '--dxr-danger', radius: '--dxr-radius', font: '--dxr-font' });
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Every string the chrome shows, by key. `theme.strings` overrides any subset (a flat map), which
|
|
47
|
+
* is also how the chrome is localised. `{n}`-style placeholders are filled by the module.
|
|
48
|
+
*/
|
|
49
|
+
export const CALL_STRINGS = Object.freeze({
|
|
50
|
+
// lobby
|
|
51
|
+
lobbyStartTitle: 'Start a 3D call',
|
|
52
|
+
lobbyJoinTitle: 'Join the 3D call',
|
|
53
|
+
lobbyFullTitle: 'This call is full',
|
|
54
|
+
lobbyLeftTitle: 'You left the call',
|
|
55
|
+
lobbyFullText: 'It already has {maxPeers} participants.',
|
|
56
|
+
lobbyText: 'Check your framing below. Camera: {camera} — {kind}.',
|
|
57
|
+
cameraDefault: 'default',
|
|
58
|
+
kindBusy: 'busy (joining audio-only)',
|
|
59
|
+
kindNone: 'none (joining audio-only)',
|
|
60
|
+
kindSbs: 'sending 3D (side-by-side, {width}×{height})',
|
|
61
|
+
kindMono: 'sending 2D ({width}×{height})',
|
|
62
|
+
liftOff: 'Mono cameras: 2D (2D→3D is off).',
|
|
63
|
+
liftChecking: 'Mono cameras: checking 2D→3D…',
|
|
64
|
+
liftMissing: 'Mono cameras: 2D→3D unavailable in this build.',
|
|
65
|
+
liftNoProvider: 'Mono cameras: 2D (no 2D→3D provider here).',
|
|
66
|
+
liftNative: 'Mono cameras: 2D→3D (native{provider}).',
|
|
67
|
+
liftWeb: 'Mono cameras: 2D→3D (in this page, WebGPU).',
|
|
68
|
+
liftProven: 'Mono cameras: 2D→3D.',
|
|
69
|
+
liftUnproven: 'Mono cameras: 2D→3D (confirmed on the first mono participant).',
|
|
70
|
+
start: 'Start 3D call',
|
|
71
|
+
join: 'Join call',
|
|
72
|
+
rejoin: 'Rejoin',
|
|
73
|
+
retryCamera: 'Retry camera',
|
|
74
|
+
cameraSelect: 'Camera',
|
|
75
|
+
joining: 'Joining…',
|
|
76
|
+
// invite
|
|
77
|
+
waitingTitle: 'Waiting for others',
|
|
78
|
+
waitingText: 'Share this link (or scan the code). Anyone who opens it joins — keep it private.',
|
|
79
|
+
inviteTitle: 'Invite',
|
|
80
|
+
inviteText: 'Anyone with this link can join.',
|
|
81
|
+
inviteLink: 'Invite link',
|
|
82
|
+
copyLink: 'Copy link',
|
|
83
|
+
copied: 'Copied',
|
|
84
|
+
pressCopy: 'Press Ctrl/Cmd+C',
|
|
85
|
+
qrLabel: 'QR code of the invite link',
|
|
86
|
+
// banner
|
|
87
|
+
banner2D: 'You are seeing this call in 2D.',
|
|
88
|
+
bannerLink: 'View in 3D with DisplayXR Browser',
|
|
89
|
+
// bar
|
|
90
|
+
mute: 'Mute microphone',
|
|
91
|
+
unmute: 'Unmute microphone',
|
|
92
|
+
cameraOn: 'Turn camera on',
|
|
93
|
+
cameraOff: 'Turn camera off',
|
|
94
|
+
cameraRetry: 'No camera — click to retry',
|
|
95
|
+
cameraBusyRetry: '{cameraBusy} — click to retry',
|
|
96
|
+
depth: 'Depth',
|
|
97
|
+
invite: 'Invite',
|
|
98
|
+
leave: 'Leave call',
|
|
99
|
+
// plates and badges
|
|
100
|
+
connecting: 'Connecting…',
|
|
101
|
+
reconnecting: 'Reconnecting…',
|
|
102
|
+
leftCall: 'Left the call',
|
|
103
|
+
cameraOffPlate: 'Camera off',
|
|
104
|
+
noCamera: 'No camera',
|
|
105
|
+
unreachable: "Can't reach this participant — the network needs a relay (TURN)",
|
|
106
|
+
cameraBusy: 'Camera busy — in use by another app (e.g. eye tracking)',
|
|
107
|
+
you: 'You',
|
|
108
|
+
badge3D: '3D',
|
|
109
|
+
badge2D3D: '2D→3D',
|
|
110
|
+
badge2D: '2D',
|
|
111
|
+
badgePending: '…',
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
/** A string table over CALL_STRINGS with `overrides`: `t(key, vars)` fills `{var}` placeholders. */
|
|
115
|
+
export function createStrings(overrides) {
|
|
116
|
+
const table = { ...CALL_STRINGS, ...(overrides && typeof overrides === 'object' ? overrides : {}) };
|
|
117
|
+
return (key, vars) => {
|
|
118
|
+
let s = typeof table[key] === 'string' ? table[key] : CALL_STRINGS[key] || key;
|
|
119
|
+
if (vars) for (const [k, v] of Object.entries(vars)) s = s.split(`{${k}}`).join(String(v));
|
|
120
|
+
return s;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
32
124
|
const STYLE_ID = 'dxr-call-style';
|
|
33
125
|
const CSS = `
|
|
34
|
-
.dxr-call-host{--dxr-accent:#4da3ff;--dxr-ink:#fff;--dxr-shell:rgba(16,17,22,.92);--dxr-danger:#ff5a5f;
|
|
126
|
+
.dxr-call-host{--dxr-accent:#4da3ff;--dxr-ink:#fff;--dxr-shell:rgba(16,17,22,.92);--dxr-danger:#ff5a5f;--dxr-radius:12px;
|
|
127
|
+
--dxr-font:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
|
|
35
128
|
display:flex;flex-direction:column;gap:12px;color:var(--dxr-ink);
|
|
36
|
-
font:14px/1.4
|
|
129
|
+
font:14px/1.4 var(--dxr-font);}
|
|
37
130
|
.dxr-call-host *{box-sizing:border-box;}
|
|
38
131
|
.dxr-call-hidden{display:none !important;}
|
|
39
|
-
.dxr-call-banner{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:9px 14px;border-radius:
|
|
132
|
+
.dxr-call-banner{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:9px 14px;border-radius:var(--dxr-radius);
|
|
40
133
|
background:var(--dxr-shell);border:1px solid rgba(255,255,255,.12);font-size:13px;}
|
|
41
134
|
.dxr-call-banner a{color:var(--dxr-accent);font-weight:600;}
|
|
42
135
|
/* ── grid: bare boxes, nothing that makes a render surface ── */
|
|
@@ -50,6 +143,10 @@ const CSS = `
|
|
|
50
143
|
.dxr-call-grid[data-layout="speaker"]{grid-template-columns:repeat(3,1fr);}
|
|
51
144
|
.dxr-call-grid[data-layout="speaker"] .dxr-call-tile--main{grid-column:1/-1;}
|
|
52
145
|
.dxr-call-grid[data-layout="speaker"][data-n="1"]{grid-template-columns:1fr;}
|
|
146
|
+
/* layout:'none' — the module creates the tiles but does not position them: the grid box steps
|
|
147
|
+
aside (display:contents) so each [data-dxr-peer] tile is laid out by the PAGE's own CSS on the
|
|
148
|
+
host. A tile is never moved; it is styled in place (woven-canvas rule 2). */
|
|
149
|
+
.dxr-call-grid[data-layout="none"]{display:contents;}
|
|
53
150
|
.dxr-call-tile{position:relative;min-width:0;}
|
|
54
151
|
.dxr-call-stage{position:relative;background:#000;}
|
|
55
152
|
.dxr-call-stage>canvas{display:block;width:100%;height:100%;}
|
|
@@ -70,29 +167,29 @@ const CSS = `
|
|
|
70
167
|
will-change:transform;pointer-events:none;}
|
|
71
168
|
.dxr-call-cover{position:absolute;inset:0;z-index:1;background:#000;}
|
|
72
169
|
/* ── empty room / lobby ── */
|
|
73
|
-
.dxr-call-panel{padding:18px;border-radius:
|
|
170
|
+
.dxr-call-panel{padding:18px;border-radius:var(--dxr-radius);background:var(--dxr-shell);border:1px solid rgba(255,255,255,.1);}
|
|
74
171
|
.dxr-call-panel h3{margin:0 0 6px;font-size:17px;}
|
|
75
172
|
.dxr-call-panel p{margin:0 0 12px;opacity:.75;}
|
|
76
173
|
.dxr-call-row{display:flex;flex-wrap:wrap;align-items:center;gap:8px;}
|
|
77
174
|
.dxr-call-btn{appearance:none;border:1px solid rgba(255,255,255,.18);background:rgba(255,255,255,.08);color:inherit;
|
|
78
|
-
font:600 13px/1
|
|
175
|
+
font:600 13px/1 var(--dxr-font);padding:9px 14px;border-radius:calc(var(--dxr-radius) * .75);cursor:pointer;}
|
|
79
176
|
.dxr-call-btn:hover{background:rgba(255,255,255,.16);}
|
|
80
177
|
.dxr-call-btn:focus-visible{outline:2px solid var(--dxr-accent);outline-offset:2px;}
|
|
81
178
|
.dxr-call-btn--primary{background:var(--dxr-accent);border-color:var(--dxr-accent);color:#07111d;}
|
|
82
179
|
.dxr-call-btn--primary:hover{background:var(--dxr-accent);}
|
|
83
180
|
.dxr-call-btn--danger{background:var(--dxr-danger);border-color:var(--dxr-danger);color:#fff;}
|
|
84
181
|
.dxr-call-select{font:inherit;color:inherit;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.18);
|
|
85
|
-
border-radius:
|
|
182
|
+
border-radius:calc(var(--dxr-radius) * .66);padding:7px 9px;max-width:260px;}
|
|
86
183
|
.dxr-call-invite{display:flex;gap:14px;align-items:flex-start;flex-wrap:wrap;}
|
|
87
184
|
.dxr-call-invite input{flex:1 1 240px;min-width:0;font:12px ui-monospace,Menlo,monospace;color:inherit;
|
|
88
|
-
background:rgba(0,0,0,.35);border:1px solid rgba(255,255,255,.14);border-radius:
|
|
185
|
+
background:rgba(0,0,0,.35);border:1px solid rgba(255,255,255,.14);border-radius:calc(var(--dxr-radius) * .66);padding:8px;}
|
|
89
186
|
.dxr-call-invite canvas{width:132px;height:132px;image-rendering:pixelated;background:#fff;}
|
|
90
187
|
/* ── footer: self view + bar, BELOW the grid (over no tile) ── */
|
|
91
188
|
.dxr-call-foot{display:flex;align-items:flex-end;gap:12px;flex-wrap:wrap;}
|
|
92
189
|
.dxr-call-self{width:200px;flex:none;}
|
|
93
190
|
.dxr-call-host--lobby .dxr-call-self{width:min(560px,100%);}
|
|
94
191
|
.dxr-call-self .dxr-call-badge b{color:var(--dxr-ink);}
|
|
95
|
-
.dxr-call-bar{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:8px 10px;border-radius:
|
|
192
|
+
.dxr-call-bar{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:8px 10px;border-radius:calc(var(--dxr-radius) + 2px);
|
|
96
193
|
background:var(--dxr-shell);border:1px solid rgba(255,255,255,.1);will-change:transform;}
|
|
97
194
|
.dxr-call-host--lobby .dxr-call-bar{display:none;}
|
|
98
195
|
.dxr-call-ib{appearance:none;border:0;width:40px;height:40px;border-radius:50%;padding:9px;cursor:pointer;
|
|
@@ -127,7 +224,7 @@ export const ICONS = {
|
|
|
127
224
|
mutedSmall: P('M19 11h-2a5 5 0 0 1-.4 1.97l1.47 1.47A6.96 6.96 0 0 0 19 11zM15 11V5a3 3 0 0 0-5.94-.6L15 10.34zM4.27 3 3 4.27l6 6V11a3 3 0 0 0 4.52 2.59l1.46 1.46A5 5 0 0 1 7 11H5a7 7 0 0 0 6 6.92V21h2v-3.08a6.9 6.9 0 0 0 3.02-1.14L19.73 21 21 19.73z'),
|
|
128
225
|
};
|
|
129
226
|
|
|
130
|
-
/** `el('div', {class: 'x'}, [children])` — a tiny builder, attributes as properties or attrs. */
|
|
227
|
+
/** `el('div', {class: 'x', part: 'bar'}, [children])` — a tiny builder, attributes as properties or attrs. */
|
|
131
228
|
export function el(tag, props = {}, children = []) {
|
|
132
229
|
const n = document.createElement(tag);
|
|
133
230
|
for (const [k, v] of Object.entries(props)) {
|
package/js/call/wire.js
CHANGED
|
@@ -13,8 +13,11 @@ export const CALL_SDK = 'inline3d-call/1';
|
|
|
13
13
|
/** Formats a sender may declare. Anything else — or no hello at all — is read as `'mono'`. */
|
|
14
14
|
export const CALL_FORMATS = Object.freeze(['sbs', 'mono']);
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// The side-by-side geometry (what counts as a pair, eye crops, the mirror-and-swap self view)
|
|
17
|
+
// moved to js/camera/geometry.js in C2 — `/camera` owns it, `/call` consumes it. Re-exported here
|
|
18
|
+
// so every in-tree import and test path keeps resolving.
|
|
19
|
+
export { SBS_ASPECT_MIN, looksSbs, eyeCropRect, eyeOutputSize, mirrorSwapOps, mirrorSwapPixels } from '../camera/geometry.js';
|
|
20
|
+
export { CONVERGENCE_ALPHA, CONVERGENCE_MAX_FRACTION, DEPTH_RANGE_FRACTION } from '../camera/converge.js';
|
|
18
21
|
|
|
19
22
|
/** Default and hard cap of participants in a full-mesh call (including yourself). */
|
|
20
23
|
export const DEFAULT_MAX_PEERS = 4;
|
|
@@ -23,15 +26,6 @@ export const MESH_HARD_CAP = 4;
|
|
|
23
26
|
/** `hint` messages are rate-limited to this many per second, on the sender AND the receiver. */
|
|
24
27
|
export const HINT_MAX_HZ = 5;
|
|
25
28
|
|
|
26
|
-
/** Low-pass factor for the convergence shift (RFC §3): next = prev + α·(target − prev). */
|
|
27
|
-
export const CONVERGENCE_ALPHA = 0.2;
|
|
28
|
-
|
|
29
|
-
/** The convergence shift never exceeds this fraction of the per-eye width, either way. */
|
|
30
|
-
export const CONVERGENCE_MAX_FRACTION = 0.12;
|
|
31
|
-
|
|
32
|
-
/** `setDepth(v)`: v in [-1, 1] adds v times this fraction of the per-eye width to the shift. */
|
|
33
|
-
export const DEPTH_RANGE_FRACTION = 0.05;
|
|
34
|
-
|
|
35
29
|
/** Plausible subject distances, mm. A hint outside this is ignored as noise. */
|
|
36
30
|
export const SUBJECT_Z_MIN_MM = 150;
|
|
37
31
|
export const SUBJECT_Z_MAX_MM = 5000;
|
|
@@ -231,143 +225,9 @@ export function badgeFor(route) {
|
|
|
231
225
|
return route === 'woven-sbs' ? '3D' : route === 'lifted' ? '2D→3D' : '2D';
|
|
232
226
|
}
|
|
233
227
|
|
|
234
|
-
// ── convergence (RFC §3)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
export function focalPx(eyeWidthPx, hfovDeg) {
|
|
238
|
-
if (!(eyeWidthPx > 0) || !(hfovDeg > 0) || hfovDeg >= 180) return null;
|
|
239
|
-
return eyeWidthPx / 2 / Math.tan(((hfovDeg / 2) * Math.PI) / 180);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Per-eye horizontal shift, in SOURCE eye pixels, that puts a subject at `subjectZmm` on the
|
|
244
|
-
* display plane: `f_px · baseline / (2 · subjectZ)`. A parallel stereo camera gives everything a
|
|
245
|
-
* crossed disparity of `f·B/Z` (full, between the eyes); half of it comes off each eye.
|
|
246
|
-
*
|
|
247
|
-
* Positive = the left eye's crop moves RIGHT and the right eye's LEFT (content pushed back).
|
|
248
|
-
* Returns 0 when anything it needs is unknown — the receiver then shows the pair as sent.
|
|
249
|
-
*/
|
|
250
|
-
export function convergenceShiftPx({ eyeWidthPx, hfovDeg, baselineMm, subjectZmm }) {
|
|
251
|
-
const f = focalPx(eyeWidthPx, hfovDeg);
|
|
252
|
-
if (f === null || !(baselineMm > 0) || !(subjectZmm > 0)) return 0;
|
|
253
|
-
return (f * baselineMm) / (2 * subjectZmm);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/** Clamp a shift to ±CONVERGENCE_MAX_FRACTION of the per-eye width. */
|
|
257
|
-
export function clampShift(px, eyeWidthPx, maxFraction = CONVERGENCE_MAX_FRACTION) {
|
|
258
|
-
const lim = Math.max(0, eyeWidthPx * maxFraction);
|
|
259
|
-
return Math.max(-lim, Math.min(lim, px || 0));
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/** One low-pass step: `prev + α(target − prev)`. Snaps when within 0.05 px so it can settle. */
|
|
263
|
-
export function lowPass(prev, target, alpha = CONVERGENCE_ALPHA) {
|
|
264
|
-
const next = prev + alpha * (target - prev);
|
|
265
|
-
return Math.abs(target - next) < 0.05 ? target : next;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* A tile's convergence state: the target from hello+hint, the page's depth offset, and the
|
|
270
|
-
* smoothed value actually painted. `step()` once per painted frame.
|
|
271
|
-
*/
|
|
272
|
-
export function createConvergence() {
|
|
273
|
-
const s = {
|
|
274
|
-
hello: null,
|
|
275
|
-
subjectZmm: null,
|
|
276
|
-
// Auto-convergence (call/disparity.js): the MEASURED disparity of the point between the remote
|
|
277
|
-
// person's eyes, in source eye pixels (left x − right x). When set it wins over the hint: it is
|
|
278
|
-
// read off the frames, so it needs no calibration and cannot disagree with them.
|
|
279
|
-
measuredPx: null,
|
|
280
|
-
depth: 0, // setDepth(), [-1, 1]
|
|
281
|
-
current: 0,
|
|
282
|
-
target(eyeWidthPx) {
|
|
283
|
-
const auto =
|
|
284
|
-
s.measuredPx !== null
|
|
285
|
-
? s.measuredPx / 2 // half the disparity comes off each eye: the eyes land at zero parallax
|
|
286
|
-
: s.hello && s.subjectZmm
|
|
287
|
-
? convergenceShiftPx({
|
|
288
|
-
eyeWidthPx,
|
|
289
|
-
hfovDeg: s.hello.hfovDeg,
|
|
290
|
-
baselineMm: s.hello.baselineMm,
|
|
291
|
-
subjectZmm: s.subjectZmm,
|
|
292
|
-
})
|
|
293
|
-
: 0;
|
|
294
|
-
return clampShift(auto + s.depth * DEPTH_RANGE_FRACTION * eyeWidthPx, eyeWidthPx);
|
|
295
|
-
},
|
|
296
|
-
step(eyeWidthPx) {
|
|
297
|
-
s.current = lowPass(s.current, s.target(eyeWidthPx));
|
|
298
|
-
return s.current;
|
|
299
|
-
},
|
|
300
|
-
};
|
|
301
|
-
return s;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* The source rectangle of ONE eye, cropped to the tile's aspect and shifted by the convergence
|
|
306
|
-
* offset. Never upscales past the source: a 640-wide eye (a real raw stereo camera) stays 640.
|
|
307
|
-
*
|
|
308
|
-
* @param {number} eyeW source per-eye width (px)
|
|
309
|
-
* @param {number} eyeH source height
|
|
310
|
-
* @param {number} aspect the tile's (= the woven buffer's per-eye) aspect, w/h
|
|
311
|
-
* @param {number} shift per-eye shift in source px (see convergenceShiftPx); + = push back
|
|
312
|
-
* @param {0|1} eye 0 = left, 1 = right
|
|
313
|
-
* @returns {{sx:number, sy:number, sw:number, sh:number}} relative to that eye's half
|
|
314
|
-
*/
|
|
315
|
-
export function eyeCropRect(eyeW, eyeH, aspect, shift, eye) {
|
|
316
|
-
const s = Math.abs(shift || 0);
|
|
317
|
-
let sw = Math.min(eyeW - 2 * s, eyeH * aspect);
|
|
318
|
-
sw = Math.max(1, sw);
|
|
319
|
-
const sh = Math.min(eyeH, sw / aspect);
|
|
320
|
-
sw = sh * aspect;
|
|
321
|
-
const cx = (eyeW - sw) / 2 + (eye === 0 ? shift : -shift);
|
|
322
|
-
return { sx: Math.max(0, Math.min(eyeW - sw, cx)), sy: (eyeH - sh) / 2, sw, sh };
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/** The output per-eye size for a source eye and a tile aspect: no upscaling, even numbers. */
|
|
326
|
-
export function eyeOutputSize(eyeW, eyeH, aspect) {
|
|
327
|
-
const w = Math.min(eyeW, eyeH * aspect);
|
|
328
|
-
const h = w / aspect;
|
|
329
|
-
return { w: Math.max(2, Math.round(w / 2) * 2), h: Math.max(2, Math.round(h / 2) * 2) };
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// ── self view: the mirroring trap (RFC §3) ─────────────────────────────────────────────────
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* The draw operations for a MIRRORED stereo self-view: each half mirrored AND the halves swapped.
|
|
336
|
-
*
|
|
337
|
-
* Why both: mirroring a scene horizontally means the reflected left eye sees what the original
|
|
338
|
-
* right eye saw (mirrored), and vice versa. Mirroring each half IN PLACE keeps the eyes where they
|
|
339
|
-
* were and inverts every disparity — the face goes pseudoscopic (inside-out). Mirror + swap keeps
|
|
340
|
-
* crossed disparity crossed. (It is the same pixels as flipping the whole SBS frame; spelled out
|
|
341
|
-
* per half so the intent survives refactoring.) The WIRE is never mirrored — only this preview.
|
|
342
|
-
*
|
|
343
|
-
* @param {number} W full SBS frame width
|
|
344
|
-
* @param {number} H height
|
|
345
|
-
* @returns {Array<{src:'L'|'R', sx:number, sw:number, dx:number, dw:number, mirror:true}>}
|
|
346
|
-
*/
|
|
347
|
-
export function mirrorSwapOps(W, H) {
|
|
348
|
-
const half = W / 2;
|
|
349
|
-
return [
|
|
350
|
-
{ src: 'R', sx: half, sw: half, sy: 0, sh: H, dx: 0, dw: half, mirror: true },
|
|
351
|
-
{ src: 'L', sx: 0, sw: half, sy: 0, sh: H, dx: half, dw: half, mirror: true },
|
|
352
|
-
];
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Apply mirrorSwapOps to a row-major single-channel frame (tests, and a reference for the canvas
|
|
357
|
-
* path). Returns a new array.
|
|
358
|
-
*/
|
|
359
|
-
export function mirrorSwapPixels(px, W, H) {
|
|
360
|
-
const out = new px.constructor(px.length);
|
|
361
|
-
for (const op of mirrorSwapOps(W, H)) {
|
|
362
|
-
for (let y = 0; y < H; y++) {
|
|
363
|
-
for (let x = 0; x < op.dw; x++) {
|
|
364
|
-
const srcX = op.sx + (op.sw - 1 - x); // mirrored within the half
|
|
365
|
-
out[y * W + op.dx + x] = px[y * W + srcX];
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return out;
|
|
370
|
-
}
|
|
228
|
+
// ── convergence (RFC 0002 §3) — moved to js/camera/converge.js in C2 (the self view and the remote
|
|
229
|
+
// tiles share one convergence state); re-exported so in-tree imports and test paths keep resolving.
|
|
230
|
+
export { focalPx, convergenceShiftPx, clampShift, lowPass, createConvergence } from '../camera/converge.js';
|
|
371
231
|
|
|
372
232
|
// ── weave liveness (displayxr-browser-pvt#172) ─────────────────────────────────────────────
|
|
373
233
|
|
|
@@ -427,8 +287,3 @@ export function backoffMs(attempt, { baseMs = 1000, maxMs = 30000, rand = Math.r
|
|
|
427
287
|
const raw = Math.min(maxMs, baseMs * Math.pow(2, Math.max(0, attempt)));
|
|
428
288
|
return Math.round(raw * (0.8 + 0.4 * rand()));
|
|
429
289
|
}
|
|
430
|
-
|
|
431
|
-
/** Does a delivered frame look like a side-by-side pair? (capture 'auto' only) */
|
|
432
|
-
export function looksSbs(width, height) {
|
|
433
|
-
return width > 0 && height > 0 && width / height > SBS_ASPECT_MIN;
|
|
434
|
-
}
|