Avoid reconnection when live ended
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
b16c91ac6d
commit
2e4f0eaf30
@ -72,5 +72,10 @@
|
|||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
</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}
|
||||||
{/await}
|
{/await}
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { onDestroy } from 'svelte';
|
||||||
|
|
||||||
import { user } from '../../../stores/user';
|
import { user } from '../../../stores/user';
|
||||||
import { ToastsStore } from '../../../stores/toasts';
|
import { ToastsStore } from '../../../stores/toasts';
|
||||||
import SurveyBadge from '../../../components/SurveyBadge.svelte';
|
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() {
|
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.addEventListener("open", () => {
|
||||||
ws_up = true;
|
ws_up = true;
|
||||||
@ -73,10 +84,11 @@
|
|||||||
ws.addEventListener("close", (e) => {
|
ws.addEventListener("close", (e) => {
|
||||||
ws_up = false;
|
ws_up = false;
|
||||||
show_question = false;
|
show_question = false;
|
||||||
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason);
|
console.log('Socket is closed. Reconnect will be attempted in 1 second.', e.reason, e);
|
||||||
setTimeout(function() {
|
if (autoreconnect && e.reason != "end")
|
||||||
wsconnect();
|
setTimeout(function() {
|
||||||
}, 1500);
|
wsconnect();
|
||||||
|
}, 1500);
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.addEventListener("error", (err) => {
|
ws.addEventListener("error", (err) => {
|
||||||
|
Reference in New Issue
Block a user