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

Add the "loopback" flag. #3640

Closed
wants to merge 1 commit into from
Closed

Conversation

ripfester
Copy link

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behaviour

It is not possible to send messages to the local (server) endpoint. In scenarios where rooms/broadcasts are used, this requires the server to maintain a separate room->socket mapping so that administrative actions can be performed (e.g., close all sockets in room 'foo').

New behaviour

With this change (and related PR socketio/socket.io-adapter#56), it is possible to emit/broadcast messages that are handled by the local (server) endpoint by inserting .loopback into the emit syntax. On connect, the server can add handlers for messages that originate server-side, and later broadcast those messages in order to effect administrative actions (e.g., close all sockets in room 'foo') without maintaining independent mappings.

Other information (e.g. related issues)

socketio/socket.io-adapter#56 must be committed before this change, as socket.io-adapter is used in tests and must honour the loopback flag.

The "loopback" flag is used to emit messages on the local endpoint of
a socket; e.g., allowing the server to send a message to the server's
handler directly.

This is especially useful in conjunction with rooms, as it allows the
server to proactively trigger behavior for each socket in a room without
having to maintain a separate list of said sockets or relying on the
client endpoint to trigger the behavior.
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.

1 participant