Skip to content

Conversation

@MarhiievHE
Copy link
Member

#476

  • tests and linter show no problems (npm t)
  • tests are added/updated for bug fixes and new features
  • code is properly formatted (npm run fix)
  • description of changes is added in CHANGELOG.md
  • update .d.ts typings

lib/server.js Outdated

if (balancer) return;
this.wsServer = new ws.Server({ server: this.httpServer });
this.wsServer = new WebsocketServer(this.httpServer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose to be compatible with ws:

Suggested change
this.wsServer = new WebsocketServer(this.httpServer);
this.wsServer = new WebsocketServer({ server: this.httpServer });

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 88 to 94
GOING_AWAY: {
reason: 'Going away',
buf: Buffer.from([
0x88, 0xc, 0x3, 0xe9, 0x47, 0x6f, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x77,
0x61, 0x79,
]),
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's hold strings as ascii strings and all unprintable as hex, for example:

Suggested change
GOING_AWAY: {
reason: 'Going away',
buf: Buffer.from([
0x88, 0xc, 0x3, 0xe9, 0x47, 0x6f, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x77,
0x61, 0x79,
]),
},
GOING_AWAY: {
reason: 'Going away',
buf: Buffer.concat([
Buffer.from([0x88, 0x0c, 0x03, 0xe9]),
Buffer.from('Going away', 'utf8'),
]),
},

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

CLOSE_CODES,
TWO_32,
} = require('./constants');
const { Result } = require('./utils/result');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always add extensions in require

Suggested change
const { Result } = require('./utils/result');
const { Result } = require('./utils/result.js');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also done

Comment on lines 205 to 207
module.exports = {
Frame,
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
module.exports = {
Frame,
};
module.exports = { Frame };

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's done

Comment on lines 268 to 275
on(event, cb) {
if (event === 'open') this._openCb = cb;
else if (event === 'message') this._messageCb = (buf) => cb(buf);
else if (event === 'frame') this._frameCb = cb;
else if (event === 'ping') this._pingCb = (buf) => cb(buf);
else if (event === 'pong') this._pongCb = (buf) => cb(buf);
else if (event === 'close') this._closeCb = cb;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just use EventEmitter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that’s a good idea — much cleaner than mocking everything. Done

// Methods: send(data), sendFrame(opcode, payload, { fin=true, mask=true }),
// sendText, sendBinary, ping, close
class ProtocolClient {
constructor(url) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wery long constructor, maybe we can decompose, for example, extracting collection:
{ [opcode]: [handler] }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done

@@ -0,0 +1,35 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be moved to metautil

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I move the Result class to metautil, or do you think it would be better to introduce an algebraic data types?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants