Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions mesop/web/src/services/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,30 @@ export class Channel {
this.queueMessage(request, uiResponse);
});
});

this.eventSource.addEventListener('error', (e) => {
zone.run(async () => {
console.error('SSE error:', e);
this.status = ChannelStatus.CLOSED;
clearTimeout(this.isWaitingTimeout);
this.isWaiting = false;
this._isHotReloading = false;
await this.processMessageQueue();
this.dequeueEvent();
});
});

this.eventSource.addEventListener('abort', (e) => {
zone.run(async () => {
console.error('SSE aborted:', e);
this.status = ChannelStatus.CLOSED;
clearTimeout(this.isWaitingTimeout);
this.isWaiting = false;
this._isHotReloading = false;
await this.processMessageQueue();
this.dequeueEvent();
});
});
}

private initWebSocket(initParams: InitParams, request: UiRequest) {
Expand Down Expand Up @@ -217,16 +241,26 @@ export class Channel {
};

this.webSocket.onerror = (error) => {
zone.run(() => {
zone.run(async () => {
console.error('WebSocket error:', error);
this.status = ChannelStatus.CLOSED;
clearTimeout(this.isWaitingTimeout);
this.isWaiting = false;
this._isHotReloading = false;
await this.processMessageQueue();
this.dequeueEvent();
});
};

this.webSocket.onclose = (event) => {
zone.run(() => {
zone.run(async () => {
console.error('WebSocket closed:', event.reason);
this.status = ChannelStatus.CLOSED;
clearTimeout(this.isWaitingTimeout);
this.isWaiting = false;
this._isHotReloading = false;
await this.processMessageQueue();
this.dequeueEvent();

// Attempt to reconnect if we haven't exceeded max attempts
if (this.wsReconnectAttempts < this.wsMaxReconnectAttempts) {
Expand Down
Loading