How to unsubscribe from a socket.io subscription?

前端 未结 11 1346
长发绾君心
长发绾君心 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

    If you want to create listeners that "listens" only once use socket.once('news',func). Socket.io automatically will distroy the listener after the event happened - it's called "volatile listener".

提交回复
热议问题