@@ -25,6 +25,8 @@ export class NaoRobotModel extends DOMWidgetModel {
25
25
connected = 'Disconnected' ;
26
26
status = 'Not busy' ;
27
27
_services : serviceDict = { } ;
28
+ _ipAddress : string ;
29
+ _port : string ;
28
30
29
31
defaults ( ) {
30
32
return {
@@ -75,6 +77,9 @@ export class NaoRobotModel extends DOMWidgetModel {
75
77
return ;
76
78
}
77
79
80
+ this . _ipAddress = ipAddress ;
81
+ this . _port = port ;
82
+
78
83
this . qiSession = new QiSession ( ipAddress , port ) ;
79
84
80
85
// Timeout after ~10 seconds
@@ -98,14 +103,19 @@ export class NaoRobotModel extends DOMWidgetModel {
98
103
}
99
104
100
105
disconnect ( ) {
101
- console . log ( 'REMOVE disconnecting' ) ;
102
106
this . qiSession . disconnect ( ) ;
107
+ this . _services = { } ;
103
108
this . set ( 'connected' , 'Disconnected' ) ;
104
109
this . save_changes ( ) ;
105
110
this . changeStatus ( 'Unavailable' ) ;
106
111
}
107
112
108
113
private async createService ( serviceName : string ) {
114
+ // Reconnect as needed
115
+ if ( ! this . qiSession . isConnected ( ) ) {
116
+ await this . connect ( this . _ipAddress , this . _port ) ;
117
+ }
118
+
109
119
// Skip if service exists already
110
120
if ( this . _services [ serviceName ] !== undefined ) {
111
121
console . log ( "Service " + serviceName + " exists." ) ;
@@ -137,6 +147,12 @@ export class NaoRobotModel extends DOMWidgetModel {
137
147
args : any ,
138
148
_kwargs : any
139
149
) {
150
+
151
+ // Reconnect as needed
152
+ if ( ! this . qiSession . isConnected ( ) ) {
153
+ await this . connect ( this . _ipAddress , this . _port ) ;
154
+ }
155
+
140
156
// Wait for service to become available
141
157
const sleep = ( ms : number ) => new Promise ( ( r ) => setTimeout ( r , ms ) ) ;
142
158
0 commit comments