share-behavior.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. export default Behavior({
  2. created: function () {
  3. this.checkInitShare();
  4. },
  5. methods: {
  6. checkInitShare() {
  7. wx.xrScene = undefined;
  8. if (!this.scene) {
  9. setTimeout(() => {
  10. this.checkInitShare()
  11. }, 100);
  12. return;
  13. }
  14. if (this.scene.ar) {
  15. if (this.scene.ar.ready) {
  16. this.initARTrackerState(this.scene);
  17. } else {
  18. this.scene.event.add('ar-ready', () => this.initARTrackerState(this.scene));
  19. }
  20. }
  21. if (!this.scene.share.supported) {
  22. console.warn('Not support xr-frame share system now!');
  23. return;
  24. }
  25. this.sharing = false;
  26. wx.xrScene = this.scene;
  27. },
  28. initARTrackerState(scene) {
  29. const xrFrameSystem = wx.getXrFrameSystem();
  30. scene.dfs(() => {}, undefined, true, el => {
  31. const comp = el.getComponent(xrFrameSystem.ARTracker);
  32. if (comp) {
  33. if (typeof comp.state === 'number') {
  34. this.triggerEvent('arTrackerState', {state: comp.state, error: comp.errorMessage});
  35. el.event.add('ar-tracker-state', tracker => {
  36. this.triggerEvent('arTrackerState', {state: tracker.state, error: tracker.errorMessage});
  37. });
  38. }
  39. return true;
  40. }
  41. });
  42. }
  43. }
  44. })