Skip to content

Commit ecacb40

Browse files
committed
Handle reconnect on streamReset event in Vitals Monitor
1 parent a8921ca commit ecacb40

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/web-components/VitalLensVitalsMonitor.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,36 @@ class VitalLensVitalsMonitor extends VitalLensWidgetBase {
139139
}
140140
}
141141

142+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
143+
protected async handleStreamReset(event: { message: string }): Promise<void> {
144+
this.statusIndicator.className = 'status-indicator status-issue';
145+
this.statusTextElement.textContent = 'Reconnecting...';
146+
this.vitalsContentElement.style.display = 'none';
147+
this.feedbackMessageElement.textContent =
148+
'Connection unstable. Reconnecting...';
149+
this.feedbackMessageElement.style.display = 'block';
150+
151+
if (this.vitalLensInstance) {
152+
this.vitalLensInstance.stopVideoStream();
153+
}
154+
if (this.mediaStream) {
155+
this.mediaStream.getTracks().forEach((track) => track.stop());
156+
this.mediaStream = null;
157+
}
158+
159+
this.isProcessingFlag = false;
160+
161+
await new Promise((resolve) => setTimeout(resolve, 3000));
162+
163+
try {
164+
await this.toggleProcessing();
165+
} catch (err) {
166+
console.error('Failed to automatically restart monitor:', err);
167+
this.showError('Could not restart. Please click to try again.');
168+
this.resetUI();
169+
}
170+
}
171+
142172
protected updateUI(result: VitalLensResult): void {
143173
// const { heart_rate, respiratory_rate, hrv_sdnn } = result.vital_signs;
144174
// const debugLog = {

0 commit comments

Comments
 (0)