Skip to content

Commit 0140cb7

Browse files
authored
Close WebSocket when removing device. (#84)
Fixes WebThingsIO/gateway#2364
1 parent a12f015 commit 0140cb7

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@
4141
}
4242
},
4343
"short_name": "Web Thing",
44-
"version": "0.4.3"
44+
"version": "0.4.4"
4545
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "thing-url-adapter",
33
"display_name": "Web Thing",
4-
"version": "0.4.3",
4+
"version": "0.4.4",
55
"description": "Native web thing support",
66
"author": "Mozilla IoT",
77
"main": "index.js",

thing-url-adapter.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class ThingURLDevice extends Device {
211211
} else if (link.href.startsWith('ws://') ||
212212
link.href.startsWith('wss://')) {
213213
this.wsUrl = link.href;
214-
this.createWebsocket();
214+
this.createWebSocket();
215215
} else {
216216
this.links.push(link);
217217
}
@@ -231,20 +231,20 @@ class ThingURLDevice extends Device {
231231
}
232232
}
233233

234-
closeWebsocket() {
234+
closeWebSocket() {
235235
this.closing = true;
236236
if (this.ws !== null) {
237237
if (this.ws.readyState === WebSocket.OPEN) {
238238
this.ws.close();
239239
}
240240

241-
// Allow the cleanup code in createWebsocket to handle shutdown
241+
// Allow the cleanup code in createWebSocket to handle shutdown
242242
} else if (this.scheduledUpdate) {
243243
clearTimeout(this.scheduledUpdate);
244244
}
245245
}
246246

247-
createWebsocket() {
247+
createWebSocket() {
248248
if (this.closing) {
249249
return;
250250
}
@@ -330,7 +330,7 @@ class ThingURLDevice extends Device {
330330

331331
setTimeout(() => {
332332
this.wsBackoff = Math.min(this.wsBackoff * 2, WS_MAX_BACKOFF);
333-
this.createWebsocket();
333+
this.createWebSocket();
334334
}, this.wsBackoff);
335335
};
336336

@@ -580,7 +580,7 @@ class ThingURLAdapter extends Adapter {
580580
for (const id in this.devices) {
581581
const device = this.devices[id];
582582
if (device.mdnsUrl === url) {
583-
device.closeWebsocket();
583+
device.closeWebSocket();
584584
this.removeThing(device);
585585
}
586586
}
@@ -621,6 +621,7 @@ class ThingURLAdapter extends Adapter {
621621
return this.removeDeviceFromConfig(device).then(() => {
622622
if (this.devices.hasOwnProperty(device.id)) {
623623
this.handleDeviceRemoved(device);
624+
device.closeWebSocket();
624625
return device;
625626
} else {
626627
throw new Error(`Device: ${device.id} not found.`);
@@ -678,7 +679,7 @@ class ThingURLAdapter extends Adapter {
678679
}
679680

680681
for (const id in this.devices) {
681-
this.devices[id].closeWebsocket();
682+
this.devices[id].closeWebSocket();
682683
}
683684

684685
return super.unload();

0 commit comments

Comments
 (0)