View Single Post
Old 03-11-2014, 12:33 AM   #2
alligatortek001
Registered User
 
Join Date: Nov 2013
Posts: 92
For example:

var heartbeat = function (data) {
if (!heartbeatInterval) {
// no heartbeat
return;
}

var obj = Package.encode(Package.TYPE_HEARTBEAT);
if (heartbeatTimeoutId) {
clearTimeout(heartbeatTimeoutId);
heartbeatTimeoutId = null;
}

if (heartbeatId) {
// already in a heartbeat interval
return;
}

heartbeatId = setTimeout(function () {
heartbeatId = null;
send(obj);

nextHeartbeatTimeout = Date.now() + heartbeatTimeout;
heartbeatTimeoutId = setTimeout(heartbeatTimeoutCb, heartbeatTimeout);
}, heartbeatInterval);
};

var heartbeatTimeoutCb = function () {
var gap = nextHeartbeatTimeout - Date.now();
if (gap > gapThreshold) {
heartbeatTimeoutId = setTimeout(heartbeatTimeoutCb, gap);
} else {
console.error('server heartbeat timeout');
pomelo.emit('heartbeat timeout');
pomelo.disconnect();
}
};
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
alligatortek001 is offline   Reply With Quote