Debug.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const BREATH_POINT_TYPE = "debugBreathPoint"
  2. , TAP_BREATH_POINT_TYPE = "debugTapBreathPoint"
  3. , DEFAULT_SEARCH_RANGE = 1e3;
  4. export default class Debug {
  5. constructor(e) {
  6. E(this, "isShowNearbyBreathPoints", !1);
  7. E(this, "isShowTapBreathPoints", !1);
  8. E(this, "isSceneShading", !0);
  9. E(this, "searchRange", DEFAULT_SEARCH_RANGE);
  10. E(this, "nearbyBreathPointListening", !1);
  11. E(this, "tapBreathPointListening", !1);
  12. E(this, "dumpStreamTimer", 0);
  13. this.room = e
  14. }
  15. toggleStats() {
  16. return this.room.stats.isShow ? this.room.stats.hide() : this.room.stats.show()
  17. }
  18. toggleNearbyBreathPoint(e=DEFAULT_SEARCH_RANGE) {
  19. this.searchRange = e,
  20. this.isShowNearbyBreathPoints = !this.isShowNearbyBreathPoints,
  21. this.isShowNearbyBreathPoints ? (this.getPointsAndRender(),
  22. this.setupNearbyBreathPointListener()) : this.room.breathPointManager.clearBreathPoints(BREATH_POINT_TYPE)
  23. }
  24. toggleTapBreathPoint() {
  25. this.isShowTapBreathPoints = !this.isShowTapBreathPoints,
  26. this.isShowTapBreathPoints ? this.setupTapPointListener() : this.room.breathPointManager.clearBreathPoints(TAP_BREATH_POINT_TYPE)
  27. }
  28. dumpStream(e, t=10 * 1e3) {
  29. if (this.dumpStreamTimer)
  30. throw new Error("dumpStream running");
  31. this.room.networkController.rtcp.workers.saveframe = !0,
  32. this.dumpStreamTimer = window.setTimeout(()=>{
  33. this.room.networkController.rtcp.workers.SaveMediaStream = !0,
  34. this.dumpStreamTimer = 0,
  35. e && e()
  36. }
  37. , t)
  38. }
  39. toggleSceneshading() {
  40. this.isSceneShading = !this.isSceneShading,
  41. this.isSceneShading ? this.room.sceneManager.changeVideoShaderForLowModel() : this.room.sceneManager.changeDefaultShaderForLowModel()
  42. }
  43. setupTapPointListener() {
  44. this.tapBreathPointListening || (this.tapBreathPointListening = !0,
  45. this.room.on("_coreClick", ({point: e})=>{
  46. this.isShowTapBreathPoints && this.renderTapBreathPoint({
  47. id: "tapToint",
  48. position: e
  49. })
  50. }
  51. ))
  52. }
  53. renderTapBreathPoint({position: e, id: t}) {
  54. let r;
  55. if (r = this.room.breathPointManager.breathPoints.get(t)) {
  56. r.position = e;
  57. return
  58. }
  59. this.room.breathPointManager.addBreathPoint({
  60. id: t,
  61. position: e,
  62. type: TAP_BREATH_POINT_TYPE,
  63. size: .8,
  64. forceLeaveGround: !0,
  65. billboardMode: !0,
  66. rotation: Math.abs(e.z) < 20 ? {
  67. pitch: 90,
  68. yaw: 0,
  69. roll: 0
  70. } : {
  71. pitch: 0,
  72. yaw: 270,
  73. roll: 0
  74. }
  75. })
  76. }
  77. setupNearbyBreathPointListener() {
  78. var e;
  79. this.nearbyBreathPointListening || (this.nearbyBreathPointListening = !0,
  80. (e = this.room._userAvatar) == null || e.on("stopMoving", ()=>{
  81. this.isShowNearbyBreathPoints && this.getPointsAndRender()
  82. }
  83. ))
  84. }
  85. async getPointsAndRender() {
  86. var r, n;
  87. const e = this.searchRange
  88. , t = ((r = this.room._userAvatar) == null ? void 0 : r.position) && await this.getNeighborPoints({
  89. point: (n = this.room._userAvatar) == null ? void 0 : n.position,
  90. containSelf: !0,
  91. searchRange: e
  92. }) || [];
  93. console.error(t)
  94. this.room.breathPointManager.breathPoints.forEach(o=>{
  95. !!t.find(s=>JSON.stringify(s) === o._id) || this.room.breathPointManager.clearBreathPoints(o._id)
  96. }
  97. ),
  98. t.forEach(o=>{
  99. const a = o.breakPointId + "" // JSON.stringify(o);
  100. this.room.breathPointManager.breathPoints.get(a) || this.room.breathPointManager.addBreathPoint({
  101. id: a,
  102. position: o.position,
  103. type: BREATH_POINT_TYPE,
  104. rotation: {
  105. pitch: 90,
  106. yaw: 0,
  107. roll: 0
  108. },
  109. forceLeaveGround: !0
  110. })
  111. }
  112. )
  113. }
  114. getNeighborPoints(e) {
  115. const {point: t, containSelf: r=!1, searchRange: n=500} = e;
  116. return this.room.actionsHandler.getNeighborPoints({
  117. point: t,
  118. containSelf: r,
  119. searchRange: n
  120. })
  121. }
  122. }