Merge branch 'develop' of https://github.com/thecodingmachine/workadventure into iframe-api-refactor

This commit is contained in:
jonny 2021-05-28 00:52:42 +02:00
commit 6a90655c44
97 changed files with 3195 additions and 706 deletions

View file

@ -1,9 +1,14 @@
import { Subject } from "rxjs";
import type { GoToPageEvent } from "./Api/Events/GoToPageEvent";
import { IframeResponseEventMap, isIframeResponseEventWrapper } from "./Api/Events/IframeEvent";
import type { LoadSoundEvent } from "./Api/Events/LoadSoundEvent";
import type { OpenCoWebSiteEvent } from "./Api/Events/OpenCoWebSiteEvent";
import type { OpenTabEvent } from "./Api/Events/OpenTabEvent";
import type { PlaySoundEvent } from "./Api/Events/PlaySoundEvent";
import type { StopSoundEvent } from "./Api/Events/StopSoundEvent";
import { isUserInputChatEvent, UserInputChatEvent } from "./Api/Events/UserInputChatEvent";
import SoundConfig = Phaser.Types.Sound.SoundConfig;
export const registeredCallbacks: { [K in keyof IframeResponseEventMap]?: {
typeChecker: Function
@ -30,6 +35,7 @@ type ObjectOfKey<Key extends ApiKeys, O = WorkadventureCommandClasses> = O exten
type ShouldAddAttribute<Key extends ApiKeys> = ObjectWithKeyOfUnion<Key>;
type WorkadventureFunctions = { [K in ApiKeys]: ObjectWithKeyOfUnion<K> extends Function ? K : never }[ApiKeys]
type WorkadventureFunctionsFilteredByRoot = { [K in WorkadventureFunctions]: ObjectOfKey<K>["addMethodsAtRoot"] extends true ? K : never }[WorkadventureFunctions]
@ -55,6 +61,7 @@ export interface WorkAdventureApi extends WorkAdventureApiFiles {
restorePlayerControls(): void;
displayBubble(): void;
removeBubble(): void;
loadSound(url: string): Sound;
}
@ -74,6 +81,41 @@ const userInputChatStream: Subject<UserInputChatEvent> = new Subject();
export class Sound {
constructor(private url: string) {
window.parent.postMessage({
"type": 'loadSound',
"data": {
url: this.url,
} as LoadSoundEvent
}, '*');
}
public play(config: SoundConfig) {
window.parent.postMessage({
"type": 'playSound',
"data": {
url: this.url,
config
} as PlaySoundEvent
}, '*');
return this.url;
}
public stop() {
window.parent.postMessage({
"type": 'stopSound',
"data": {
url: this.url,
} as StopSoundEvent
}, '*');
return this.url;
}
}
window.WA = {
disablePlayerControls(): void {
window.parent.postMessage({ 'type': 'disablePlayerControls' }, '*');
@ -100,6 +142,10 @@ window.WA = {
}, '*');
},
loadSound(url: string): Sound {
return new Sound(url);
},
goToPage(url: string): void {
window.parent.postMessage({
"type": 'goToPage',