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 { iframeListener } from "../../Api/IframeListener";
|
||||||
import { Room } from "../../Connexion/Room";
|
import { Room } from "../../Connexion/Room";
|
||||||
import LL from "../../i18n/i18n-svelte";
|
import LL from "../../i18n/i18n-svelte";
|
||||||
import { AvailabilityStatus } from "../../Messages/ts-proto-generated/protos/messages";
|
import { inJitsiStore, silentStore } from "../../Stores/MediaStore";
|
||||||
import { availabilityStatusStore } from "../../Stores/MediaStore";
|
|
||||||
|
|
||||||
interface OpenCoWebsite {
|
interface OpenCoWebsite {
|
||||||
actionId: string;
|
actionId: string;
|
||||||
@ -67,7 +66,7 @@ export class GameMapPropertiesListener {
|
|||||||
coWebsiteManager.closeCoWebsite(coWebsite);
|
coWebsiteManager.closeCoWebsite(coWebsite);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.changeAvailabilityStatus(AvailabilityStatus.ONLINE);
|
inJitsiStore.set(false);
|
||||||
} else {
|
} else {
|
||||||
const openJitsiRoomFunction = () => {
|
const openJitsiRoomFunction = () => {
|
||||||
let addPrefix = true;
|
let addPrefix = true;
|
||||||
@ -112,13 +111,13 @@ export class GameMapPropertiesListener {
|
|||||||
message: message,
|
message: message,
|
||||||
callback: () => {
|
callback: () => {
|
||||||
openJitsiRoomFunction();
|
openJitsiRoomFunction();
|
||||||
this.changeAvailabilityStatus(AvailabilityStatus.JITSI);
|
inJitsiStore.set(true);
|
||||||
},
|
},
|
||||||
userInputManager: this.scene.userInputManager,
|
userInputManager: this.scene.userInputManager,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
openJitsiRoomFunction();
|
openJitsiRoomFunction();
|
||||||
this.changeAvailabilityStatus(AvailabilityStatus.JITSI);
|
inJitsiStore.set(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -155,9 +154,9 @@ export class GameMapPropertiesListener {
|
|||||||
|
|
||||||
this.gameMap.onPropertyChange(GameMapProperties.SILENT, (newValue) => {
|
this.gameMap.onPropertyChange(GameMapProperties.SILENT, (newValue) => {
|
||||||
if (newValue === undefined || newValue === false || newValue === "") {
|
if (newValue === undefined || newValue === false || newValue === "") {
|
||||||
this.changeAvailabilityStatus(AvailabilityStatus.ONLINE);
|
silentStore.set(false);
|
||||||
} else {
|
} else {
|
||||||
this.changeAvailabilityStatus(AvailabilityStatus.SILENT);
|
silentStore.set(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -377,10 +376,4 @@ export class GameMapPropertiesListener {
|
|||||||
handler();
|
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 { followUsersColorStore } from "../../Stores/FollowStore";
|
||||||
import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler";
|
import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler";
|
||||||
import { locale } from "../../i18n/i18n-svelte";
|
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 { StringUtils } from "../../Utils/StringUtils";
|
||||||
import { startLayerNamesStore } from "../../Stores/StartLayerNamesStore";
|
import { startLayerNamesStore } from "../../Stores/StartLayerNamesStore";
|
||||||
import { JitsiCoWebsite } from "../../WebRtc/CoWebsite/JitsiCoWebsite";
|
import { JitsiCoWebsite } from "../../WebRtc/CoWebsite/JitsiCoWebsite";
|
||||||
@ -100,7 +100,7 @@ import type { CoWebsite } from "../../WebRtc/CoWebsite/CoWesbite";
|
|||||||
import CancelablePromise from "cancelable-promise";
|
import CancelablePromise from "cancelable-promise";
|
||||||
import { Deferred } from "ts-deferred";
|
import { Deferred } from "ts-deferred";
|
||||||
import { SuperLoaderPlugin } from "../Services/SuperLoaderPlugin";
|
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";
|
import { privacyShutdownStore } from "../../Stores/PrivacyShutdownStore";
|
||||||
export interface GameSceneInitInterface {
|
export interface GameSceneInitInterface {
|
||||||
initPosition: PointInterface | null;
|
initPosition: PointInterface | null;
|
||||||
@ -681,6 +681,11 @@ export class GameScene extends DirtyScene {
|
|||||||
this.tryChangeShowVoiceIndicatorState(this.jitsiDominantSpeaker && this.jitsiParticipantsCount > 1);
|
this.tryChangeShowVoiceIndicatorState(this.jitsiDominantSpeaker && this.jitsiParticipantsCount > 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
availabilityStatusStore.subscribe((status) => {
|
||||||
|
this.connection?.emitPlayerStatusChange(status);
|
||||||
|
this.CurrentPlayer.setStatus(status);
|
||||||
|
});
|
||||||
|
|
||||||
this.emoteUnsubscribe = emoteStore.subscribe((emote) => {
|
this.emoteUnsubscribe = emoteStore.subscribe((emote) => {
|
||||||
if (emote) {
|
if (emote) {
|
||||||
this.CurrentPlayer?.playEmote(emote.url);
|
this.CurrentPlayer?.playEmote(emote.url);
|
||||||
@ -708,12 +713,7 @@ export class GameScene extends DirtyScene {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.privacyShutdownStoreUnsubscribe = privacyShutdownStore.subscribe((away) => {
|
this.privacyShutdownStoreUnsubscribe = privacyShutdownStore.subscribe((away) => {
|
||||||
if ([AvailabilityStatus.SILENT, AvailabilityStatus.JITSI].includes(get(availabilityStatusStore))) {
|
awayStore.set(away);
|
||||||
return;
|
|
||||||
}
|
|
||||||
const status = away ? AvailabilityStatus.AWAY : AvailabilityStatus.ONLINE;
|
|
||||||
availabilityStatusStore.set(status);
|
|
||||||
this.connection?.emitPlayerStatusChange(status);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Promise.all([
|
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();
|
export const videoConstraintStore = createVideoConstraintStore();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user