Skip to content

Commit 2796a5f

Browse files
committed
Handle unexpected disconnections
1 parent bb043ec commit 2796a5f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/widget.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ export class NaoRobotModel extends DOMWidgetModel {
9797

9898
// Handle connection failure
9999
if (!this.qiSession.isConnected()) {
100+
this.disconnect();
100101
console.error('Connection to ', ipAddress, ' could not be established.');
101-
this.changeStatus('Unavailable');
102+
this.changeStatus('Connection to ' + ipAddress + ' could not be established.');
102103
}
103104
}
104105

@@ -126,6 +127,8 @@ export class NaoRobotModel extends DOMWidgetModel {
126127

127128
// Reconnect if possible
128129
if (!this.qiSession.isConnected()) {
130+
this.set('connected', 'Disconnected');
131+
this.save_changes();
129132
await this.connect(this._ipAddress, this._port);
130133
}
131134
return true;
@@ -188,6 +191,11 @@ export class NaoRobotModel extends DOMWidgetModel {
188191

189192
// Timeout after ~10 seconds
190193
for (let i = 0; i < 100; i++) {
194+
// Do not wait for service if there is no connection
195+
if (!this.qiSession.isConnected()) {
196+
this.disconnect();
197+
break;
198+
}
191199
if (this._services[serviceName]) {
192200
console.log('Service available after ', i / 10.0, ' seconds.');
193201
break;

0 commit comments

Comments
 (0)