Skip to content

Commit e0ad565

Browse files
committed
Moved the raw socket.io to a "private" property and using this.socket as message subject
1 parent 7280c8a commit e0ad565

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/daemon.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ import { Subject, BehaviorSubject } from 'rxjs';
22

33
export default class Daemon {
44
constructor() {
5-
this.socket = null;
5+
this._socket = null;
66
this.pluginURL = null;
7-
this.messageBus = new Subject();
7+
this.socket = new Subject();
88
this.serialMonitor = new Subject();
99
this.devicesList = new BehaviorSubject({
1010
serial: [],
1111
network: []
1212
});
13-
this.messageBus.subscribe(this.updateDevicesList.bind(this));
13+
this.socket.subscribe(this.updateDevicesList.bind(this));
1414
this.openingSerial = null;
1515
this.closingSerial = null;
1616
}
1717

1818
initSocket() {
19-
this.socket.on('message', this.parseMessage.bind(this));
19+
this._socket.on('message', this.parseMessage.bind(this));
2020
}
2121

2222
initPluginUrl(pluginUrl) {
@@ -56,10 +56,10 @@ export default class Daemon {
5656

5757
parseMessage(message) {
5858
try {
59-
this.messageBus.next(JSON.parse(message));
59+
this.socket.next(JSON.parse(message));
6060
}
6161
catch (SyntaxError) {
62-
this.messageBus.next(message);
62+
this.socket.next(message);
6363
}
6464
}
6565

@@ -85,12 +85,12 @@ export default class Daemon {
8585
return reject(new Error('Failed to open serial'));
8686
}
8787
};
88-
this.openSubscription = this.messageBus.subscribe(checkOpen);
88+
this.openSubscription = this.socket.subscribe(checkOpen);
8989
}).finally(() => {
9090
this.openSubscription.unsubscribe();
9191
this.openingSerial = null;
9292
});
93-
this.socket.emit('command', `open ${port} 9600 timed`);
93+
this._socket.emit('command', `open ${port} 9600 timed`);
9494
return this.openingSerial;
9595
}
9696

@@ -118,12 +118,12 @@ export default class Daemon {
118118
return reject(new Error('Failed to close serial'));
119119
}
120120
};
121-
this.closeSubscription = this.messageBus.subscribe(checkClosed);
121+
this.closeSubscription = this.socket.subscribe(checkClosed);
122122
}).finally(() => {
123123
this.closeSubscription.unsubscribe();
124124
this.closingSerial = null;
125125
});
126-
this.socket.emit('command', `close ${port}`);
126+
this._socket.emit('command', `close ${port}`);
127127
return this.closingSerial;
128128
}
129129

@@ -134,7 +134,7 @@ export default class Daemon {
134134
}
135135
};
136136
if (!this.readSerialSubscription) {
137-
this.readSerialSubscription = this.messageBus.subscribe(onMessage);
137+
this.readSerialSubscription = this.socket.subscribe(onMessage);
138138
}
139139
}
140140
}

src/socket-daemon.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default class SocketDaemon extends Daemon {
7878
interval(POLLING_INTERVAL)
7979
.pipe(startWith(0))
8080
.pipe(takeUntil(this.wsConnected.pipe(filter(status => !status))))
81-
.subscribe(() => this.socket.emit('command', 'list'));
81+
.subscribe(() => this._socket.emit('command', 'list'));
8282
}
8383
else {
8484
this.agentFound.next(false);
@@ -163,19 +163,19 @@ export default class SocketDaemon extends Daemon {
163163
_wsConnect() {
164164
const wsProtocol = this.selectedProtocol === PROTOCOL.HTTPS ? 'ws' : 'wss';
165165
const address = this.agentInfo[wsProtocol];
166-
this.socket = io(address, { reconnection: false, forceNew: true });
166+
this._socket = io(address, { reconnection: false, forceNew: true });
167167

168-
this.socket.on('connect', () => {
168+
this._socket.on('connect', () => {
169169
// On connect download windows drivers which are indispensable for detection of boards
170-
this.socket.emit('command', 'downloadtool windows-drivers latest arduino keep');
171-
this.socket.emit('command', 'downloadtool bossac 1.7.0 arduino keep');
170+
this._socket.emit('command', 'downloadtool windows-drivers latest arduino keep');
171+
this._socket.emit('command', 'downloadtool bossac 1.7.0 arduino keep');
172172

173173
this.wsConnected.next(true);
174174
});
175175

176-
this.socket.on('error', error => this.error.next(error));
176+
this._socket.on('error', error => this.error.next(error));
177177

178-
this.socket.on('disconnect', () => {
178+
this._socket.on('disconnect', () => {
179179
this.wsConnected.next(false);
180180
});
181181
}

0 commit comments

Comments
 (0)