Skip to content

Commit 93915dc

Browse files
author
Avaer Kazmer
committed
Handle land init state
1 parent 765bbcd commit 93915dc

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

app.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,18 @@
354354

355355
peerConnection.open = true;
356356

357+
if (landState) {
358+
// emit owned xr-iframes
359+
360+
const landXrIframe = root.childNodes[0];
361+
const ownedXrIframes = _getOwnedXrIframes(landXrIframe);
362+
const state = parse5.parseFragment(`<xr-site>${ownedXrIframes.map(xrIframe => xrIframe.outerHTML).join('')}</xr-site>`);
363+
sendChannel.send(JSON.stringify({
364+
method: 'initState',
365+
state,
366+
}));
367+
}
368+
357369
pingInterval = setInterval(() => {
358370
sendChannel.send(JSON.stringify({
359371
method: 'ping',
@@ -425,7 +437,18 @@
425437
const {hmd, gamepads} = data;
426438
skinMesh.setState(hmd, gamepads);
427439
}
428-
} else if (method === 'editState') {
440+
} else if (landState && method === 'initState') {
441+
const {state} = data;
442+
const stateXrSite = state.childNodes.find(node => node.tagName === 'xr-site');
443+
const stateXrIframes = stateXrSite ? stateXrSite.childNodes.filter(node => node.tagName === 'xr-iframe') : [];
444+
445+
for (let i = 0; i < stateXrIframes.length; i++) {
446+
const xrIframe = document.createElement('xr-iframe');
447+
root.appendChild(xrIframe);
448+
const htmlString = parse5.serialize(state);
449+
xrIframe.outerHTML = htmlString;
450+
}
451+
} else if (landState && method === 'editState') {
429452
_applyEditState(data.spec);
430453
} else if (method === 'ping') {
431454
// nothing

0 commit comments

Comments
 (0)