📜  处理 Websocket 超时 - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:19.145000             🧑  作者: Mango

代码示例1
let timerID = 0; 
function keepAlive() { 
    let timeout = 15000;  
    if (webSocket.readyState == webSocket.OPEN) {  
        webSocket.send('');  
    }  
    timerId = setTimeout(keepAlive, timeout);  
}  
function cancelKeepAlive() {  
    if (timerId) {  
        cancelTimeout(timerId);  
    }  
}