-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
Copy pathshare-behavior.js
48 lines (44 loc) · 1.28 KB
/
share-behavior.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
export default Behavior({
created: function () {
this.checkInitShare();
},
methods: {
checkInitShare() {
wx.xrScene = undefined;
if (!this.scene) {
setTimeout(() => {
this.checkInitShare()
}, 100);
return;
}
if (this.scene.ar) {
if (this.scene.ar.ready) {
this.initARTrackerState(this.scene);
} else {
this.scene.event.add('ar-ready', () => this.initARTrackerState(this.scene));
}
}
if (!this.scene.share.supported) {
console.warn('Not support xr-frame share system now!');
return;
}
this.sharing = false;
wx.xrScene = this.scene;
},
initARTrackerState(scene) {
const xrFrameSystem = wx.getXrFrameSystem();
scene.dfs(() => {}, undefined, true, el => {
const comp = el.getComponent(xrFrameSystem.ARTracker);
if (comp) {
if (typeof comp.state === 'number') {
this.triggerEvent('arTrackerState', {state: comp.state, error: comp.errorMessage});
el.event.add('ar-tracker-state', tracker => {
this.triggerEvent('arTrackerState', {state: tracker.state, error: tracker.errorMessage});
});
}
return true;
}
});
}
}
})