|
@@ -102,20 +102,20 @@ export default class XverseAvatarManager extends EventEmitter {
|
|
|
|
|
|
async _handleAvatar(newUserStates) {
|
|
|
|
|
|
- newUserStates == null || newUserStates.forEach(state=>{
|
|
|
+ newUserStates && newUserStates.forEach(state=>{
|
|
|
|
|
|
const isMainAvatar = this._room.userId === state.userId;
|
|
|
|
|
|
- if ((state.event != null && state.event.type) === SyncEventType.ET_RemoveVisitor)
|
|
|
+ if (state.event && state.event.type === SyncEventType.ET_RemoveVisitor)
|
|
|
{
|
|
|
- const removeVisitorEvent = state.event != null && state.event.removeVisitorEvent
|
|
|
- const event = removeVisitorEvent!= null && removeVisitorEvent.removeVisitorEvent
|
|
|
- , extraInfo = JSON.parse(safeDecodeURIComponent((removeVisitorEvent != null && removeVisitorEvent.extraInfo) || ""))
|
|
|
+ const removeVisitorEvent = state.event.removeVisitorEvent
|
|
|
+ const event = removeVisitorEvent && removeVisitorEvent.removeVisitorEvent
|
|
|
+ , extraInfo = JSON.parse(safeDecodeURIComponent((removeVisitorEvent && removeVisitorEvent.extraInfo) || ""))
|
|
|
, { code, msg } = extraInfo;
|
|
|
|
|
|
event === RemoveVisitorType.RVT_ChangeToObserver
|
|
|
? this._room.audienceViewModeHook()
|
|
|
- : event === RemoveVisitorType.RVT_MoveOutOfTheRoom && this._room.leave()
|
|
|
+ : event === RemoveVisitorType.RVT_MoveOutOfTheRoom && this._room.leave() // 这里会触发Actions.Exit
|
|
|
|
|
|
this._room.emit("visitorStatusChanged", { code, msg })
|
|
|
}
|
|
@@ -123,17 +123,19 @@ export default class XverseAvatarManager extends EventEmitter {
|
|
|
if (state.event && [SyncEventType.Appear, SyncEventType.Reset].includes(state.event.type) || !state.event) {
|
|
|
|
|
|
let avatar = this.avatars.get(state.userId);
|
|
|
- if(state.playerState.avatarId && avatar != null && avatar.avatarId !== state.playerState.avatarId) {
|
|
|
+ if(state.playerState.avatarId && avatar && avatar.avatarId !== state.playerState.avatarId) {
|
|
|
avatar = void 0
|
|
|
this.removeAvatar(state.userId)
|
|
|
}
|
|
|
|
|
|
if (avatar) {
|
|
|
- if (avatar.disconnected && avatar.setConnectionStatus(!1),
|
|
|
- state.event != null && state.event.id && this._room.actionsHandler.confirmEvent(state.event.id),
|
|
|
- state.playerState.nickName && (avatar == null || avatar._setNickname(state.playerState.nickName)),
|
|
|
- state.playerState.avatarComponents && !avatar.isSelf && avatar.xAvatar) {
|
|
|
+ avatar.disconnected && avatar.setConnectionStatus(!1)
|
|
|
+ state.event && state.event.id && this._room.actionsHandler.confirmEvent(state.event.id) // 这里会触发Actions.ConfirmEvent
|
|
|
+ state.playerState.nickName && (avatar && avatar._setNickname(state.playerState.nickName))
|
|
|
+
|
|
|
+ if (state.playerState.avatarComponents && !avatar.isSelf && avatar.xAvatar) {
|
|
|
const avatarComponents = safeParseComponents(state.playerState.avatarComponents);
|
|
|
+ // 这里会触发Actions.SetPlayerState
|
|
|
avatar._changeComponents({
|
|
|
avatarComponents,
|
|
|
mode: ChangeComponentsMode.Preview
|
|
@@ -164,7 +166,7 @@ export default class XverseAvatarManager extends EventEmitter {
|
|
|
prioritySync,
|
|
|
extraInfo
|
|
|
}).then(()=>{
|
|
|
- state.event != null && state.event.id && this._room.actionsHandler.confirmEvent(state.event.id),
|
|
|
+ state.event && state.event.id && this._room.actionsHandler.confirmEvent(state.event.id), // 这里会触发Actions.ConfirmEvent
|
|
|
this.updateAvatarPositionAndRotation(state),
|
|
|
isMainAvatar && (
|
|
|
this.xAvatarManager.setMainAvatar(state.userId),
|
|
@@ -182,17 +184,17 @@ export default class XverseAvatarManager extends EventEmitter {
|
|
|
}
|
|
|
|
|
|
if(state.event && SyncEventType.Disappear === state.event.type) {
|
|
|
- state.event.id && this._room.actionsHandler.confirmEvent(state.event.id)
|
|
|
+ state.event.id && this._room.actionsHandler.confirmEvent(state.event.id) // 这里会触发Actions.ConfirmEvent
|
|
|
this.removeAvatar(state.userId)
|
|
|
}
|
|
|
|
|
|
if (state.event && [SyncEventType.Move, SyncEventType.ChangeRenderInfo].includes(state.event.type) || !state.event) {
|
|
|
- state.event != null && state.event.id && this._room.actionsHandler.confirmEvent(state.event.id);
|
|
|
+ state.event && state.event.id && this._room.actionsHandler.confirmEvent(state.event.id); // 这里会触发Actions.ConfirmEvent
|
|
|
const avatar = this.avatars.get(state.userId);
|
|
|
avatar && avatar.withModel && !avatar.isLoading && this.updateAvatarPositionAndRotation(state)
|
|
|
}
|
|
|
|
|
|
- if (!isMainAvatar && state.event != null && state.event.type === SyncEventType.Rotate) {
|
|
|
+ if (!isMainAvatar && state.event && state.event.type === SyncEventType.Rotate) {
|
|
|
const avatar = this.avatars.get(state.userId);
|
|
|
avatar.statusSyncQueue.append({
|
|
|
type: QueueType.Rotate,
|
|
@@ -206,31 +208,34 @@ export default class XverseAvatarManager extends EventEmitter {
|
|
|
var n;
|
|
|
return e === this._room.userId ? EAvatarRelationRank.Self : (n = this._room.options.firends) != null && n.includes(e) ? EAvatarRelationRank.Friend : EAvatarRelationRank.Stranger
|
|
|
}
|
|
|
- updateAvatarPositionAndRotation(e) {
|
|
|
- var t, r;
|
|
|
- if ((t = e == null ? void 0 : e.playerState) != null && t.player) {
|
|
|
- let {position: n, angle: o} = e.playerState.player;
|
|
|
- const a = this.avatars.get(e.userId);
|
|
|
- if (!a)
|
|
|
- return;
|
|
|
- if (n = positionPrecisionProtect(n),
|
|
|
- o = rotationPrecisionProtect(o),
|
|
|
- a.isSelf && !this._room.networkController.rtcp.workers.inPanoMode && (a.setPosition(n),
|
|
|
- a.setRotation(o)),
|
|
|
- e.event && (((r = e.event) == null ? void 0 : r.points.length) || 0) > 1 && !a.isSelf && a.statusSyncQueue.append({
|
|
|
+
|
|
|
+ updateAvatarPositionAndRotation(userState)
|
|
|
+ {
|
|
|
+ if (userState.playerState && userState.playerState.player)
|
|
|
+ {
|
|
|
+ let {position, angle} = userState.playerState.player;
|
|
|
+ const avatar = this.avatars.get(userState.userId);
|
|
|
+ if (!avatar) return;
|
|
|
+
|
|
|
+ position = positionPrecisionProtect(position)
|
|
|
+ angle = rotationPrecisionProtect(angle)
|
|
|
+ avatar.isSelf && !this._room.networkController.rtcp.workers.inPanoMode && (avatar.setPosition(position), avatar.setRotation(angle))
|
|
|
+ userState.event && (userState.event.points.length || 0) > 1 && !avatar.isSelf && avatar.statusSyncQueue.append({
|
|
|
type: QueueType.Move,
|
|
|
- action: ()=>a.statusSync(e)
|
|
|
- }),
|
|
|
- e.renderInfo && a.isSelf) {
|
|
|
- const {isMoving: s, isRotating: l} = e.renderInfo;
|
|
|
+ action: () => avatar.statusSync(userState)
|
|
|
+ })
|
|
|
+
|
|
|
+ if (userState.renderInfo && avatar.isSelf) {
|
|
|
+ const {isMoving, isRotating} = userState.renderInfo;
|
|
|
this._updateAvatarMovingStatus({
|
|
|
- id: e.userId,
|
|
|
- isMoving: !!s,
|
|
|
- isRotating: !!l
|
|
|
+ id: userState.userId,
|
|
|
+ isMoving: !!isMoving,
|
|
|
+ isRotating: !!isRotating
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
async addAvatar(e) {
|
|
|
const {userId: t, isHost: r, avatarPosition: n, avatarId: o, avatarRotation: a, nickname: s, avatarComponents: l=[], priority: u, group: c=AvatarGroup.Npc, avatarScale: h=DEFAULT_AVATAR_SCALE, extraInfo: f, prioritySync: d} = e
|
|
|
, _ = t === this._room.userId;
|
|
@@ -315,6 +320,7 @@ export default class XverseAvatarManager extends EventEmitter {
|
|
|
Promise.reject(b)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
removeAvatar(e, t=!1) {
|
|
|
const r = this.avatars.get(e);
|
|
|
if (!!r) {
|
|
@@ -329,12 +335,14 @@ export default class XverseAvatarManager extends EventEmitter {
|
|
|
r.setConnectionStatus(!0)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
clearOtherUsers() {
|
|
|
this.avatars.forEach(e=>{
|
|
|
!e.isSelf && e.group === AvatarGroup.User && this.removeAvatar(e.userId)
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
+
|
|
|
async _updateAvatarMovingStatus(e) {
|
|
|
const {id: t, isMoving: r, isRotating: n} = e
|
|
|
, o = this.avatars.get(t);
|