How to unsubscribe from a socket.io subscription?

前端 未结 11 1349
长发绾君心
长发绾君心 2020-11-30 02:00

Suppose there are objects making subscriptions to a socket server like so:

socket.on(\'news\', obj.socketEvent)

These objects have a short life

11条回答
  •  忘掉有多难
    2020-11-30 02:02

    Also on java client, it can be done the same way with the Javascript client. I've pasted from socket.io.

    // remove all listeners of the connect event
    socket.off(Socket.EVENT_CONNECT);
    
    listener = new Emitter.Listener() { ... };
    socket.on(Socket.EVENT_CONNECT, listener);
    // remove the specified listener
    socket.off(Socket.EVENT_CONNECT, listener);
    

提交回复
热议问题