From 92c79a89fea62e397c138687737358f064e9cbc7 Mon Sep 17 00:00:00 2001
From: Piotr 'pwh' Hanusiak
Date: Tue, 19 Apr 2022 12:27:39 +0200
Subject: [PATCH] statuses swapping fixes
---
back/src/Model/User.ts | 6 +++--
.../src/Phaser/Components/PlayerStatusDot.ts | 3 ++-
.../Phaser/Game/GameMapPropertiesListener.ts | 23 +++++++++++++------
front/src/Phaser/Game/GameScene.ts | 10 +++++---
front/src/Stores/MediaStore.ts | 1 +
messages/protos/messages.proto | 9 ++++----
6 files changed, 35 insertions(+), 17 deletions(-)
diff --git a/back/src/Model/User.ts b/back/src/Model/User.ts
index 404f4e52..b103f240 100644
--- a/back/src/Model/User.ts
+++ b/back/src/Model/User.ts
@@ -139,8 +139,10 @@ export class User implements Movable {
this.voiceIndicatorShown = details.getShowvoiceindicator()?.getValue();
const status = details.getStatus();
- if (status !== undefined) {
+ let sendStatusUpdate = false;
+ if (status && status !== this.status) {
this.status = status;
+ sendStatusUpdate = true;
}
const playerDetails = new SetPlayerDetailsMessage();
@@ -151,7 +153,7 @@ export class User implements Movable {
if (this.voiceIndicatorShown !== undefined) {
playerDetails.setShowvoiceindicator(new BoolValue().setValue(this.voiceIndicatorShown));
}
- if (details.getStatus() !== undefined) {
+ if (sendStatusUpdate) {
playerDetails.setStatus(details.getStatus());
}
diff --git a/front/src/Phaser/Components/PlayerStatusDot.ts b/front/src/Phaser/Components/PlayerStatusDot.ts
index a886cdbb..585f6360 100644
--- a/front/src/Phaser/Components/PlayerStatusDot.ts
+++ b/front/src/Phaser/Components/PlayerStatusDot.ts
@@ -13,6 +13,7 @@ export class PlayerStatusDot extends Phaser.GameObjects.Container {
[AvailabilityStatus.SILENT]: { filling: 0xe74c3c, outline: 0xc0392b },
[AvailabilityStatus.JITSI]: { filling: 0x74b9ff, outline: 0x0984e3 },
[AvailabilityStatus.UNRECOGNIZED]: { filling: 0xffffff, outline: 0xffffff },
+ [AvailabilityStatus.UNCHANGED]: { filling: 0xffffff, outline: 0xffffff },
};
constructor(scene: Phaser.Scene, x: number, y: number) {
@@ -31,7 +32,7 @@ export class PlayerStatusDot extends Phaser.GameObjects.Container {
}
public setStatus(status: AvailabilityStatus, instant: boolean = false): void {
- if (this.status === status) {
+ if (this.status === status || status === AvailabilityStatus.UNCHANGED) {
return;
}
this.status = status;
diff --git a/front/src/Phaser/Game/GameMapPropertiesListener.ts b/front/src/Phaser/Game/GameMapPropertiesListener.ts
index a74b1be4..562aa6f7 100644
--- a/front/src/Phaser/Game/GameMapPropertiesListener.ts
+++ b/front/src/Phaser/Game/GameMapPropertiesListener.ts
@@ -18,7 +18,7 @@ import { iframeListener } from "../../Api/IframeListener";
import { Room } from "../../Connexion/Room";
import LL from "../../i18n/i18n-svelte";
import { AvailabilityStatus } from "../../Messages/ts-proto-generated/protos/messages";
-import { availabilityStatusStore } from "../../Stores/MediaStore";
+import { availabilityStatusStore, previousAvailabilityStatusStore } from "../../Stores/MediaStore";
interface OpenCoWebsite {
actionId: string;
@@ -67,9 +67,9 @@ export class GameMapPropertiesListener {
coWebsiteManager.closeCoWebsite(coWebsite);
}
});
- this.scene.connection?.emitPlayerStatusChange(AvailabilityStatus.ONLINE);
- availabilityStatusStore.set(AvailabilityStatus.ONLINE);
- this.scene.CurrentPlayer.setStatus(AvailabilityStatus.ONLINE);
+ const newStatus = this.swapAvailabilityStatuses();
+ this.scene.connection?.emitPlayerStatusChange(newStatus);
+ this.scene.CurrentPlayer.setStatus(newStatus);
} else {
const openJitsiRoomFunction = () => {
const roomName = jitsiFactory.getRoomName(newValue.toString(), this.scene.instance);
@@ -113,6 +113,7 @@ export class GameMapPropertiesListener {
});
} else {
openJitsiRoomFunction();
+ previousAvailabilityStatusStore.set(get(availabilityStatusStore));
this.scene.connection?.emitPlayerStatusChange(AvailabilityStatus.JITSI);
availabilityStatusStore.set(AvailabilityStatus.JITSI);
this.scene.CurrentPlayer.setStatus(AvailabilityStatus.JITSI);
@@ -151,10 +152,11 @@ export class GameMapPropertiesListener {
});
this.gameMap.onPropertyChange(GameMapProperties.SILENT, (newValue) => {
+ const newStatus = this.swapAvailabilityStatuses();
if (newValue === undefined || newValue === false || newValue === "") {
- this.scene.connection?.emitPlayerStatusChange(AvailabilityStatus.ONLINE);
- availabilityStatusStore.set(AvailabilityStatus.ONLINE);
- this.scene.CurrentPlayer.setStatus(AvailabilityStatus.ONLINE);
+ availabilityStatusStore.set(newStatus);
+ this.scene.connection?.emitPlayerStatusChange(newStatus);
+ this.scene.CurrentPlayer.setStatus(newStatus);
} else {
this.scene.connection?.emitPlayerStatusChange(AvailabilityStatus.SILENT);
availabilityStatusStore.set(AvailabilityStatus.SILENT);
@@ -378,4 +380,11 @@ export class GameMapPropertiesListener {
handler();
});
}
+
+ private swapAvailabilityStatuses(): AvailabilityStatus {
+ const newStatus = get(previousAvailabilityStatusStore);
+ previousAvailabilityStatusStore.set(get(availabilityStatusStore));
+ availabilityStatusStore.set(newStatus);
+ return newStatus;
+ }
}
diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts
index d6d66f9e..3419b5b1 100644
--- a/front/src/Phaser/Game/GameScene.ts
+++ b/front/src/Phaser/Game/GameScene.ts
@@ -91,7 +91,7 @@ import { MapStore } from "../../Stores/Utils/MapStore";
import { followUsersColorStore } from "../../Stores/FollowStore";
import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler";
import { locale } from "../../i18n/i18n-svelte";
-import { availabilityStatusStore, localVolumeStore } from "../../Stores/MediaStore";
+import { availabilityStatusStore, localVolumeStore, previousAvailabilityStatusStore } from "../../Stores/MediaStore";
import { StringUtils } from "../../Utils/StringUtils";
import { startLayerNamesStore } from "../../Stores/StartLayerNamesStore";
import { JitsiCoWebsite } from "../../WebRtc/CoWebsite/JitsiCoWebsite";
@@ -709,9 +709,13 @@ export class GameScene extends DirtyScene {
});
this.privacyShutdownStoreUnsubscribe = privacyShutdownStore.subscribe((away) => {
- const status = away ? AvailabilityStatus.AWAY : AvailabilityStatus.ONLINE;
- this.connection?.emitPlayerStatusChange(status);
+ if ([AvailabilityStatus.SILENT, AvailabilityStatus.JITSI].includes(get(availabilityStatusStore))) {
+ return;
+ }
+ const status = away ? AvailabilityStatus.AWAY : get(previousAvailabilityStatusStore);
+ previousAvailabilityStatusStore.set(get(availabilityStatusStore));
availabilityStatusStore.set(status);
+ this.connection?.emitPlayerStatusChange(status);
});
Promise.all([
diff --git a/front/src/Stores/MediaStore.ts b/front/src/Stores/MediaStore.ts
index 27454acf..a7519952 100644
--- a/front/src/Stores/MediaStore.ts
+++ b/front/src/Stores/MediaStore.ts
@@ -179,6 +179,7 @@ function createVideoConstraintStore() {
};
}
+export const previousAvailabilityStatusStore = writable(AvailabilityStatus.ONLINE);
export const availabilityStatusStore = writable(AvailabilityStatus.ONLINE);
export const videoConstraintStore = createVideoConstraintStore();
diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto
index 7ca26793..8317d829 100644
--- a/messages/protos/messages.proto
+++ b/messages/protos/messages.proto
@@ -5,10 +5,11 @@ import "google/protobuf/wrappers.proto";
/*********** PARTIAL MESSAGES **************/
enum AvailabilityStatus {
- ONLINE = 0;
- SILENT = 1;
- AWAY = 2;
- JITSI = 3;
+ UNCHANGED = 0;
+ ONLINE = 1;
+ SILENT = 2;
+ AWAY = 3;
+ JITSI = 4;
}
message PositionMessage {