-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
resources/js/components/indicators/WebSocketConnection.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<template> | ||
<div | ||
v-if="visible" | ||
class="web-socket-connection d-flex align-items-center gap-2 position-absolute start-50 translate-middle mt-2 z-2 bg-white order p-2 border border-1 border-secondary rounded" | ||
:title="status" | ||
> | ||
<DotIndicator :type="indicatorStatus" /> | ||
{{ message }} | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { computed, onMounted, onBeforeUnmount, ref } from 'vue'; | ||
import DotIndicator from '@/components/indicators/DotIndicator.vue'; | ||
import { getState, getConnection } from '@/helpers/websocket'; | ||
import { useI18n } from 'vue-i18n'; | ||
export default { | ||
components: { | ||
DotIndicator | ||
}, | ||
setup() { | ||
const t = useI18n().t; | ||
const status = ref(getState()); | ||
const message = computed(() => { | ||
if(indicatorStatus.value === 'success') { | ||
return t('websockets.service_available_again'); | ||
} else { | ||
return t('websockets.service_unavailable'); | ||
} | ||
}); | ||
const indicatorStatus = computed(() => { | ||
switch(status.value) { | ||
case 'connected': | ||
return 'success'; | ||
case 'connecting': | ||
case 'initialized': | ||
case 'unavailable': | ||
case 'disconnected': | ||
case 'failed': | ||
default: | ||
return 'danger'; | ||
} | ||
}); | ||
const visible = ref(indicatorStatus.value === 'danger'); | ||
console.log('visible', visible.value); | ||
let timeout = null; | ||
const updateState = _ => { | ||
status.value = getState(); | ||
console.log(status.value); | ||
clearTimeout(timeout); | ||
if(status.value === 'connected') { | ||
timeout = setTimeout(() => { | ||
visible.value = false; | ||
}, 3000); | ||
} else { | ||
visible.value = true; | ||
} | ||
}; | ||
onMounted(() => { | ||
console.log('WebSocketConnection mounted'); | ||
const connection = getConnection(); | ||
if(!connection) { | ||
console.error('Could not get connection object'); | ||
} else { | ||
console.log(connection, connection.bind); | ||
connection.bind('state_change', function (states) { | ||
updateState(); | ||
}); | ||
} | ||
}); | ||
onBeforeUnmount(() => { | ||
const connection = getConnection(); | ||
if(!connection) { | ||
console.error('Could not get connection object'); | ||
} else { | ||
connection.unbind('state_change ', updateState); | ||
} | ||
}); | ||
return { | ||
status, | ||
indicatorStatus, | ||
message, | ||
visible, | ||
}; | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters