Comparing version 0.1.6 to 0.1.7
@@ -20,3 +20,3 @@ "use strict"; | ||
? { | ||
clientId: clientInfo.data.id, | ||
clientId: client.id, | ||
info: clientInfo.data.info, | ||
@@ -23,0 +23,0 @@ } |
@@ -39,29 +39,45 @@ "use strict"; | ||
this.onClientConnect.emit(client); | ||
let failCount = 0; | ||
const pingTimer = setInterval(() => { | ||
ws.ping(); | ||
ws.ping(undefined, 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 => { | ||
if (evt.type === 'message') { | ||
try { | ||
const msg = this.formatMsg(evt.data); | ||
this.logger.info('[client] ws onmessage', msg.type, client.id, `isAuthorized: ${client.isAuthorized}`, `isAdmin: ${client.isAdmin}`); | ||
const processors = this.commandProcessors.filter(cp => { | ||
return typeof cp.tester === 'string' ? cp.tester === msg.type : cp.tester(msg.type); | ||
}); | ||
if (!processors.length) { | ||
this.logger.warn('[client] NotFound Command Processor', client.id, msg); | ||
} | ||
processors.forEach(cp => { | ||
if (cp.needAuth && !client.isAuthorized) { | ||
this.logger.warn('[NoAuth]', client.id, msg); | ||
} | ||
else { | ||
cp.onMessage(client, msg.data, msg); | ||
} | ||
}); | ||
if (!evt || evt.type !== 'message') { | ||
return; | ||
} | ||
try { | ||
const msg = this.formatMsg(evt.data); | ||
if (!msg) { | ||
return; | ||
} | ||
catch (error) { | ||
this.logger.warn('[client] ws onmessage Err!', client.id, evt.data, error); | ||
this.logger.debug('[client] ws onmessage', msg.type, client.id, `isAuthorized: ${client.isAuthorized}`, `isAdmin: ${client.isAdmin}`); | ||
const processors = this.commandProcessors.filter(cp => { | ||
return typeof cp.tester === 'string' ? cp.tester === msg.type : cp.tester(msg.type); | ||
}); | ||
if (!processors.length) { | ||
this.logger.warn('[client] NotFound Command Processor', client.id, msg); | ||
} | ||
processors.forEach(cp => { | ||
if (cp.needAuth && !client.isAuthorized) { | ||
this.logger.warn('[NoAuth]', client.id, msg); | ||
} | ||
else { | ||
cp.onMessage(client, msg.data, msg); | ||
} | ||
}); | ||
} | ||
catch (error) { | ||
this.logger.warn('[client] ws onmessage Err!', client.id, evt.data, error); | ||
} | ||
}; | ||
@@ -87,3 +103,3 @@ ws.onerror = evt => { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
this.logger.info('[client] broadcast', evt); | ||
this.logger.debug('[client] broadcast', evt.type); | ||
// Worker 内尝试直接分发,找不到则直接抛出 | ||
@@ -90,0 +106,0 @@ if (!cbType && evt instanceof Any_1.ClientMessageEvent) { |
@@ -17,3 +17,3 @@ "use strict"; | ||
const newEvt = new A_W_1.ClientInfoResponseEvent({ | ||
id: evt.id, | ||
id: client.id, | ||
info: client.ext.info, | ||
@@ -20,0 +20,0 @@ data: client.ext.data, |
@@ -19,3 +19,3 @@ "use strict"; | ||
return new A_W_1.ClientInfoResponseEvent({ | ||
id: evt.id, | ||
id: client.id, | ||
info: client.ext.info, | ||
@@ -22,0 +22,0 @@ data: client.ext.data, |
{ | ||
"name": "egg-ez-ws", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"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
62559
1578