mirror of
https://github.com/Thream/socketio-jwt.git
synced 2024-07-21 09:38:31 +02:00
Make async call of .disconnect() optional
This commit is contained in:
parent
c31764aac3
commit
0fa2cc2590
16
lib/index.js
16
lib/index.js
@ -34,7 +34,23 @@ function noQsMethod(options) {
|
|||||||
var error = new UnauthorizedError(code, {
|
var error = new UnauthorizedError(code, {
|
||||||
message: (Object.prototype.toString.call(err) === '[object Object]' && err.message) ? err.message : err
|
message: (Object.prototype.toString.call(err) === '[object Object]' && err.message) ? err.message : err
|
||||||
});
|
});
|
||||||
|
var callback_timeout;
|
||||||
|
// If callback explicitely set to false, start timeout to disconnect socket
|
||||||
|
if (options.callback === false || typeof options.callback === "number") {
|
||||||
|
if (typeof options.callback === "number") {
|
||||||
|
if (options.callback < 0) {
|
||||||
|
// If callback is negative(invalid value), make it positive
|
||||||
|
options.callback = Math.abs(options.callback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback_timeout = setTimeout(function () {
|
||||||
|
socket.disconnect('unauthorized');
|
||||||
|
}, (options.callback === false ? 0 : options.callback));
|
||||||
|
}
|
||||||
socket.emit('unauthorized', error, function() {
|
socket.emit('unauthorized', error, function() {
|
||||||
|
if (typeof options.callback === "number") {
|
||||||
|
clearTimeout(callback_timeout);
|
||||||
|
}
|
||||||
socket.disconnect('unauthorized');
|
socket.disconnect('unauthorized');
|
||||||
});
|
});
|
||||||
return; // stop logic, socket will be close on next tick
|
return; // stop logic, socket will be close on next tick
|
||||||
|
Loading…
Reference in New Issue
Block a user