Skip to content

Commit 28d2315

Browse files
author
Avaer Kazmer
committed
Make data attribute transferable over RTC in the asset case
1 parent 458cba5 commit 28d2315

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

app.html

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,7 @@
36303630
if (!landState) {
36313631
let live = true;
36323632
landState = {
3633+
loaded: false,
36333634
disconnect() {
36343635
live = false;
36353636
},
@@ -4286,9 +4287,32 @@
42864287

42874288
_rtcConnect('land', loginToken.name, 'land', async state => {
42884289
await p;
4289-
const xrSite = state.childNodes.find(childNode => childNode.nodeName === 'xr-site');
4290-
const xrIframes = xrSite.childNodes.filter(childNode => childNode.nodeName === 'xr-iframe');
4291-
console.log('got land xr iframes', state, xrIframes);
4290+
4291+
const landXrIframe = root.childNodes[0];
4292+
const extentXrIframes = _getChildXrIframes(landXrIframe);
4293+
const assetXrIframes = extentXrIframes.map(extentXrIframe => _getChildXrIframes(extentXrIframe)).flat();
4294+
4295+
const stateXrSite = state.childNodes.find(node => node.tagName === 'xr-site');
4296+
const stateXrIframes = stateXrSite ? stateXrSite.childNodes.filter(node => node.tagName === 'xr-iframe') : [];
4297+
for (let i = 0; i < stateXrIframes.length; i++) {
4298+
const stateXrIframe = stateXrIframes[i];
4299+
if (stateXrIframe.attrs) {
4300+
const idAttr = stateXrIframe.attrs.find(attr => attr.name === 'id');
4301+
if (idAttr) {
4302+
const id = idAttr.value;
4303+
const xrIframe = assetXrIframes.find(xrIframe => xrIframe.id === id);
4304+
console.log('set attrs', xrIframe, stateXrIframe.attrs);
4305+
if (xrIframe) {
4306+
for (let j = 0; j < stateXrIframe.attrs.length; j++) {
4307+
const attr = stateXrIframe.attrs[j];
4308+
const {name, value} = attr;
4309+
xrIframe.setAttribute(name, value);
4310+
}
4311+
}
4312+
}
4313+
}
4314+
}
4315+
landState.loaded = true;
42924316
});
42934317

42944318
const p = _connectLand();
@@ -5753,6 +5777,34 @@
57535777
}
57545778
}
57555779
}
5780+
5781+
if (rtcWs && landState && landState.loaded) {
5782+
for (let i = 0; i < assetMeshes.length; i++) {
5783+
const moveMesh = assetMeshes[i];
5784+
const {xrIframe} = moveMesh;
5785+
rtcWs.send(JSON.stringify({
5786+
method: 'editState',
5787+
spec: {
5788+
keyPath: [0, '#' + xrIframe.id],
5789+
method: 'setAttributes',
5790+
values: [
5791+
{
5792+
key: 'position',
5793+
value: xrIframe.getAttribute('position'),
5794+
},
5795+
{
5796+
key: 'orientation',
5797+
value: xrIframe.getAttribute('orientation'),
5798+
},
5799+
{
5800+
key: 'data',
5801+
value: xrIframe.getAttribute('data'),
5802+
},
5803+
],
5804+
},
5805+
}));
5806+
}
5807+
}
57565808
};
57575809
_updateCurrentMoveMeshes();
57585810

0 commit comments

Comments
 (0)