Skip to content

chore: migrate websocket-stream to ws#1030

Merged
robertsLando merged 1 commit intomoscajs:mainfrom
seriousme:move-to-ws
Jun 17, 2025
Merged

chore: migrate websocket-stream to ws#1030
robertsLando merged 1 commit intomoscajs:mainfrom
seriousme:move-to-ws

Conversation

@seriousme
Copy link
Copy Markdown
Contributor

This PR migrates Aedes from websocket-stream to ws.
When installing npm modules I got warnings from npm on high-severity issues on websocket stream.

In the discussion at max-mapper/websocket-stream#166 it became clear that the best way forward is to migrate from websocket-stream to ws.

Aedes only used websocket-stream in test but the documentation recommended to use it as well.

I have a question open at ws to see if we can improve the developer experience when setting up a websocket stream, but for now we have a working setup and the documentation has been amended.

KInd regards,
Hans

@seriousme
Copy link
Copy Markdown
Contributor Author

seriousme commented Jun 17, 2025

We could also make .handle() accept a websocket + req as well and do the conversion to duplex stream + req within .handle() if that improves developer experience.

e.g. instead of:

const wss = new ws.WebSocketServer({
  server
})

wss.on('connection', (websocket, req) => {
  const stream = ws.createWebSocketStream(websocket)
  aedes.handle(stream, req)
})

one would then just do:

const wss = new ws.WebSocketServer({
  server
})

wss.on(connection, aedes.handle)

However I proposed to the ws project to allow for:

const wss = new ws.WebSocketServer({
  server,
  webSocketStream:aedes.handle
})

which would be more clean imo.

Kind regards,
Hans

@robertsLando
Copy link
Copy Markdown
Member

I'm +1 for

const wss = new ws.WebSocketServer({
  server,
  webSocketStream:aedes.handle
})

so let's wait for that

Copy link
Copy Markdown
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

LGTM

@robertsLando robertsLando merged commit ef5e1a8 into moscajs:main Jun 17, 2025
14 checks passed
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 15711266362

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 99.575%

Totals Coverage Status
Change from base Build 15700589068: 0.0%
Covered Lines: 827
Relevant Lines: 828

💛 - Coveralls

@seriousme seriousme deleted the move-to-ws branch June 17, 2025 17:24
@seriousme
Copy link
Copy Markdown
Contributor Author

seriousme commented Jun 17, 2025

I'm +1 for

const wss = new ws.WebSocketServer({
  server,
  webSocketStream:aedes.handle
})

so let's wait for that

We got an answer: the ws project prefers not to have it in the constructor of ws.WebSocketServer websockets/ws#2289 (comment)

@robertsLando
Copy link
Copy Markdown
Member

Ok so no action to do, I think examples are really clear and the code is simple

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.

3 participants