|
@@ -4,6 +4,7 @@ import ECurrentShaderMode from "./enum/ECurrentShaderMode.js"
|
|
import Actions from "./enum/Actions.js"
|
|
import Actions from "./enum/Actions.js"
|
|
import PointType from "./enum/PointType.js"
|
|
import PointType from "./enum/PointType.js"
|
|
import Logger from "./Logger.js"
|
|
import Logger from "./Logger.js"
|
|
|
|
+import util from "./util.js"
|
|
|
|
|
|
const logger = new Logger('xverse-signal')
|
|
const logger = new Logger('xverse-signal')
|
|
export default class Signal {
|
|
export default class Signal {
|
|
@@ -13,14 +14,17 @@ export default class Signal {
|
|
this._room = e
|
|
this._room = e
|
|
}
|
|
}
|
|
handleSignal(e) {
|
|
handleSignal(e) {
|
|
- var a, s, l;
|
|
|
|
|
|
+ var a, s, newUserStates;
|
|
if (!this.signalHandleActived)
|
|
if (!this.signalHandleActived)
|
|
|
|
+ {
|
|
return;
|
|
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)) {
|
|
if ((u == null ? void 0 : u.renderInfo) && ((s = this._room._userAvatar) == null ? void 0 : s.isMoving)) {
|
|
logger.debug("stream stoped, make avatar to stop");
|
|
logger.debug("stream stoped, make avatar to stop");
|
|
const {isMoving: c, isRotating: h} = u.renderInfo;
|
|
const {isMoving: c, isRotating: h} = u.renderInfo;
|
|
@@ -32,66 +36,109 @@ export default class Signal {
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- this.isUpdatedYUV = r;
|
|
|
|
- const n = t;
|
|
|
|
- if (!t) {
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ this.isUpdatedYUV = alreadyUpdateYUV;
|
|
|
|
+ const receiveSignal = signal;
|
|
|
|
+ if (!signal) {
|
|
logger.warn("metadata signal is empty");
|
|
logger.warn("metadata signal is empty");
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- if (n.code === Codes.RepeatLogin) {
|
|
|
|
|
|
+ if (receiveSignal.code === Codes.RepeatLogin) {
|
|
this._room.handleRepetLogin();
|
|
this._room.handleRepetLogin();
|
|
return
|
|
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 {
|
|
try {
|
|
- const u = JSON.parse(n.broadcastAction.data);
|
|
|
|
|
|
+ const u = JSON.parse(receiveSignal.broadcastAction.data);
|
|
Broadcast.handlers.forEach(c=>c(u))
|
|
Broadcast.handlers.forEach(c=>c(u))
|
|
} catch (u) {
|
|
} catch (u) {
|
|
logger.error(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)
|
|
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({
|
|
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) {
|
|
async udpateSkinInfo(e) {
|
|
this._room.updateCurrentState({
|
|
this._room.updateCurrentState({
|