Skip to content

Commit 1a55579

Browse files
author
Avaer Kazmer
committed
Handle apply edit state with land peer connection
1 parent 5f5bb8d commit 1a55579

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

app.html

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,14 +1663,22 @@
16631663

16641664
if (rtcWs) {
16651665
const index = _getChildNodeIndex(xrIframe);
1666-
rtcWs.send(JSON.stringify({
1666+
const m = {
16671667
method: 'editState',
16681668
spec: {
16691669
keyPath: [0],
16701670
method: 'removeChild',
1671-
key: index,
1671+
key: landState ? ('#' + xrIframe.id) : index,
16721672
},
1673-
}));
1673+
};
1674+
if (landState) {
1675+
for (let i = 0; i < peerConnections.length; i++) {
1676+
const peerConnection = peerConnections[i];
1677+
peerConnection.sendChannel && peerConnection.sendChannel.send(JSON.stringify(m));
1678+
}
1679+
} else {
1680+
rtcWs.send(JSON.stringify(m));
1681+
}
16741682
}
16751683

16761684
root.removeChild(xrIframe);
@@ -4330,20 +4338,31 @@
43304338
const xrIframe = document.createElement('xr-iframe');
43314339
xrIframe.src = href;
43324340
xrIframe.name = name;
4341+
if (landState) {
4342+
xrIframe.id = `${connectionId}-${_randomString()}`;
4343+
}
43334344
root.appendChild(xrIframe);
43344345
root.update(); // force mutation observer to run
43354346

43364347
currentMoveMeshes[controllerIndex] = xrIframe.moveMesh;
43374348

43384349
if (rtcWs) {
4339-
rtcWs.send(JSON.stringify({
4350+
const m = {
43404351
method: 'editState',
43414352
spec: {
43424353
keyPath: [0],
43434354
method: 'appendChild',
43444355
value: xrIframe.outerHTML,
43454356
},
4346-
}));
4357+
};
4358+
if (landState) {
4359+
for (let i = 0; i < peerConnections.length; i++) {
4360+
const peerConnection = peerConnections[i];
4361+
peerConnection.sendChannel && peerConnection.sendChannel.send(JSON.stringify(m));
4362+
}
4363+
} else {
4364+
rtcWs.send(JSON.stringify(m));
4365+
}
43474366
}
43484367
/* } else if (id && (match = id.match(/^playlist:(.+)$/))) {
43494368
console.log('click playlist', match[1]); // XXX */
@@ -5762,11 +5781,12 @@
57625781
moveMesh.xrIframe.orientation = localQuaternion.toArray();
57635782

57645783
if (rtcWs) {
5765-
const index = _getChildNodeIndex(moveMesh.xrIframe);
5766-
rtcWs.send(JSON.stringify({
5784+
const {xrIframe} = moveMesh;
5785+
const index = _getChildNodeIndex(xrIframe);
5786+
const m = {
57675787
method: 'editState',
57685788
spec: {
5769-
keyPath: [0, index],
5789+
keyPath: landState ? [0, '#' + xrIframe.id] : [0, index],
57705790
method: 'setAttributes',
57715791
values: [
57725792
{
@@ -5779,7 +5799,15 @@
57795799
},
57805800
],
57815801
},
5782-
}));
5802+
};
5803+
if (landState) {
5804+
for (let i = 0; i < peerConnections.length; i++) {
5805+
const peerConnection = peerConnections[i];
5806+
peerConnection.sendChannel && peerConnection.sendChannel.send(JSON.stringify(m));
5807+
}
5808+
} else {
5809+
rtcWs.send(JSON.stringify(m));
5810+
}
57835811
}
57845812
}
57855813
}
@@ -6227,14 +6255,22 @@
62276255

62286256
if (rtcWs) {
62296257
const index = _getChildNodeIndex(xrIframe);
6230-
rtcWs.send(JSON.stringify({
6258+
const m = {
62316259
method: 'editState',
62326260
spec: {
62336261
keyPath: [0],
62346262
method: 'removeChild',
6235-
key: index,
6263+
key: landState ? ('#' + xrIframe.id) : index,
62366264
},
6237-
}));
6265+
};
6266+
if (landState) {
6267+
for (let i = 0; i < peerConnections.length; i++) {
6268+
const peerConnection = peerConnections[i];
6269+
peerConnection.sendChannel && peerConnection.sendChannel.send(JSON.stringify(m));
6270+
}
6271+
} else {
6272+
rtcWs.send(JSON.stringify(m));
6273+
}
62386274
}
62396275

62406276
root.removeChild(xrIframe);

0 commit comments

Comments
 (0)