statuses swapping fixes

This commit is contained in:
Piotr 'pwh' Hanusiak 2022-04-19 12:27:39 +02:00
parent 7385ce522f
commit 92c79a89fe
6 changed files with 35 additions and 17 deletions

View File

@ -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());
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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([

View File

@ -179,6 +179,7 @@ function createVideoConstraintStore() {
};
}
export const previousAvailabilityStatusStore = writable(AvailabilityStatus.ONLINE);
export const availabilityStatusStore = writable(AvailabilityStatus.ONLINE);
export const videoConstraintStore = createVideoConstraintStore();

View File

@ -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 {