Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-ez-ws

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-ez-ws - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

2

lib/ClientManager/Command/RoomCommand.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc