Comparing version 0.1.9 to 0.1.10
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { BaseManager } from '../common/BaseManager'; | ||
@@ -14,2 +15,3 @@ import * as WebSocket from 'ws'; | ||
readonly logger: import("_egg-logger@2.4.1@egg-logger").EggLogger; | ||
readonly checkHeart: NodeJS.Timeout; | ||
private commandProcessors; | ||
@@ -16,0 +18,0 @@ private clients; |
@@ -17,2 +17,10 @@ "use strict"; | ||
this.logger = this.app.getLogger('ClientManager'); | ||
this.checkHeart = setInterval(() => { | ||
[...this.clients.values()].forEach(client => client.ws.ping('', undefined, err => { | ||
if (err) { | ||
this.logger.warn(client.id, 'ping fail!', err); | ||
client.ws.close(); | ||
} | ||
})); | ||
}, 30 * 1000); | ||
this.commandProcessors = []; | ||
@@ -40,17 +48,2 @@ this.clients = new Map(); | ||
this.onClientConnect.emit(client); | ||
let failCount = 0; | ||
const pingTimer = setInterval(() => { | ||
ws.ping('', undefined, err => { | ||
if (err) { | ||
failCount++; | ||
this.logger.warn(client.id, 'ping fail!', failCount, err); | ||
if (failCount >= 2) { | ||
ws.close(); | ||
} | ||
} | ||
else { | ||
failCount = 0; | ||
} | ||
}); | ||
}, 30 * 1000); | ||
ws.onmessage = evt => { | ||
@@ -90,3 +83,2 @@ if (!evt || evt.type !== 'message') { | ||
this.logger.info('[client] onclose', client.id); | ||
clearInterval(pingTimer); | ||
this.clients.delete(client.id); | ||
@@ -93,0 +85,0 @@ const clientInfo = yield this.broadcast(new W_A_1.ClientDisconnectEvent({ id: client.id }), A_W_1.ClientInfoResponseEvent); |
{ | ||
"name": "egg-ez-ws", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "easy websocket for egg.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63089
1586