// WebSocket註冊ts示例:
ws: any;
//註冊ws
registerWebSorkt(){
let url = 'wss://.......com/......'
this.ws = new WebSocket(url);
this.ws.onmessage = this.loginSuccCall();//WebSorkt通知
this.ws.onerror = this.websocketOnError();//WebSorkt異常
this.ws.onclose = this.websocketClose();//WebSorkt關閉
setTimeout(()=>{this.overTime(this.ws)},1000*60*10);//10分鐘二維碼登錄過期
}
//關閉ws
overTime(ws: WebSocket){
console.log("主動關閉websocket========");
ws.close();
}
//ws通知監聽
loginSuccCall(wsData: any){ console.log("====WS回調=====",wsData) }
//ws異常監聽
websocketOnError(){
console.log("websocket發生異常,3秒後重連========");
setTimeout(()=>{this.registerWebSorkt()},1000*3);
}
//ws關閉監聽
websocketClose(){
console.log("websocket關閉========");
}