From 3e5ddf90ed8a0b2c9e34b663ce330b9ad9a0a9a4 Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 3 Dec 2021 18:03:34 -0600 Subject: [PATCH] Add:Socket not connected toast --- client/layouts/default.vue | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/client/layouts/default.vue b/client/layouts/default.vue index c58a3d89..2ce40aeb 100644 --- a/client/layouts/default.vue +++ b/client/layouts/default.vue @@ -46,46 +46,41 @@ export default { } }, methods: { + updateSocketConnectionToast(content, type, timeout) { + if (this.socketConnectionToastId !== null && this.socketConnectionToastId !== undefined) { + this.$toast.update(this.socketConnectionToastId, { content: content, options: { timeout: timeout, type: type, closeButton: false, position: 'bottom-center', onClose: () => null, closeOnClick: timeout !== null } }, false) + } else { + this.socketConnectionToastId = this.$toast[type](content, { position: 'bottom-center', timeout: timeout, closeButton: false, closeOnClick: timeout !== null }) + } + }, connect() { console.log('[SOCKET] Connected') var token = this.$store.getters['user/getToken'] this.socket.emit('auth', token) - if (this.socketConnectionToastId !== null) { - this.$toast.update(this.socketConnectionToastId, { content: 'Socket Connected', options: { timeout: 5000, type: 'success', closeButton: false, position: 'bottom-center', onClose: () => null } }, true) - } else if (!this.isFirstSocketConnection) { - this.$toast.success('Socket Connected', { position: 'bottom-center' }) + if (!this.isFirstSocketConnection || this.socketConnectionToastId !== null) { + this.updateSocketConnectionToast('Socket Connected', 'success', 5000) } this.isFirstSocketConnection = false this.isSocketConnected = true }, connectError() { console.error('[SOCKET] connect error') - - // if (this.socketConnectionToastId) { - // this.$toast.update(this.socketConnectionToastId, { content: 'Socket Connection Error', options: { timeout: 5000, type: 'error', closeButton: false, position: 'bottom-center', onClose: () => null } }, true) - // } else { - // this.$toast.error('Socket Connection Error', { position: 'bottom-center' }) - // } + this.updateSocketConnectionToast('Socket Failed to Connect', 'error', null) }, disconnect() { console.log('[SOCKET] Disconnected') this.isSocketConnected = false - - if (this.socketConnectionToastId !== null) { - this.socketConnectionToastId = this.$toast.update(this.socketConnectionToastId, { content: 'Socket Disconnected', options: { timeout: null, type: 'error', closeButton: false, position: 'bottom-center', onClose: () => null } }, true) - } else { - this.socketConnectionToastId = this.$toast.error('Socket Disconnected', { timeout: null, position: 'bottom-center' }) - } + this.updateSocketConnectionToast('Socket Disconnected', 'error', null) }, reconnect() { console.error('[SOCKET] reconnected') }, - reconnection_attempt(val) { - console.log(`[SOCKET] Reconnection attempt ${val}`) + reconnectAttempt(val) { + console.log(`[SOCKET] reconnect attempt ${val}`) }, reconnectError() { - console.error('[SOCKET] reconnect error') + // console.error('[SOCKET] reconnect error') }, reconnectFailed() { console.error('[SOCKET] reconnect failed') @@ -352,7 +347,7 @@ export default { this.socket.on('connect', this.connect) this.socket.on('connect_error', this.connectError) this.socket.on('disconnect', this.disconnect) - this.socket.io.on('reconnection_attempt', this.reconnection_attempt) + this.socket.io.on('reconnect_attempt', this.reconnectAttempt) this.socket.io.on('reconnect', this.reconnect) this.socket.io.on('reconnect_error', this.reconnectError) this.socket.io.on('reconnect_failed', this.reconnectFailed)