Skip to content

Commit bb043ec

Browse files
committed
Fix disconnect error when no connection
1 parent 26d8bb6 commit bb043ec

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/widget.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class NaoRobotModel extends DOMWidgetModel {
8383
this.qiSession = new QiSession(ipAddress, port);
8484

8585
// Timeout after ~10 seconds
86-
for (let i = 0; i < 10; i++) {
86+
for (let i = 0; i < 100; i++) {
8787
if (this.qiSession.isConnected()) {
8888
this.connected = 'Connected';
8989
this.set('connected', 'Connected');
@@ -103,7 +103,9 @@ export class NaoRobotModel extends DOMWidgetModel {
103103
}
104104

105105
disconnect() {
106-
this.qiSession.disconnect();
106+
if (this.qiSession) {
107+
this.qiSession.disconnect();
108+
};
107109
this._services = {};
108110
this.set('connected', 'Disconnected');
109111
this.save_changes();
@@ -136,7 +138,7 @@ export class NaoRobotModel extends DOMWidgetModel {
136138
}
137139

138140
// Skip if service exists already
139-
if (this._services[serviceName] !== undefined) {
141+
if (this._services[serviceName]) {
140142
console.log('Service ' + serviceName + ' exists.');
141143
return;
142144
}
@@ -186,14 +188,14 @@ export class NaoRobotModel extends DOMWidgetModel {
186188

187189
// Timeout after ~10 seconds
188190
for (let i = 0; i < 100; i++) {
189-
if (this._services[serviceName] !== undefined) {
191+
if (this._services[serviceName]) {
190192
console.log('Service available after ', i / 10.0, ' seconds.');
191193
break;
192194
}
193195
await sleep(100);
194196
}
195197

196-
if (this._services[serviceName] === undefined) {
198+
if (!this._services[serviceName]) {
197199
this.changeStatus(serviceName + ' not available');
198200
this.send({
199201
isError: true,
@@ -204,7 +206,7 @@ export class NaoRobotModel extends DOMWidgetModel {
204206
return;
205207
}
206208

207-
if (this._services[serviceName][methodName] === undefined) {
209+
if (!this._services[serviceName][methodName]) {
208210
this.changeStatus(`${methodName} does not exist for ${serviceName}`);
209211
this.send({
210212
isError: true,

0 commit comments

Comments
 (0)