essai reco websocket

This commit is contained in:
afornerot 2019-10-17 13:37:39 +02:00
parent 2e34d65cbf
commit b29ce57c6e
1 changed files with 30 additions and 8 deletions

View File

@ -120,7 +120,7 @@
{% endblock %} {% endblock %}
{% block localjavascript %} {% block localjavascript %}
var webSocket; var webSocket;
$(document).ready(function(){ $(document).ready(function(){
if (CKEDITOR.instances["chat_message"]) CKEDITOR.instances["chat_message"].destroy(); if (CKEDITOR.instances["chat_message"]) CKEDITOR.instances["chat_message"].destroy();
@ -147,13 +147,24 @@
},500); },500);
$(".switch").bootstrapSwitch(); $(".switch").bootstrapSwitch();
var dateoptions = {weekday: "long", year: "numeric", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit" };
$("#mymodal-sendmail").removeAttr("tabindex"); $("#mymodal-sendmail").removeAttr("tabindex");
websocket();
});
function websocket()
{
{% if websocket_activate and app.user %} {% if websocket_activate and app.user %}
var _WS_URI = "wss://{{ gos_web_socket_server_host }}:{{ gos_web_socket_server_port }}"; var _WS_URI = "wss://{{ gos_web_socket_server_host }}:{{ gos_web_socket_server_port }}";
console.log("INI WS");
webSocket = WS.connect(_WS_URI); webSocket = WS.connect(_WS_URI);
console.log("END INI WS");
var dateoptions = {weekday: "long", year: "numeric", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit" };
var timer; var timer;
var session;
webSocket.on("socket/connect", function (session) { webSocket.on("socket/connect", function (session) {
// Reinit du tps de tentative de reco // Reinit du tps de tentative de reco
@ -260,39 +271,50 @@
webSocket.on("socket/disconnect", function(error){ webSocket.on("socket/disconnect", function(error){
laberror="Disconnected for " + error.reason + " with code " + error.code; laberror="Disconnected for " + error.reason + " with code " + error.code;
console.log("=== DISCONNECT ===");
console.log(laberror); console.log(laberror);
$('#modalinfo').modal('show');
if(error.code==2) { if(error.code==2) {
$('#modalinfo').modal('show');
$('#modalinfotext').html("<center>Impossible de se connecter au serveur.<br>Vous avez dépassé le nombre de reconnexion maximum<br><br>Veuillez retentez d'ici quelques secondes<br><br><code>"+laberror+"</code><br><br><div id='modalinfotimer'></div><br><a class='btn btn-primary' onclick='location.reload(true);'>Forcer la tentative de reconnexion</a></center>"); $('#modalinfotext').html("<center>Impossible de se connecter au serveur.<br>Vous avez dépassé le nombre de reconnexion maximum<br><br>Veuillez retentez d'ici quelques secondes<br><br><code>"+laberror+"</code><br><br><div id='modalinfotimer'></div><br><a class='btn btn-primary' onclick='location.reload(true);'>Forcer la tentative de reconnexion</a></center>");
clearInterval(timer); clearInterval(timer);
var nbtentative=10; var nbtentative=10;
timer=setInterval(function(){ $('#modalinfotimer').html((nbtentative--)+"s") }, 1000); timer=setInterval(function(){ $('#modalinfotimer').html((nbtentative--)+"s") }, 1000);
setTimeout(function(){ location.reload(true); }, 10000); setTimeout(function(){ websocket(); }, 10000);
//setTimeout(function(){ location.reload(true); }, 10000);
} }
if(error.code==3) { if(error.code==3) {
$('#modalinfo').modal('show');
$('#modalinfotext').html("<center>Impossible de se connecter au serveur.<br>Veuillez retentez d'ici quelques secondes<br><br><code>"+laberror+"</code><br><br><div id='modalinfotimer'></div><br><a class='btn btn-primary' onclick='location.reload(true);'>Forcer la tentative de reconnexion</a></center>"); $('#modalinfotext').html("<center>Impossible de se connecter au serveur.<br>Veuillez retentez d'ici quelques secondes<br><br><code>"+laberror+"</code><br><br><div id='modalinfotimer'></div><br><a class='btn btn-primary' onclick='location.reload(true);'>Forcer la tentative de reconnexion</a></center>");
clearInterval(timer); clearInterval(timer);
var nbtentative=10; var nbtentative=10;
timer=setInterval(function(){ $('#modalinfotimer').html((nbtentative--)+"s") }, 1000); timer=setInterval(function(){ $('#modalinfotimer').html((nbtentative--)+"s") }, 1000);
setTimeout(function(){ location.reload(true); }, 10000); setTimeout(function(){ websocket(); }, 10000);
// setTimeout(function(){ location.reload(true); }, 10000);
} }
if(error.code==6 || error.code==5) { if(error.code==6 || error.code==5) {
$('#modalinfotext').html("<center>Impossible de se connecter au serveur.<br>Vous allez être reconnecté d'ici quelques secondes<br><br><code>"+laberror+"</code><br><br><div id='modalinfotimer'></div><br><a class='btn btn-primary' onclick='location.reload(true);'>Forcer la tentative de reconnexion</a></center>"); $('#modalinfotext').html("<center>Impossible de se connecter au serveur.<br>Vous allez être reconnecté d'ici quelques secondes<br><br><code>"+laberror+"</code><br><br><div id='modalinfotimer'></div><br><a class='btn btn-primary' onclick='location.reload(true);'>Forcer la tentative de reconnexion</a></center>");
clearInterval(timer); clearInterval(timer);
var nbtentative=5; var nbtentative=5;
//session.unsubscribe("websocket/channel/{{groupid}}");
websocket();
/*
timer=setInterval(function(){ $('#modalinfotimer').html((nbtentative--)+"s") }, 1000); timer=setInterval(function(){ $('#modalinfotimer').html((nbtentative--)+"s") }, 1000);
setTimeout(function(){ websocket(); }, 10000);
*/
} }
}); });
{% endif %} {% endif %}
}); }
{% endblock %} {% endblock %}