Adds WebSocket server support#37
Conversation
|
I pushed a new commit addressing your comments. I also noticed that I forgot to update the integration script runner and that all the integration tests were on 0.6.2 so I updated those to 0.6.3. |
|
Hey @dkoontz , excellent stuff! After my last review I thought of a few other things, and didn't add those comments to this issue. In any case, here they are:
|
Adds the WebSocket module to the Node platform allowing Gren programs to create WebSocket servers and handle client connections.
886fd7a to
a374ed6
Compare
robinheghan
left a comment
There was a problem hiding this comment.
We're getting close!
I have a few notes on the API.
Whenever we get a new connection, we give the user this record:
{ connection : Connection
, readable : Readable Message
, textWritable : Writable String
, binaryWritable : Writable Bytes
}
I think Connection should suffice here. The WebSocketServer.Connection module can expose functions that takes in a Connection and returns the readable and or writable stream.
I also think that instead of having two writeable streams, one for string and one for bytes, should be reduced to a single Writeable Message instead.
I also wonder why there are send and sendBytes functions in WebSocketServer.Connection. Shouldn't this be handled by the writable stream? 🤔
Also, should Connection, connectionId and Message be moved to the WebSocketServer.Connection module?
In summary:
- Remove
sendandsendBytesfromWebSocketServer.Connection(unless there's a good reason for keeping them?). Communication over the web socket should be handled by streams. - Add
readStream : Connection -> Stream.Readable MessageandwriteStream : Connection -> Stream.Writable MessagetoWebSocketServer.Connection. - Simplify
WebSocketServer.onConnectionto only return aConnection. - Move
Connection,connectionId(rename toid?) andMessageto `WebSocketServer.Connection.
Adds WebSocket server capabilities.
This is mostly modeled after the HttpServer module. There are tests but I haven't integrated it into a real application yet (going to work on gren-lang/browser#101 next so I have both parts to test with).