workadventure/front/src/Api/iframe/Sound/Sound.ts

37 lines
1,016 B
TypeScript
Raw Normal View History

import { sendToWorkadventure } from "../IframeApiContribution";
import type { LoadSoundEvent } from "../../Events/LoadSoundEvent";
import type { PlaySoundEvent } from "../../Events/PlaySoundEvent";
import type { StopSoundEvent } from "../../Events/StopSoundEvent";
2021-06-21 12:26:12 +02:00
import SoundConfig = Phaser.Types.Sound.SoundConfig;
export class Sound {
constructor(private url: string) {
sendToWorkadventure({
type: "loadSound",
data: {
2021-06-21 12:26:12 +02:00
url: this.url,
} as LoadSoundEvent,
2021-06-21 12:26:12 +02:00
});
}
public play(config: SoundConfig | undefined) {
2021-06-21 12:26:12 +02:00
sendToWorkadventure({
type: "playSound",
data: {
2021-06-21 12:26:12 +02:00
url: this.url,
config,
} as PlaySoundEvent,
2021-06-21 12:26:12 +02:00
});
return this.url;
}
public stop() {
sendToWorkadventure({
type: "stopSound",
data: {
2021-06-21 12:26:12 +02:00
url: this.url,
} as StopSoundEvent,
2021-06-21 12:26:12 +02:00
});
return this.url;
}
}