xushiting 3 vuotta sitten
vanhempi
commit
f1ecbef674
7 muutettua tiedostoa jossa 193 lisäystä ja 81 poistoa
  1. 1 0
      dist/index.html
  2. 15 0
      dist/libs/toastify.js
  3. 25 0
      src/ActionsHandler.js
  4. 40 20
      src/RotationEvent.js
  5. 94 47
      src/Signal.js
  6. 15 14
      src/XverseAvatar.js
  7. 3 0
      src/util.js

+ 1 - 0
dist/index.html

@@ -32,6 +32,7 @@
     <script src="./libs/socket.2.3.js"></script>
     <script src="./libs/events.js"></script>
     <script src="./libs/axios.min.js"></script>
+    <script src="./libs/toastify.js"></script>
     <script src="./libs/VisibilityChangeHandler.js"></script>
     <script src="./libs/decoder.js"></script>
     <script src="./libs/nipplejs.min.js"></script>

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 15 - 0
dist/libs/toastify.js


+ 25 - 0
src/ActionsHandler.js

@@ -28,6 +28,7 @@ export default class ActionsHandler {
     }
 
     async sendData(e) {
+        //console.log('发送数据:'+JSON.stringify(e))
         await this.beforeSend(e);
         const t = util.uuid();
         this.room.networkController.sendRtcData(le(oe({}, e.data), {
@@ -331,6 +332,9 @@ export default class ActionsHandler {
         }
         )
     }
+
+/***********************************************************************xst****************************************************************/
+    
     rotate({pitch: e, yaw: t}) {
         var n;
         if (this.room.disableRotate || this.room.isPano || ((n = this.room._userAvatar) == null ? void 0 : n._isChangingComponentsMode))
@@ -342,11 +346,29 @@ export default class ActionsHandler {
                 horizontal_move: -t
             }
         };
+
+        //console.log('发送数据rotate:'+JSON.stringify(r.rotation_action))
         this.sendData({
             data: r,
             sampleRate: .02
         })
     }
+    
+
+    // rotate({type: type, angle: angle}) {
+    //     //每6°一个角
+    //     for(let i=0;i<60;++i){
+    //         if(Math.abs(angle - i/60 * 2 * Math.PI)<0.01){
+    //             //找到了
+    //             this.sendData({
+
+    //             })
+    //         }
+    //     }
+    // }
+
+/*******************************************************************************************************************************************/
+
     turnTo(e) {
         const {point: t, timeout: r=2e3, offset: n=8} = e || {}
           , o = {
@@ -371,6 +393,9 @@ export default class ActionsHandler {
                 speed: n
             }
         };
+
+        console.log('发送数据rotateTo:'+JSON.stringify(o.rotate_to_action))
+
         return this.sendData({
             data: o
         })

+ 40 - 20
src/RotationEvent.js

@@ -49,27 +49,47 @@ export default class RotationEvent {
             if (!this.touchStartX || !this.touchStartY)
                 return;
             const t = e.touches[0]
-              , r = t.pageX
-              , n = t.pageY
-              , o = r - this.touchStartX
-              , a = n - this.touchStartY
-              , s = this._room.options.canvas.offsetHeight
-              , l = this._room.options.canvas.offsetWidth;
-            let u = 2 * a / s
-              , c = 2 * o / l;
-            u > 1 && (u = 1),
-            c > 1 && (c = 1),
+            //   , r = t.pageX
+            //   , n = t.pageY
+            //   , o = r - this.touchStartX
+            //   , a = n - this.touchStartY
+            //   , s = this._room.options.canvas.offsetHeight
+            //   , l = this._room.options.canvas.offsetWidth;
+            const pageX = t.pageX
+            const pageY = t.pageY
+            const offsetX = pageX - this.touchStartX
+            const offsetY = pageY - this.touchStartY
+            const offsetHeight = this._room.options.canvas.offsetHeight
+            const offsetWidth = this._room.options.canvas.offsetWidth
+
+            let pitch = 2 * offsetY / offsetHeight;
+            let yaw = 2 * offsetX / offsetWidth;
+
+            pitch > 1 && (pitch = 1);
+            yaw > 1 && (yaw = 1);
+
             this._room.actionsHandler.rotate({
-                pitch: u,
-                yaw: c
-            }),
-            this.touchStartX = r,
-            this.touchStartY = n,
-            this._room.emit("touchMove", {
-                pitch: u,
-                yaw: c,
-                event: e
-            })
+                pitch: pitch,
+                yaw: yaw
+            });
+/***********************************************************************xst****************************************************************/
+            // let angle = offsetX / offsetWidth * 2 * Math.PI
+            // this._room.actionsHandler.rotate({
+            //     type: 'rotate',
+            //     angle: angle
+            // });
+/********************************************************************************************************************************************/           
+            
+            this.touchStartX = pageX;
+            this.touchStartY = pageY;
+
+/***********************************************************************xst****************************************************************/
+            // this._room.emit("touchMove", {
+            //     pitch: pitch,
+            //     yaw: yaw,
+            //     event: e
+            // })
+/********************************************************************************************************************************************/ 
         }
         );
         E(this, "handleTouchEnd", e=>{

+ 94 - 47
src/Signal.js

@@ -4,6 +4,7 @@ import ECurrentShaderMode from "./enum/ECurrentShaderMode.js"
 import Actions from "./enum/Actions.js"
 import PointType from "./enum/PointType.js"
 import Logger from "./Logger.js"
+import util from "./util.js"
 
 const logger = new Logger('xverse-signal')
 export default class Signal {
@@ -13,14 +14,17 @@ export default class Signal {
         this._room = e
     }
     handleSignal(e) {
-        var a, s, l;
+        var a, s, newUserStates;
         if (!this.signalHandleActived)
+        {
             return;
-        const {signal: t, alreadyUpdateYUV: r} = e;
-        if (this.handleActionResponses(t),
-        this._room.handleSignalHook(t),
-        !r) {
-            const u = (a = t.newUserStates) == null ? void 0 : a.find(c=>c.userId === this._room.userId);
+        }
+        const {signal: signal, alreadyUpdateYUV: alreadyUpdateYUV} = e;
+        this.handleActionResponses(signal);
+        //this._room.handleSignalHook(signal);
+        //视频流没有传送就不能执行
+        if (!alreadyUpdateYUV) {
+            const u = (a = signal.newUserStates) == null ? void 0 : a.find(c=>c.userId === this._room.userId);
             if ((u == null ? void 0 : u.renderInfo) && ((s = this._room._userAvatar) == null ? void 0 : s.isMoving)) {
                 logger.debug("stream stoped, make avatar to stop");
                 const {isMoving: c, isRotating: h} = u.renderInfo;
@@ -32,66 +36,109 @@ export default class Signal {
             }
             return
         }
-        this.isUpdatedYUV = r;
-        const n = t;
-        if (!t) {
+
+
+        this.isUpdatedYUV = alreadyUpdateYUV;
+        const receiveSignal = signal;
+        if (!signal) {
             logger.warn("metadata signal is empty");
             return
         }
-        if (n.code === Codes.RepeatLogin) {
+        if (receiveSignal.code === Codes.RepeatLogin) {
             this._room.handleRepetLogin();
             return
         }
-        n.code !== void 0 && n.code !== Codes.Success && n.code !== Codes.ActionMaybeDelay && n.code !== Codes.DoActionBlocked && n.code !== Codes.GetOnVehicle && (logger.error("signal errcode: ", n),
-        this._room.emit("error", n));
-        const o = (l = n.newUserStates) == null ? void 0 : l.find(u=>u.userId === this._room.userId);
-        if (n.broadcastAction)
+        if(receiveSignal.code !== void 0 && receiveSignal.code !== Codes.Success && receiveSignal.code !== Codes.ActionMaybeDelay && receiveSignal.code !== Codes.DoActionBlocked && receiveSignal.code !== Codes.GetOnVehicle){
+            logger.error("signal errcode: ", receiveSignal)
+            this._room.emit("error", receiveSignal)
+        }
+        newUserStates = receiveSignal.newUserStates
+        let currentUserStates = void 0 
+        if(newUserStates != null){
+            currentUserStates = newUserStates.find(u=>u.userId === this._room.userId);
+        }
+        
+        if (receiveSignal.broadcastAction)
+        {
             try {
-                const u = JSON.parse(n.broadcastAction.data);
+                const u = JSON.parse(receiveSignal.broadcastAction.data);
                 Broadcast.handlers.forEach(c=>c(u))
             } catch (u) {
                 logger.error(u)
             }
-        if (n.newUserStates && n.newUserStates.length > 0 && this._room.avatarManager.handleAvatar(n),
-        o != null && o.playerState) {
-            this._room._currentClickingState = o.playerState;
-            const {pathName: u, attitude: c, areaName: h, skinId: f} = o.playerState;
-            if (u && (this._room.pathManager.currentPathName = u,
-            this._room.updateCurrentState({
-                pathName: u
-            })),
-            f && this.udpateSkinInfo(f),
-            h && this._room.updateCurrentState({
-                areaName: h
-            }),
-            c) {
+        }
+        receiveSignal.newUserStates && receiveSignal.newUserStates.length > 0 && this._room.avatarManager.handleAvatar(receiveSignal);
+        if (currentUserStates != null && currentUserStates.playerState) {
+            this._room._currentClickingState = currentUserStates.playerState;
+            const {pathName: pathName, attitude: attitude, areaName: areaName, skinId: skinId} = currentUserStates.playerState;
+
+            if(pathName){
+                this._room.pathManager.currentPathName = pathName;
+                this._room.updateCurrentState({
+                    pathName: pathName
+                })
+            }
+            skinId && this.udpateSkinInfo(skinId);
+            areaName && this._room.updateCurrentState({
+                areaName: areaName
+            });
+
+            if (attitude) {
                 const d = this._room.skin.routeList.find(g=>g.areaName === this._room.currentState.areaName)
-                  , _ = ((d == null ? void 0 : d.step) || 7.5) * 30;
+                const speed = ((d == null ? void 0 : d.step) || 7.5) * 30;
                 this._room.updateCurrentState({
-                    speed: _,
-                    attitude: c
+                    speed: speed,
+                    attitude: attitude
                 }),
-                this._room.pathManager.currentAttitude = c,
-                this._room._userAvatar && (this._room._userAvatar.motionType = c)
+                this._room.pathManager.currentAttitude = attitude,
+                this._room._userAvatar && (this._room._userAvatar.motionType = attitude)
+            }
+            if(this._room.sceneManager.getCurrentShaderMode() !== ECurrentShaderMode.pano && !this._room.isPano && currentUserStates.playerState.camera){
+                this._room.camera.setCameraPose(currentUserStates.playerState.camera)
+
+                //console.log('接收数据setCameraPose:'+JSON.stringify(currentUserStates.playerState.camera.angle))
+                console.log('我们计算:'+ util.ue4Rotation2Xverse(currentUserStates.playerState.camera.angle).y/Math.PI*180)
             }
-            this._room.sceneManager.getCurrentShaderMode() !== ECurrentShaderMode.pano && !this._room.isPano && o.playerState.camera && this._room.camera.setCameraPose(o.playerState.camera)
         }
-        if (o != null && o.renderInfo && this._room.camera.handleRenderInfo(o),
-        n.actionType !== void 0) {
-            const {actionType: u, code: c, echoMsg: h, traceId: f} = n;
-            u === Actions.Echo && c === Codes.Success && this._room.networkController.rtcp.heartbeat.pong(h, f),
-            c !== Codes.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)
+        currentUserStates != null && currentUserStates.renderInfo && this._room.camera.handleRenderInfo(currentUserStates)
+        if (receiveSignal.actionType !== void 0) {
+            const {actionType: actionType, code: code, echoMsg: echoMsg, traceId: traceId} = receiveSignal;
+            if(actionType === Actions.Echo && code === Codes.Success){
+                this._room.networkController.rtcp.heartbeat.pong(echoMsg, traceId)
+            }
+
+            if(code !== Codes.Success){
+                eventsManager.remove(traceId, code)
+            }
+            else if([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(actionType)){
+                eventsManager.remove(traceId, code, receiveSignal)
+            }
         }
     }
-    handleActionResponses(e) {
-        !(e != null && e.actionResponses) || e.actionResponses.length === 0 || e.actionResponses.forEach(t=>{
-            if (t.actionType == null)
-                return;
-            const {pointType: r, extra: n, actionType: o, traceId: a, code: s, msg: l} = t;
-            o === Actions.GetNeighborPoints ? eventsManager.remove(a, s, t.nps) : o === Actions.GetUserWithAvatar ? eventsManager.remove(a, s, t.userWithAvatarList) : eventsManager.remove(a, s, l),
-            r === PointType.Path && o === Actions.Clicking && (this._room.moveToExtra = decodeURIComponent(n))
+    handleActionResponses(responseData) {
+
+        if(responseData != null && responseData.actionResponses&&responseData.actionResponses.length != 0){
+            responseData.actionResponses.forEach(actionResponse=>{
+                if (actionResponse.actionType == null)
+                {
+                    return;
+                }
+                const {pointType: pointType, extra: extra, actionType: actionType, traceId: traceId, code: code, msg: msg} = actionResponse;
+                if(actionType === Actions.GetNeighborPoints){
+                    eventsManager.remove(traceId, code, actionResponse.nps)
+                }
+                else if(actionType === Actions.GetUserWithAvatar){
+                    eventsManager.remove(traceId, code, actionResponse.userWithAvatarList)
+                }
+                else{
+                    eventsManager.remove(traceId, code, msg)
+                }
+
+                if(pointType === PointType.Path && actionType === Actions.Clicking){
+                    this._room.moveToExtra = decodeURIComponent(extra)
+                }
+            })
         }
-        )
     }
     async udpateSkinInfo(e) {
         this._room.updateCurrentState({

+ 15 - 14
src/XverseAvatar.js

@@ -444,28 +444,29 @@ export default class XverseAvatar extends EventEmitter {
         var t, r, n;
         try {
             if ((t = e.event) != null && t.rotateEvent) {
-                const {angle: o, speed: a} = e.event.rotateEvent
-                  , s = this.motionType === MotionType.Run ? "Running" : "Walking";
-                this.rotation && (this.rotation.yaw = this.rotation.yaw % 360,
-                o.yaw - this.rotation.yaw > 180 && (o.yaw = 180 - o.yaw),
-                this.isRotating = !0,
-                await this.xAvatar.rotateTo(o, this.rotation, s).then(()=>{
-                    this._playAnimation("Idle", !0),
-                    this.isRotating = !1
+                const {angle: angle, speed: speed} = e.event.rotateEvent
+                const motionType = this.motionType === MotionType.Run ? "Running" : "Walking";
+                if(this.rotation){
+                    this.rotation.yaw = this.rotation.yaw % 360;
+                    angle.yaw - this.rotation.yaw > 180 && (angle.yaw = 180 - angle.yaw);
+                    this.isRotating = !0;
+                    await this.xAvatar.rotateTo(angle, this.rotation, motionType).then(()=>{
+                        this._playAnimation("Idle", !0);
+                        this.isRotating = !1;
+                    })
                 }
-                ))
             }
             if (e.event && (((r = e.event) == null ? void 0 : r.points.length) || 0) > 1 && !this.isSelf) {
-                this.isMoving = !0,
+                this.isMoving = !0;
                 e.playerState.attitude && (this._motionType = e.playerState.attitude);
-                const o = this.motionType === MotionType.Run ? "Running" : "Walking"
+                const motionType = this.motionType === MotionType.Run ? "Running" : "Walking"
                   , a = this._room.skin.routeList.find(l=>l.areaName === this._room.currentState.areaName)
-                  , s = ((a == null ? void 0 : a.step) || 7.5) * 30 * (25 / 30);
+                  , speed = ((a == null ? void 0 : a.step) || 7.5) * 30 * (25 / 30);
                 this.position && await this._move({
                     start: this.position,
                     end: e.event.points[e.event.points.length - 1],
-                    walkSpeed: s,
-                    moveAnimation: o,
+                    walkSpeed: speed,
+                    moveAnimation: motionType,
                     inter: (n = e.event) == null ? void 0 : n.points.slice(0, -1)
                 }).then(()=>{
                     this.isMoving = !1

+ 3 - 0
src/util.js

@@ -103,6 +103,7 @@ var util = {
         return Math.sqrt(Math.abs(t - o) ** 2 + Math.abs(r - a) ** 2 + Math.abs(n - s) ** 2)
     }
     , 
+    //pitch,yaw,roll转rotation
     ue4Rotation2Xverse(i){
         if(this.isRotationCorrect(i)){
             if(i.pitch >= 89.5){
@@ -123,6 +124,7 @@ var util = {
             return null
         }
     },
+
     ue4Rotation2Xverse_mesh(i){
         if(this.isRotationCorrect(i)){
             if(Math.abs(Math.PI * i.roll) / 180 < .001){
@@ -154,6 +156,7 @@ var util = {
             return null;
         }
     },
+    //rotation转成pitch,yaw,roll
     xversePosition2Ue4(i){
         if(this.isPositionCorrect(i)){
             return {