@@ -48,18 +48,29 @@ export class NaoRobotModel extends DOMWidgetModel {
48
48
}
49
49
50
50
async connect ( ipAddress : string , port : string ) {
51
- console . log ( 'REMOVE the command was to connect' ) ;
52
- this . changeStatus ( 'Establishing connection' ) ;
51
+ const sleep = ( ms : number ) => new Promise ( ( r ) => setTimeout ( r , ms ) ) ;
53
52
53
+ this . changeStatus ( 'Establishing connection' ) ;
54
+ // TODO: check ipAddress is valid format
54
55
this . qiSession = new QiSession ( ipAddress , port ) ;
55
56
56
- console . log ( 'CONNECTED: ' , this . qiSession . isConnected ( ) ) ;
57
-
58
- this . connected = 'Connected' ;
59
- this . set ( 'connected' , 'Connected' ) ;
60
- this . save_changes ( ) ;
57
+ // Timeout after ~10 seconds
58
+ for ( let i = 0 ; i < 100 ; i ++ ) {
59
+ await sleep ( 100 ) ;
60
+ if ( this . qiSession . isConnected ( ) ) {
61
+ this . connected = 'Connected' ;
62
+ this . set ( 'connected' , 'Connected' ) ;
63
+ this . save_changes ( ) ;
64
+ this . changeStatus ( 'Available' ) ;
65
+ console . log ( "Connection successful after " , i / 10.0 , " seconds." ) ;
66
+ break ;
67
+ }
68
+ }
61
69
62
- this . changeStatus ( 'Not busy' ) ;
70
+ // Handle connection failure
71
+ if ( ! this . qiSession . isConnected ( ) ) {
72
+ this . changeStatus ( 'Unavailable' ) ;
73
+ }
63
74
}
64
75
65
76
disconnect ( ) {
@@ -98,7 +109,7 @@ export class NaoRobotModel extends DOMWidgetModel {
98
109
serviceName : string ,
99
110
methodName : string ,
100
111
args : any ,
101
- kwargs : any
112
+ _kwargs : any
102
113
) {
103
114
const naoService = await this . qiSession . service ( serviceName ) ;
104
115
0 commit comments