我使用服务器发送的事件从服务器端接收一些事件。代码是:
var eventSource;
if(this.model.eventSource){
eventSource = this.model.eventSource;
}else{
var sseHandlerUrl = utils.config.baseUrl + "/video/ssehandler/" + lessonStore.id;
var eventSource = new EventSource(sseHandlerUrl);
this.model.eventSource = eventSource;
}
this.model.retryTime = 0;
eventSource.onopen = function(e) {
console.log("onopen");
};
eventSource.addEventListener('error',function(event) {
if (event.readyState == EventSource.CLOSED) {
self.closeVideo();
closeEventSource(eventSource);
} else {
if(self.model.retryTime > 30){
self.closeVideo();
closeEventSource(eventSource);
self.alertDialog("close", "network error!");
}
self.model.retryTime++;
}
});
它在PC上工作正常,SSE连接将持续超过一小时。但在Andoird或iOS上,连接将每60秒断开一次。 如果有人能告诉我发生了什么,我感激不尽。