@@ -54,10 +54,12 @@ export class NaoRobotModel extends DOMWidgetModel {
54
54
55
55
private validateIPaddress ( ipAddress : string ) {
56
56
// TODO: validate port also
57
- if ( ipAddress == 'nao.local' ) {
57
+ if ( ipAddress === 'nao.local' ) {
58
58
return true ;
59
59
} else {
60
- const regexp = new RegExp ( '^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}$' ) ;
60
+ const regexp = new RegExp (
61
+ '^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(.(?!$)|$)){4}$'
62
+ ) ;
61
63
return regexp . test ( ipAddress ) ;
62
64
}
63
65
}
@@ -83,16 +85,16 @@ export class NaoRobotModel extends DOMWidgetModel {
83
85
this . set ( 'connected' , 'Connected' ) ;
84
86
this . save_changes ( ) ;
85
87
this . changeStatus ( 'Available' ) ;
86
- console . log ( " Connection successful after " , i / 10.0 , " seconds." ) ;
88
+ console . log ( ' Connection successful after ' , i / 10.0 , ' seconds.' ) ;
87
89
break ;
88
90
}
89
91
}
90
92
91
93
// Handle connection failure
92
94
if ( ! this . qiSession . isConnected ( ) ) {
93
- console . error ( " Connection to " , ipAddress , " could not be established." ) ;
95
+ console . error ( ' Connection to ' , ipAddress , ' could not be established.' ) ;
94
96
this . changeStatus ( 'Unavailable' ) ;
95
- }
97
+ }
96
98
}
97
99
98
100
disconnect ( ) {
@@ -103,26 +105,21 @@ export class NaoRobotModel extends DOMWidgetModel {
103
105
this . changeStatus ( 'Unavailable' ) ;
104
106
}
105
107
106
-
107
- private async createService (
108
- serviceName : string ,
109
- ) {
108
+ private async createService ( serviceName : string ) {
110
109
this . changeStatus ( 'Creating service ' + serviceName ) ;
111
110
const servicePromise = this . qiSession . service ( serviceName ) ;
112
111
113
- const naoService = await servicePromise . then (
114
- ( resolution : object ) => {
112
+ const naoService = await servicePromise
113
+ . then ( ( resolution : any ) => {
115
114
return resolution ;
116
- }
117
- ) . catch (
118
- ( rejection : string ) => {
115
+ } )
116
+ . catch ( ( rejection : string ) => {
119
117
this . changeStatus ( rejection ) ;
120
118
return rejection ;
121
- }
122
- ) ;
119
+ } ) ;
123
120
124
121
// Store service only when successfully created
125
- if ( typeof ( naoService ) === 'object' ) {
122
+ if ( typeof naoService === 'object' ) {
126
123
this . _services [ serviceName ] = naoService ;
127
124
this . changeStatus ( serviceName + ' available' ) ;
128
125
}
@@ -143,27 +140,25 @@ export class NaoRobotModel extends DOMWidgetModel {
143
140
this . changeStatus ( 'Running method ' + methodName ) ;
144
141
145
142
const servicePromise = this . _services [ serviceName ] [ methodName ] ( ...args ) ;
146
- await servicePromise . then (
147
- ( resolution : any ) => {
143
+ await servicePromise
144
+ . then ( ( resolution : any ) => {
148
145
this . changeStatus ( 'Task completed' ) ;
149
146
if ( resolution !== undefined ) {
150
- this . send ( resolution )
147
+ this . send ( resolution ) ;
151
148
}
152
- }
153
- ) . catch (
154
- ( rejection : string ) => {
149
+ } )
150
+ . catch ( ( rejection : string ) => {
155
151
this . changeStatus ( rejection ) ;
156
152
this . send ( rejection ) ;
157
- }
158
- ) ;
153
+ } ) ;
159
154
160
155
this . set ( 'counter' , this . get ( 'counter' ) + 1 ) ;
161
156
this . save_changes ( ) ;
162
157
}
163
158
164
159
private async onCommand ( commandData : any , buffers : any ) {
165
160
const cmd = commandData [ 'command' ] ;
166
-
161
+
167
162
switch ( cmd ) {
168
163
case 'connect' :
169
164
await this . connect ( commandData [ 'ipAddress' ] , commandData [ 'port' ] ) ;
@@ -186,7 +181,6 @@ export class NaoRobotModel extends DOMWidgetModel {
186
181
) ;
187
182
break ;
188
183
}
189
-
190
184
}
191
185
192
186
static serializers : ISerializers = {
0 commit comments