socket io,停止在客户端接收数据

时间:2021-07-24 11:06:06

标签: ionic-framework socket.io

我在我的 ionic 应用中使用 socket.io。我只是想不通,我如何停止在客户端监听事件,我已经试过了。 “socket.disconnect”、“socket.off”、“socket.removeAllListeners()”,但它仍然从服务器接收事件。有人能解释一下这种疯狂吗!下面是我的代码,我在我的客户端上使用了“ngx-socket-io”。

checkIfCourierHaveEnableWatch(): void{
    this.socket.fromEvent('get-courier-location')
    .subscribe((couriersPositions: CourierPosition[])=>{
        const latestcourPosition = couriersPositions.find(postion => postion.courierId === this.state.courierId);
        console.log('latest cour poisiton ', latestcourPosition);
    });
    
}

ionViewWillLeave(): void{ //this will trigger on page leave, this should stop socket.io from receiving, but its not working
    this.socket.disconnect();
}

0 个答案:

没有答案