Unbind the specified event handler (opposite of
This method is here for completeness, but most apps should not need to use it. See below for more information.
|1||eventIdentity||The unique event identity associated with a server-sent message, e.g. "recipe".|
|2||handlerFn||The event handler function to unbind from the specified event.|
- If you decide to use this method, be careful!
io.socket.off()does not stop the this client-side socket from receiving any server-sent messages, it just prevents the specified event handler from firing. Usually, the desired effect is to prevent messages from being sent altogether, which is critical if your server-sent messages contain private data. This happens automatically when a socket disconnects, but there are also less-common use cases where it is necessary to unsubscribe sockets from rooms while they are still connected. For example, consider a scenario where an admin user is banned from your system while viewing a realtime dashboard, and your app needs to prevent them from receiving all subsequent realtime updates. To force a client socket to stop receiving broadcasted messages, do not use this method. Instead, unsubscribe the socket in your server-side code:
- If the room was joined using
- If the room was joined using resourceful PubSub methods, call
- In order to use
.off(), you will need to store the
handlerFnargument you passed in to
.on()in a variable.