@@ -83,7 +83,7 @@ export class NaoRobotModel extends DOMWidgetModel {
83
83
this . qiSession = new QiSession ( ipAddress , port ) ;
84
84
85
85
// Timeout after ~10 seconds
86
- for ( let i = 0 ; i < 10 ; i ++ ) {
86
+ for ( let i = 0 ; i < 100 ; i ++ ) {
87
87
if ( this . qiSession . isConnected ( ) ) {
88
88
this . connected = 'Connected' ;
89
89
this . set ( 'connected' , 'Connected' ) ;
@@ -103,7 +103,9 @@ export class NaoRobotModel extends DOMWidgetModel {
103
103
}
104
104
105
105
disconnect ( ) {
106
- this . qiSession . disconnect ( ) ;
106
+ if ( this . qiSession ) {
107
+ this . qiSession . disconnect ( ) ;
108
+ } ;
107
109
this . _services = { } ;
108
110
this . set ( 'connected' , 'Disconnected' ) ;
109
111
this . save_changes ( ) ;
@@ -136,7 +138,7 @@ export class NaoRobotModel extends DOMWidgetModel {
136
138
}
137
139
138
140
// Skip if service exists already
139
- if ( this . _services [ serviceName ] !== undefined ) {
141
+ if ( this . _services [ serviceName ] ) {
140
142
console . log ( 'Service ' + serviceName + ' exists.' ) ;
141
143
return ;
142
144
}
@@ -186,14 +188,14 @@ export class NaoRobotModel extends DOMWidgetModel {
186
188
187
189
// Timeout after ~10 seconds
188
190
for ( let i = 0 ; i < 100 ; i ++ ) {
189
- if ( this . _services [ serviceName ] !== undefined ) {
191
+ if ( this . _services [ serviceName ] ) {
190
192
console . log ( 'Service available after ' , i / 10.0 , ' seconds.' ) ;
191
193
break ;
192
194
}
193
195
await sleep ( 100 ) ;
194
196
}
195
197
196
- if ( this . _services [ serviceName ] === undefined ) {
198
+ if ( ! this . _services [ serviceName ] ) {
197
199
this . changeStatus ( serviceName + ' not available' ) ;
198
200
this . send ( {
199
201
isError : true ,
@@ -204,7 +206,7 @@ export class NaoRobotModel extends DOMWidgetModel {
204
206
return ;
205
207
}
206
208
207
- if ( this . _services [ serviceName ] [ methodName ] === undefined ) {
209
+ if ( ! this . _services [ serviceName ] [ methodName ] ) {
208
210
this . changeStatus ( `${ methodName } does not exist for ${ serviceName } ` ) ;
209
211
this . send ( {
210
212
isError : true ,
0 commit comments