Signal.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const log$4 = new Logger("xverse-signal");
  2. class Signal {
  3. constructor(e) {
  4. E(this, "_room");
  5. E(this, "signalHandleActived", !0);
  6. E(this, "isUpdatedYUV", !0);
  7. this._room = e
  8. }
  9. handleSignal(e) {
  10. var a, s, l;
  11. if (!this.signalHandleActived)
  12. return;
  13. const {signal: t, alreadyUpdateYUV: r} = e;
  14. if (this.handleActionResponses(t),
  15. this._room.handleSignalHook(t),
  16. !r) {
  17. const u = (a = t.newUserStates) == null ? void 0 : a.find(c=>c.userId === this._room.userId);
  18. if ((u == null ? void 0 : u.renderInfo) && ((s = this._room._userAvatar) == null ? void 0 : s.isMoving)) {
  19. log$4.debug("stream stoped, make avatar to stop");
  20. const {isMoving: c, isRotating: h} = u.renderInfo;
  21. this._room.avatarManager._updateAvatarMovingStatus({
  22. id: u.userId,
  23. isMoving: !!c,
  24. isRotating: !!h
  25. })
  26. }
  27. return
  28. }
  29. this.isUpdatedYUV = r;
  30. const n = t;
  31. if (!t) {
  32. log$4.warn("metadata signal is empty");
  33. return
  34. }
  35. if (n.code === Codes$1.RepeatLogin) {
  36. this._room.handleRepetLogin();
  37. return
  38. }
  39. n.code !== void 0 && n.code !== Codes$1.Success && n.code !== Codes$1.ActionMaybeDelay && n.code !== Codes$1.DoActionBlocked && n.code !== Codes$1.GetOnVehicle && (log$4.error("signal errcode: ", n),
  40. this._room.emit("error", n));
  41. const o = (l = n.newUserStates) == null ? void 0 : l.find(u=>u.userId === this._room.userId);
  42. if (n.broadcastAction)
  43. try {
  44. const u = JSON.parse(n.broadcastAction.data);
  45. Broadcast.handlers.forEach(c=>c(u))
  46. } catch (u) {
  47. log$4.error(u)
  48. }
  49. if (n.newUserStates && n.newUserStates.length > 0 && this._room.avatarManager.handleAvatar(n),
  50. o != null && o.playerState) {
  51. this._room._currentClickingState = o.playerState;
  52. const {pathName: u, attitude: c, areaName: h, skinId: f} = o.playerState;
  53. if (u && (this._room.pathManager.currentPathName = u,
  54. this._room.updateCurrentState({
  55. pathName: u
  56. })),
  57. f && this.udpateSkinInfo(f),
  58. h && this._room.updateCurrentState({
  59. areaName: h
  60. }),
  61. c) {
  62. const d = this._room.skin.routeList.find(g=>g.areaName === this._room.currentState.areaName)
  63. , _ = ((d == null ? void 0 : d.step) || 7.5) * 30;
  64. this._room.updateCurrentState({
  65. speed: _,
  66. attitude: c
  67. }),
  68. this._room.pathManager.currentAttitude = c,
  69. this._room._userAvatar && (this._room._userAvatar.motionType = c)
  70. }
  71. this._room.sceneManager.getCurrentShaderMode() !== ECurrentShaderMode.pano && !this._room.isPano && o.playerState.camera && this._room.camera.setCameraPose(o.playerState.camera)
  72. }
  73. if (o != null && o.renderInfo && this._room.camera.handleRenderInfo(o),
  74. n.actionType !== void 0) {
  75. const {actionType: u, code: c, echoMsg: h, traceId: f} = n;
  76. u === Actions.Echo && c === Codes$1.Success && this._room.networkController.rtcp.heartbeat.pong(h, f),
  77. c !== Codes$1.Success ? eventsManager.remove(f, c) : [Actions.GetReserveStatus, Actions.Broadcast, Actions.ChangeNickname, Actions.ConfirmEvent, Actions.ReserveSeat, Actions.Rotation, Actions.TurnTo, Actions.RotateTo, Actions.SetPlayerState, Actions.GetNeighborPoints, Actions.TurnToFace, Actions.AudienceChangeToVisitor, Actions.RemoveVisitor, Actions.GetUserWithAvatar].includes(u) && eventsManager.remove(f, c, n)
  78. }
  79. }
  80. handleActionResponses(e) {
  81. !(e != null && e.actionResponses) || e.actionResponses.length === 0 || e.actionResponses.forEach(t=>{
  82. if (t.actionType == null)
  83. return;
  84. const {pointType: r, extra: n, actionType: o, traceId: a, code: s, msg: l} = t;
  85. o === Actions.GetNeighborPoints ? eventsManager.remove(a, s, t.nps) : o === Actions.GetUserWithAvatar ? eventsManager.remove(a, s, t.userWithAvatarList) : eventsManager.remove(a, s, l),
  86. r === PointType.Path && o === Actions.Clicking && (this._room.moveToExtra = decodeURIComponent(n))
  87. }
  88. )
  89. }
  90. async udpateSkinInfo(e) {
  91. this._room.updateCurrentState({
  92. skinId: e
  93. });
  94. const t = await this._room.skinList.find(r=>r.id === e);
  95. t && this._room.updateCurrentState({
  96. skin: t
  97. })
  98. }
  99. }