merge: fix-ack-dead-socket into confirmDeliver
This commit is contained in:
+17
-3
@@ -41,6 +41,10 @@ class Appv2 {
|
||||
return 10;
|
||||
}
|
||||
|
||||
get ackTimeoutMs() {
|
||||
return Number(process.env.ACK_TIMEOUT_MS || 1500);
|
||||
}
|
||||
|
||||
_takeIO() {
|
||||
this.app = express();
|
||||
this.server = http.createServer(this.app);
|
||||
@@ -64,13 +68,17 @@ class Appv2 {
|
||||
console.log('publish to ' + room + ' data:');
|
||||
console.log(req.body);
|
||||
const userId = room.split("_")[0];
|
||||
const connection = this.connections[userId];
|
||||
|
||||
if (typeof this.connections[userId] === 'undefined') {
|
||||
if (typeof connection === 'undefined' || !connection.connected) {
|
||||
if (typeof connection !== 'undefined' && !connection.connected) {
|
||||
delete this.connections[userId];
|
||||
}
|
||||
th.addToQueue(userId, req.body);
|
||||
this.postResponse(res, 404);
|
||||
return;
|
||||
}
|
||||
this.connections[userId].timeout(100).emit('data', req.body, (err, response)=> {
|
||||
connection.timeout(this.ackTimeoutMs).emit('data', req.body, (err, response)=> {
|
||||
let success = true;
|
||||
console.log(response);
|
||||
if(typeof response !== 'undefined') {
|
||||
@@ -99,9 +107,15 @@ class Appv2 {
|
||||
this.connections[userId] = socket;
|
||||
this.tryResolveQueueStorage(userId, room).then(r => console.log(r));
|
||||
console.log('user ' + socket.id + ' joined to room ' + room);
|
||||
socket.on('disconnect', () => {
|
||||
if (this.connections[userId] === socket) {
|
||||
delete this.connections[userId];
|
||||
}
|
||||
console.log('user ' + socket.id + ' disconnected');
|
||||
});
|
||||
return;
|
||||
}
|
||||
socket.on('disconnect', () => {
|
||||
const room = socket.handshake.query.id;
|
||||
console.log('user ' + socket.id + ' disconnected');
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user