mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
switched to 'ping active' system
This commit is contained in:
@@ -6,8 +6,8 @@ define(['taskbar'], function(taskbar) {
|
|||||||
|
|
||||||
function initialise() {
|
function initialise() {
|
||||||
socket.on('event:composer.ping', function(post_uuid) {
|
socket.on('event:composer.ping', function(post_uuid) {
|
||||||
if (composer.active !== post_uuid) {
|
if (composer.active === post_uuid) {
|
||||||
socket.emit('modules.composer.pingInactive', post_uuid);
|
socket.emit('modules.composer.pingActive', post_uuid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -832,6 +832,8 @@ define(['taskbar'], function(taskbar) {
|
|||||||
taskbar.discard('composer', post_uuid);
|
taskbar.discard('composer', post_uuid);
|
||||||
$('body').css({'margin-bottom': 0});
|
$('body').css({'margin-bottom': 0});
|
||||||
$('.action-bar button').removeAttr('disabled');
|
$('.action-bar button').removeAttr('disabled');
|
||||||
|
|
||||||
|
socket.emit('modules.composer.unregister', post_uuid);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -77,23 +77,38 @@ SocketModules.composer.renderHelp = function(socket, data, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketModules.composer.register = function(socket, data) {
|
SocketModules.composer.register = function(socket, data) {
|
||||||
|
var now = Date.now();
|
||||||
server.in('topic_' + data.tid).emit('event:topic.replyStart', data.uid);
|
server.in('topic_' + data.tid).emit('event:topic.replyStart', data.uid);
|
||||||
|
|
||||||
data.socket = socket;
|
data.socket = socket;
|
||||||
|
data.lastPing = now;
|
||||||
|
data.lastAnswer = now;
|
||||||
data.timer = setInterval(function() {
|
data.timer = setInterval(function() {
|
||||||
|
if (data.lastPing === data.lastAnswer) {
|
||||||
// Ping the socket to see if the composer is still active
|
// Ping the socket to see if the composer is still active
|
||||||
|
data.lastPing = Date.now();
|
||||||
socket.emit('event:composer.ping', data.uuid);
|
socket.emit('event:composer.ping', data.uuid);
|
||||||
}, 1000*10); // Every 10 seconds...
|
} else {
|
||||||
|
server.in('topic_' + data.tid).emit('event:topic.replyStop', data.uid);
|
||||||
|
delete SocketModules.composer.replyHash[data.uuid];
|
||||||
|
}
|
||||||
|
}, 1000*5); // Every 5 seconds...
|
||||||
|
|
||||||
SocketModules.composer.replyHash[data.uuid] = data;
|
SocketModules.composer.replyHash[data.uuid] = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketModules.composer.pingInactive = function(socket, uuid) {
|
SocketModules.composer.unregister = function(socket, uuid) {
|
||||||
|
var replyObj = SocketModules.composer.replyHash[uuid];
|
||||||
|
if (uuid && replyObj) {
|
||||||
|
server.in('topic_' + replyObj.tid).emit('event:topic.replyStop', replyObj.uid);
|
||||||
|
delete SocketModules.composer.replyHash[replyObj.uuid];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SocketModules.composer.pingActive = function(socket, uuid) {
|
||||||
var data = SocketModules.composer.replyHash[uuid];
|
var data = SocketModules.composer.replyHash[uuid];
|
||||||
if (SocketModules.composer.replyHash[uuid]) {
|
if (data) {
|
||||||
server.in('topic_' + data.tid).emit('event:topic.replyStop', data.uid);
|
data.lastAnswer = data.lastPing;
|
||||||
clearInterval(data.timer);
|
|
||||||
delete SocketModules.composer.replyHash[uuid];
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user