simpler way of handling availability statuses with stores
This commit is contained in:
parent
b0be00c020
commit
dfd9a66bd4
@ -17,8 +17,7 @@ import { audioManagerFileStore, audioManagerVisibilityStore } from "../../Stores
|
||||
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 { inJitsiStore, silentStore } from "../../Stores/MediaStore";
|
||||
|
||||
interface OpenCoWebsite {
|
||||
actionId: string;
|
||||
@ -67,7 +66,7 @@ export class GameMapPropertiesListener {
|
||||
coWebsiteManager.closeCoWebsite(coWebsite);
|
||||
}
|
||||
});
|
||||
this.changeAvailabilityStatus(AvailabilityStatus.ONLINE);
|
||||
inJitsiStore.set(false);
|
||||
} else {
|
||||
const openJitsiRoomFunction = () => {
|
||||
let addPrefix = true;
|
||||
@ -112,13 +111,13 @@ export class GameMapPropertiesListener {
|
||||
message: message,
|
||||
callback: () => {
|
||||
openJitsiRoomFunction();
|
||||
this.changeAvailabilityStatus(AvailabilityStatus.JITSI);
|
||||
inJitsiStore.set(true);
|
||||
},
|
||||
userInputManager: this.scene.userInputManager,
|
||||
});
|
||||
} else {
|
||||
openJitsiRoomFunction();
|
||||
this.changeAvailabilityStatus(AvailabilityStatus.JITSI);
|
||||
inJitsiStore.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -155,9 +154,9 @@ export class GameMapPropertiesListener {
|
||||
|
||||
this.gameMap.onPropertyChange(GameMapProperties.SILENT, (newValue) => {
|
||||
if (newValue === undefined || newValue === false || newValue === "") {
|
||||
this.changeAvailabilityStatus(AvailabilityStatus.ONLINE);
|
||||
silentStore.set(false);
|
||||
} else {
|
||||
this.changeAvailabilityStatus(AvailabilityStatus.SILENT);
|
||||
silentStore.set(true);
|
||||
}
|
||||
});
|
||||
|
||||
@ -377,10 +376,4 @@ export class GameMapPropertiesListener {
|
||||
handler();
|
||||
});
|
||||
}
|
||||
|
||||
private changeAvailabilityStatus(status: AvailabilityStatus): void {
|
||||
availabilityStatusStore.set(status);
|
||||
this.scene.connection?.emitPlayerStatusChange(status);
|
||||
this.scene.CurrentPlayer.setStatus(status);
|
||||
}
|
||||
}
|
||||
|
@ -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, awayStore, localVolumeStore } from "../../Stores/MediaStore";
|
||||
import { StringUtils } from "../../Utils/StringUtils";
|
||||
import { startLayerNamesStore } from "../../Stores/StartLayerNamesStore";
|
||||
import { JitsiCoWebsite } from "../../WebRtc/CoWebsite/JitsiCoWebsite";
|
||||
@ -100,7 +100,7 @@ import type { CoWebsite } from "../../WebRtc/CoWebsite/CoWesbite";
|
||||
import CancelablePromise from "cancelable-promise";
|
||||
import { Deferred } from "ts-deferred";
|
||||
import { SuperLoaderPlugin } from "../Services/SuperLoaderPlugin";
|
||||
import { AvailabilityStatus, PlayerDetailsUpdatedMessage } from "../../Messages/ts-proto-generated/protos/messages";
|
||||
import { PlayerDetailsUpdatedMessage } from "../../Messages/ts-proto-generated/protos/messages";
|
||||
import { privacyShutdownStore } from "../../Stores/PrivacyShutdownStore";
|
||||
export interface GameSceneInitInterface {
|
||||
initPosition: PointInterface | null;
|
||||
@ -681,6 +681,11 @@ export class GameScene extends DirtyScene {
|
||||
this.tryChangeShowVoiceIndicatorState(this.jitsiDominantSpeaker && this.jitsiParticipantsCount > 1);
|
||||
});
|
||||
|
||||
availabilityStatusStore.subscribe((status) => {
|
||||
this.connection?.emitPlayerStatusChange(status);
|
||||
this.CurrentPlayer.setStatus(status);
|
||||
});
|
||||
|
||||
this.emoteUnsubscribe = emoteStore.subscribe((emote) => {
|
||||
if (emote) {
|
||||
this.CurrentPlayer?.playEmote(emote.url);
|
||||
@ -708,12 +713,7 @@ export class GameScene extends DirtyScene {
|
||||
});
|
||||
|
||||
this.privacyShutdownStoreUnsubscribe = privacyShutdownStore.subscribe((away) => {
|
||||
if ([AvailabilityStatus.SILENT, AvailabilityStatus.JITSI].includes(get(availabilityStatusStore))) {
|
||||
return;
|
||||
}
|
||||
const status = away ? AvailabilityStatus.AWAY : AvailabilityStatus.ONLINE;
|
||||
availabilityStatusStore.set(status);
|
||||
this.connection?.emitPlayerStatusChange(status);
|
||||
awayStore.set(away);
|
||||
});
|
||||
|
||||
Promise.all([
|
||||
|
@ -180,7 +180,20 @@ function createVideoConstraintStore() {
|
||||
};
|
||||
}
|
||||
|
||||
export const availabilityStatusStore = writable(AvailabilityStatus.ONLINE);
|
||||
export const inJitsiStore = writable(false);
|
||||
export const silentStore = writable(false);
|
||||
export const awayStore = writable(false);
|
||||
|
||||
export const availabilityStatusStore = derived(
|
||||
[inJitsiStore, silentStore, awayStore],
|
||||
([$inJitsiStore, $silentStore, $awayStore]) => {
|
||||
if ($inJitsiStore) return AvailabilityStatus.JITSI;
|
||||
if ($silentStore) return AvailabilityStatus.SILENT;
|
||||
if ($awayStore) return AvailabilityStatus.AWAY;
|
||||
return AvailabilityStatus.ONLINE;
|
||||
},
|
||||
AvailabilityStatus.ONLINE
|
||||
);
|
||||
|
||||
export const videoConstraintStore = createVideoConstraintStore();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user