Avoid reconnection when live ended
continuous-integration/drone/push Build is failing Details

This commit is contained in:
nemunaire 2022-09-02 12:25:32 +02:00
parent b16c91ac6d
commit 2e4f0eaf30
2 changed files with 22 additions and 5 deletions

View File

@ -72,5 +72,10 @@
<hr>
</div>
</div>
{#if survey.direct != null}
<div class="alert alert-warning">
<strong><a href="surveys/{survey.id}/live">Cliquez ici pour accéder au direct</a>.</strong> Il s'agit d'un questionnaire en direct, le questionnaire n'est pas accessible sur cette page.
</div>
{/if}
{/await}
{/await}

View File

@ -10,6 +10,8 @@
</script>
<script>
import { onDestroy } from 'svelte';
import { user } from '../../../stores/user';
import { ToastsStore } from '../../../stores/toasts';
import SurveyBadge from '../../../components/SurveyBadge.svelte';
@ -63,8 +65,17 @@
}
}
let ws = null;
let autoreconnect = true;
onDestroy(() => {
autoreconnect = false;
console.log("destroy", ws)
if (ws) {
ws.close();
}
});
function wsconnect() {
const ws = new WebSocket((window.location.protocol == 'https:'?'wss://':'ws://') + window.location.host + `/api/surveys/${sid}/ws`);
ws = new WebSocket((window.location.protocol == 'https:'?'wss://':'ws://') + window.location.host + `/api/surveys/${sid}/ws`);
ws.addEventListener("open", () => {
ws_up = true;
@ -73,10 +84,11 @@
ws.addEventListener("close", (e) => {
ws_up = false;
show_question = false;
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
setTimeout(function() {
wsconnect();
}, 1500);
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason, e);
if (autoreconnect && e.reason != "end")
setTimeout(function() {
wsconnect();
}, 1500);
});
ws.addEventListener("error", (err) => {