-
-
Notifications
You must be signed in to change notification settings - Fork 41
WIP: Custom websocket #515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
lib/server.js
Outdated
|
|
||
| if (balancer) return; | ||
| this.wsServer = new ws.Server({ server: this.httpServer }); | ||
| this.wsServer = new WebsocketServer(this.httpServer); |
There was a problem hiding this comment.
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:
| this.wsServer = new WebsocketServer(this.httpServer); | |
| this.wsServer = new WebsocketServer({ server: this.httpServer }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| GOING_AWAY: { | ||
| reason: 'Going away', | ||
| buf: Buffer.from([ | ||
| 0x88, 0xc, 0x3, 0xe9, 0x47, 0x6f, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x77, | ||
| 0x61, 0x79, | ||
| ]), | ||
| }, |
There was a problem hiding this comment.
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:
| 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'), | |
| ]), | |
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lib/websocket/frame.js
Outdated
| CLOSE_CODES, | ||
| TWO_32, | ||
| } = require('./constants'); | ||
| const { Result } = require('./utils/result'); |
There was a problem hiding this comment.
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
| const { Result } = require('./utils/result'); | |
| const { Result } = require('./utils/result.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also done
lib/websocket/frame.js
Outdated
| module.exports = { | ||
| Frame, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| module.exports = { | |
| Frame, | |
| }; | |
| module.exports = { Frame }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it's done
| 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; | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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] }
There was a problem hiding this comment.
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'; | |||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
#476
npm t)npm run fix)