mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
connection/disconnection handling
This commit is contained in:
@@ -14,6 +14,10 @@ var socket,
|
|||||||
config = data;
|
config = data;
|
||||||
socket = io.connect('http://' + config.socket.address + config.socket.port? ':' + config.socket.port : '');
|
socket = io.connect('http://' + config.socket.address + config.socket.port? ':' + config.socket.port : '');
|
||||||
|
|
||||||
|
var reconnecting = false;
|
||||||
|
var reconnectTries = 0;
|
||||||
|
|
||||||
|
|
||||||
socket.on('event:connect', function(data) {
|
socket.on('event:connect', function(data) {
|
||||||
console.log('connected to nodebb socket: ', data);
|
console.log('connected to nodebb socket: ', data);
|
||||||
});
|
});
|
||||||
@@ -32,14 +36,63 @@ var socket,
|
|||||||
contentEl.value = data.post;
|
contentEl.value = data.post;
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnect', function(data){
|
socket.on('connect', function(data){
|
||||||
setTimeout(function() {
|
if(reconnecting) {
|
||||||
$('#disconnect-modal').modal('show');
|
app.alert({
|
||||||
$('#reload-button').on('click',function(){
|
alert_id: 'connection_alert',
|
||||||
$('#disconnect-modal').modal('hide');
|
title: 'Connected',
|
||||||
window.location.reload();
|
message: 'Connection successfull',
|
||||||
|
type: 'success',
|
||||||
|
timeout: 5000
|
||||||
});
|
});
|
||||||
}, 500);
|
reconnecting = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('disconnect', function(data){
|
||||||
|
app.alert({
|
||||||
|
alert_id: 'connection_alert',
|
||||||
|
title: 'Disconnect',
|
||||||
|
message: 'You have disconnected from NodeBB, we will try to reconnect!',
|
||||||
|
type: 'error',
|
||||||
|
timeout: 1000
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('reconnecting', function(data) {
|
||||||
|
reconnecting = true;
|
||||||
|
reconnectTries++;
|
||||||
|
if(reconnectTries > 4) {
|
||||||
|
showDisconnectModal();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
app.alert({
|
||||||
|
alert_id: 'connection_alert',
|
||||||
|
title: 'Reconnecting',
|
||||||
|
message: 'You have disconnected from NodeBB, we will try to reconnect you. <br/><i class="icon-refresh icon-spin"></i>',
|
||||||
|
type: 'notify',
|
||||||
|
timeout: 5000
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function showDisconnectModal() {
|
||||||
|
$('#disconnect-modal').modal({
|
||||||
|
backdrop:'static',
|
||||||
|
show:true
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#reload-button').on('click',function(){
|
||||||
|
$('#disconnect-modal').modal('hide');
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.on('reconnect_failed', function(data) {
|
||||||
|
console.log('reconnect_failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('connect_failed', function(data){
|
||||||
|
console.log('connect_faled');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async: false
|
async: false
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
<h3 id="myModalLabel">Socket Disconnect</h3>
|
<h3 id="myModalLabel">Socket Disconnect</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<span>Looks like you disconnected, try reloading the page.</span>
|
<span id="disconnect-text">Looks like you disconnected, try reloading the page.</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<a id="reload-button" href="/" class="btn btn-primary">Reload</a>
|
<a id="reload-button" href="/" class="btn btn-primary">Reload</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user