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

message event listener registration error #40

Closed
emarteca opened this issue Dec 4, 2019 · 0 comments
Closed

message event listener registration error #40

emarteca opened this issue Dec 4, 2019 · 0 comments

Comments

@emarteca
Copy link

emarteca commented Dec 4, 2019

Hi all, I've been working on a tool to identify instances of events registered to the wrong object in uses of some JavaScript event-driven APIs, as part of a research project.

The tool flagged line 27 in server/console.ts, on the registration of the “message” event.
The reason I believe this is indicative of an error is as follows (from looking at the npm ws API documentation).
The wss variable, created by the call to Ws.Server (on line 18) is an object of type ws.Server. However, the “message” event is emitter on ws.Socket.
My guess is that your listener registration for “message” should be on the ws variable inside the listener for “connection” on line 22, since ws is a ws.Socket.
Specifically, I think the code should be:

wss.on('connection', (ws) => {
    consoleSocket = ws;
    send('console connected \n', 'default');

    ws.on(“message”), ….); // place the code from the “message” registration on wss here 
  });

This corresponds to the example in the API documentation.

Thanks!

@q-nick q-nick closed this as completed Jan 15, 2023
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

No branches or pull requests

2 participants