版本 "angular2-websocket":"^0.9.8"
现象 由于websocket的长连接机制,在Chrome中5min后就会自动断开,需要再次重新连接
如何解决?
this.ws.onClose(
()=> {
if (window.location.hash.indexOf('当前页面')!== -1) {
this.ws.connect();// 断开后重新连接
}
}
);
ngOnDestroy() {
this.ws.close(true); // 离开该组件需销毁,否则会重复创建同样的ws连接
}
网友评论