diff --git a/src/components/guild/home/AudioPreviewComponent.vue b/src/components/guild/home/AudioPreviewComponent.vue
index 062d17a..0fe6e09 100644
--- a/src/components/guild/home/AudioPreviewComponent.vue
+++ b/src/components/guild/home/AudioPreviewComponent.vue
@@ -151,6 +151,7 @@
variant="outlined"
:disabled="actionBtnDisable"
:color="actionBtnDisable ? '' : 'primary'"
+ @click="playPause"
>
{
function voiceChannelSelected(value: string[]) {
voiceChannelConnecting.value = true;
if (value[0] != status.value.channel?.id) {
- connect(properties.guild.id, value[0]).then((value) => {
+ audioService.connect(properties.guild.id, value[0]).then((value) => {
if (value) {
status.value = value.data;
voiceChannelConnecting.value = false;
@@ -352,7 +355,52 @@ function voiceChannelSelected(value: string[]) {
}
function onDisconnect() {
- disconnect(properties.guild.id)
+ audioService
+ .disconnect(properties.guild.id)
+ .then((value) => {
+ if (value) {
+ status.value = value.data;
+ }
+ })
+ .catch();
+}
+
+function playPause() {
+ if (status.value.playBackInfo?.paused) {
+ audioService
+ .resume(properties.guild.id)
+ .then((value) => {
+ if (value) {
+ status.value = value.data;
+ }
+ })
+ .catch();
+ } else {
+ audioService
+ .pause(properties.guild.id)
+ .then((value) => {
+ if (value) {
+ status.value = value.data;
+ }
+ })
+ .catch();
+ }
+}
+
+function skip() {
+ audioService
+ .skip(properties.guild.id)
+ .then((value) => {
+ if (value) {
+ status.value = value.data;
+ }
+ })
+ .catch();
+}
+
+function stop() {
+ audioService
+ .stop(properties.guild.id)
.then((value) => {
if (value) {
status.value = value.data;
@@ -368,7 +416,7 @@ function timeToMMSS(time: number) {
return `${minutes}:${("0" + seconds).slice(-2)}`;
}
-getAudioStatus(properties.guild.id).then((value) => {
+audioService.getAudioStatus(properties.guild.id).then((value) => {
if (value) {
status.value = value.data;
loading.value = false;
@@ -376,7 +424,7 @@ getAudioStatus(properties.guild.id).then((value) => {
});
let interval = setInterval(() => {
- getAudioStatus(properties.guild.id).then((value) => {
+ audioService.getAudioStatus(properties.guild.id).then((value) => {
if (value) {
status.value = value.data;
}
diff --git a/src/services/audioService.ts b/src/services/audioService.ts
index 8d8a576..33e3968 100644
--- a/src/services/audioService.ts
+++ b/src/services/audioService.ts
@@ -73,4 +73,100 @@ function disconnect(guildId: string) {
});
}
-export { getAudioStatus, connect, disconnect };
+function resume(guildId: string) {
+ const userStore = useUserStore();
+ return axios
+ .post(
+ `/audio/${guildId}/resume`,
+ {},
+ {
+ headers: {
+ authorization: `Bearer ${userStore.token}`,
+ },
+ }
+ )
+ .catch((reason) => {
+ console.error(`Fail to resume playback !`);
+ console.log(reason);
+ const eventQueuStore = useEventQueuStore();
+ eventQueuStore.push({
+ uuid: undefined,
+ type: "error",
+ text: "Fail to resume playback !",
+ });
+ });
+}
+
+function pause(guildId: string) {
+ const userStore = useUserStore();
+ return axios
+ .post(
+ `/audio/${guildId}/pause`,
+ {},
+ {
+ headers: {
+ authorization: `Bearer ${userStore.token}`,
+ },
+ }
+ )
+ .catch((reason) => {
+ console.error(`Fail to pause playback !`);
+ console.log(reason);
+ const eventQueuStore = useEventQueuStore();
+ eventQueuStore.push({
+ uuid: undefined,
+ type: "error",
+ text: "Fail to pause playback !",
+ });
+ });
+}
+
+function skip(guildId: string) {
+ const userStore = useUserStore();
+ return axios
+ .post(
+ `/audio/${guildId}/skip`,
+ {},
+ {
+ headers: {
+ authorization: `Bearer ${userStore.token}`,
+ },
+ }
+ )
+ .catch((reason) => {
+ console.error(`Fail to skip playback !`);
+ console.log(reason);
+ const eventQueuStore = useEventQueuStore();
+ eventQueuStore.push({
+ uuid: undefined,
+ type: "error",
+ text: "Fail to skip playback !",
+ });
+ });
+}
+
+function stop(guildId: string) {
+ const userStore = useUserStore();
+ return axios
+ .post(
+ `/audio/${guildId}/stop`,
+ {},
+ {
+ headers: {
+ authorization: `Bearer ${userStore.token}`,
+ },
+ }
+ )
+ .catch((reason) => {
+ console.error(`Fail to stop playback !`);
+ console.log(reason);
+ const eventQueuStore = useEventQueuStore();
+ eventQueuStore.push({
+ uuid: undefined,
+ type: "error",
+ text: "Fail to stop playback !",
+ });
+ });
+}
+
+export { getAudioStatus, connect, disconnect, resume, pause, skip, stop };