-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
53 lines (49 loc) · 1.28 KB
/
app.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<template>
<NuxtLayout>
<NuxtPage />
<NuxtLoadingIndicator />
<Notification v-if="notification._id" />
<Setting v-if="isSetting" />
<Toast />
</NuxtLayout>
</template>
<script setup>
const toast = useToast();
const notification = useNotification();
const isSetting = settingStatus();
const user = userStore();
const socket = useSocket();
const handleStatus = e => {
if (e.type === "offline") {
toast.value.push("It looks like you are offline")
} else {
toast.value.push("Internet connection restored")
}
}
onMounted(() => {
window.addEventListener("offline", handleStatus)
window.addEventListener("online", handleStatus)
const audioNotification = new Audio("/sfx/messages.mp3")
socket.value.on("notification", newNotification => {
if (user._id != newNotification.from._id) {
notification.value = newNotification;
audioNotification.play();
}
});
})
onUnmounted(() => {
window.removeEventListener("offline", handleStatus);
window.removeEventListener("online", handleStatus);
socket.value.off("notification");
})
</script>
<style>
.page-enter-active,
.page-leave-active {
transition: all 0.1s;
}
.page-enter-from,
.page-leave-to {
opacity: 0
}
</style>