mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
switched to 'ping active' system
This commit is contained in:
@@ -6,8 +6,8 @@ define(['taskbar'], function(taskbar) {
|
||||
|
||||
function initialise() {
|
||||
socket.on('event:composer.ping', function(post_uuid) {
|
||||
if (composer.active !== post_uuid) {
|
||||
socket.emit('modules.composer.pingInactive', post_uuid);
|
||||
if (composer.active === post_uuid) {
|
||||
socket.emit('modules.composer.pingActive', post_uuid);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -832,6 +832,8 @@ define(['taskbar'], function(taskbar) {
|
||||
taskbar.discard('composer', post_uuid);
|
||||
$('body').css({'margin-bottom': 0});
|
||||
$('.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) {
|
||||
var now = Date.now();
|
||||
server.in('topic_' + data.tid).emit('event:topic.replyStart', data.uid);
|
||||
|
||||
data.socket = socket;
|
||||
data.lastPing = now;
|
||||
data.lastAnswer = now;
|
||||
data.timer = setInterval(function() {
|
||||
if (data.lastPing === data.lastAnswer) {
|
||||
// Ping the socket to see if the composer is still active
|
||||
data.lastPing = Date.now();
|
||||
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.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];
|
||||
if (SocketModules.composer.replyHash[uuid]) {
|
||||
server.in('topic_' + data.tid).emit('event:topic.replyStop', data.uid);
|
||||
clearInterval(data.timer);
|
||||
delete SocketModules.composer.replyHash[uuid];
|
||||
if (data) {
|
||||
data.lastAnswer = data.lastPing;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user