1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-09 08:32:48 +00:00
Files
go-discord-bot/client/app/services/sound.service.ts
2022-03-29 00:35:45 -05:00

25 lines
699 B
TypeScript

import { ISound, SoundListType, SoundType } from '../model';
import { axios } from './axios.service';
const playSound = (sound: SoundType): Promise<unknown> => {
return axios.post('/api/sound/play', { name: sound.name });
};
const getSounds = async (): Promise<ISound[]> => {
const res = await axios.get('/api/sound');
return res.data.data;
};
export const playAudioInBrowser = (sound: SoundType, type: SoundListType) => {
const t = type === 'favorites' ? 'sounds' : type;
const url = `/public/${t.toLowerCase()}/` + sound.name + '.' + sound.extension;
const audio = new Audio(url);
audio.play();
};
export const SoundService = {
getSounds,
playSound,
playAudioInBrowser,
};