Skip to content

Commit 4083caa

Browse files
committed
Test auto reconnect
1 parent 418121b commit 4083caa

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jderobot-commsmanager",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"main": "dist/main.js",
55
"typings": "dist/index.d.ts",
66
"scripts": {

src/components/CommsManager.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default class CommsManager {
1414
private observers: { [id: string]: Function[] } = {};
1515
private pendingPromises: Map<string, PromiseHandlers> = new Map();
1616
private static state: string = "idle";
17+
private static adress: string = "ws://127.0.0.1:7163";
1718
private static universe?: string;
1819
private static hostData?: {
1920
gpu_avaliable: string;
@@ -22,8 +23,8 @@ export default class CommsManager {
2223
};
2324

2425
// Private constructor to only allow single instatiation
25-
private constructor(address: string) {
26-
this.ws = new WebSocket(address);
26+
private constructor() {
27+
this.ws = new WebSocket(CommsManager.adress);
2728
this.subscribe(events.STATE_CHANGED, this.setManagerState);
2829
this.subscribeOnce(events.INTROSPECTION, this.setHostData);
2930

@@ -58,19 +59,21 @@ export default class CommsManager {
5859
this.ws.onclose = (e) => {
5960
if (e.wasClean) {
6061
console.log(
61-
`Connection with ${address} closed, all suscribers cleared`
62+
`Connection with ${CommsManager.adress} closed, all suscribers cleared`
6263
);
6364
} else {
64-
console.log(`Connection with ${address} interrupted`);
65+
console.log(`Connection with ${CommsManager.adress} interrupted`);
66+
delete CommsManager.instance;
67+
CommsManager.instance = new CommsManager();
6568
}
6669
};
6770
}
6871

6972
// Singleton behavior
7073
public static getInstance(address?: string): CommsManager {
71-
const newAddress = address ? address : "ws://127.0.0.1:7163"
7274
if (!CommsManager.instance) {
73-
CommsManager.instance = new CommsManager(newAddress);
75+
CommsManager.adress = address ? address : "ws://127.0.0.1:7163"
76+
CommsManager.instance = new CommsManager();
7477
}
7578
return CommsManager.instance;
7679
}

0 commit comments

Comments
 (0)