Skip to content

Commit d96ebda

Browse files
committed
Fix reconnect without initial IP
1 parent bc1fbe6 commit d96ebda

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/widget.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,29 @@ export class NaoRobotModel extends DOMWidgetModel {
110110
this.changeStatus('Unavailable');
111111
}
112112

113-
private async createService(serviceName: string) {
114-
// Reconnect as needed
113+
private async checkConnection() {
114+
// Cannot reconnect without initial connection
115+
if (!this._ipAddress) {
116+
this.send({
117+
isError: true,
118+
data: 'Cannot connect without IP Address.',
119+
});
120+
this.set('counter', this.get('counter') + 1);
121+
this.save_changes();
122+
return false;
123+
}
124+
125+
// Reconnect if possible
115126
if (!this.qiSession.isConnected()) {
116127
await this.connect(this._ipAddress, this._port);
117128
}
129+
return true;
130+
}
131+
132+
private async createService(serviceName: string) {
133+
134+
const isConnected : boolean = await this.checkConnection();
135+
if (!isConnected) return;
118136

119137
// Skip if service exists already
120138
if (this._services[serviceName] !== undefined) {
@@ -147,10 +165,8 @@ export class NaoRobotModel extends DOMWidgetModel {
147165
args: any,
148166
_kwargs: any
149167
) {
150-
// Reconnect as needed
151-
if (!this.qiSession.isConnected()) {
152-
await this.connect(this._ipAddress, this._port);
153-
}
168+
const isConnected : boolean = await this.checkConnection();
169+
if (!isConnected) return;
154170

155171
// Wait for service to become available
156172
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

0 commit comments

Comments
 (0)