Skip to content
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

ws.ping() not implemented when using express-ws #7346

Closed
tobobo opened this issue Nov 28, 2023 · 4 comments
Closed

ws.ping() not implemented when using express-ws #7346

tobobo opened this issue Nov 28, 2023 · 4 comments
Labels
bug Something isn't working quick fix Something that can be fixed with low effort, but high impact

Comments

@tobobo
Copy link

tobobo commented Nov 28, 2023

What version of Bun is running?

1.0.14+d8be3e51b

What platform is your computer?

Darwin 23.1.0 arm64 arm

What steps can reproduce the bug?

I'm attempting to migrate an app that uses express-ws but it seems like the WebSocket implementation is not compatible.

It seems like this should have been closed by #3257 but ping didn't make it on to BunWebSocketMocked.

// index.ts
import express from 'express';
import expressWs from 'express-ws';

const { app } = expressWs(express());

app.ws('/', (ws) => {
  console.log('ws connected');
  const interval = setInterval(() => {
    console.log('sending ping');
    ws.ping();
  }, 5000);
  
  ws.on('close', () => {
    console.log('ws closed');
    clearInterval(interval);
  });
});

app.listen(3000);

Once the server has started, use a WebSocket client to connect.

websocat ws://localhost:3000

What is the expected behavior?

ws connected
sending ping
closing ws

What do you see instead?

ws connected
sending ping
 5 | 
 6 | app.ws('/', (ws) => {
 7 |   console.log('ws connected');
 8 |   const interval = setInterval(() => {
 9 |     console.log('sending ping');
10 |     ws.ping();
        ^
TypeError: ws.ping is not a function. (In 'ws.ping()', 'ws.ping' is undefined)
      at /Users/tobiasbutler/Documents/code/express-ws-example/index.ts:10:4

Additional information

I can see ping is implemented on BunWebSocketMocked.#ws but it is not exposed directly on BunWebSocketMocked

@tobobo tobobo added the bug Something isn't working label Nov 28, 2023
@tobobo
Copy link
Author

tobobo commented Dec 15, 2023

@Electroid based on your work on #3257, is this a bug or expected behavior?

@tobowers
Copy link

running into this trying to use WebSocketServer from "ws" too

@iJigg
Copy link

iJigg commented Mar 1, 2024

Seems like both WebSocket.ping and WebSocket.terminate aren't implemented/exposed in BunWebSocketMocked

This prevents eg. webpack-dev-server from working

@robobun robobun added the quick fix Something that can be fixed with low effort, but high impact label Mar 1, 2024
@Electroid
Copy link
Contributor

Fixed by #9461

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working quick fix Something that can be fixed with low effort, but high impact
Projects
None yet
Development

No branches or pull requests

5 participants