Skip to content

Commit 1c11ef5

Browse files
author
Stefania
committed
minor cleanup, updated naming
1 parent f7a0def commit 1c11ef5

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ daemon.agentFound.subscribe(status => {
1818
// true / false
1919
});
2020

21-
daemon.wsConnected.subscribe(status => {
21+
daemon.channelOpen.subscribe(status => {
2222
// true / false
2323
});
2424

src/chrome-app-daemon.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
*/
2929
import {
3030
Subject,
31-
BehaviorSubject,
3231
interval
3332
} from 'rxjs';
3433
import { filter, startWith, takeUntil } from 'rxjs/operators';
@@ -40,21 +39,17 @@ export default class ChromeOsDaemon extends Daemon {
4039
constructor(chromeExtensionId) {
4140
super();
4241
this.channel = null;
43-
this.agentInfo = {};
44-
this.agentFound = new BehaviorSubject(null);
45-
this.wsConnected = new BehaviorSubject(null);
4642
this.appMessages = new Subject();
47-
this.error = new Subject();
4843

4944
this.appMessages
5045
.subscribe(this.handleAppMessage.bind(this));
5146

52-
this.wsConnected
53-
.subscribe(wsConnected => {
54-
if (wsConnected) {
47+
this.channelOpen
48+
.subscribe(channelOpen => {
49+
if (channelOpen) {
5550
interval(POLLING_INTERVAL)
5651
.pipe(startWith(0))
57-
.pipe(takeUntil(this.wsConnected.pipe(filter(status => !status))))
52+
.pipe(takeUntil(this.channelOpen.pipe(filter(status => !status))))
5853
.subscribe(() => this.channel.postMessage({
5954
command: 'listPorts'
6055
}));
@@ -78,14 +73,14 @@ export default class ChromeOsDaemon extends Daemon {
7873
if (message.version) {
7974
this.agentInfo = message;
8075
this.agentFound.next(true);
81-
this.wsConnected.next(true);
76+
this.channelOpen.next(true);
8277
}
8378
else {
8479
this.appMessages.next(message);
8580
}
8681
});
8782
this.channel.onDisconnect.addListener(() => {
88-
this.wsConnected.next(false);
83+
this.channelOpen.next(false);
8984
this.agentFound.next(false);
9085
});
9186
}

src/daemon.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export default class Daemon {
1010
constructor() {
1111
this.socket = null;
1212
this.pluginURL = null;
13+
this.agentInfo = {};
14+
this.agentFound = new BehaviorSubject(null);
15+
this.channelOpen = new BehaviorSubject(null);
16+
this.error = new Subject();
1317
this.socketMessages = new Subject();
1418
this.serialMonitorOpened = new BehaviorSubject(false);
1519
this.serialMonitorMessages = new Subject();

src/socket-daemon.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import semVerCompare from 'semver-compare';
3232
import { detect } from 'detect-browser';
3333

3434
import {
35-
Subject,
36-
BehaviorSubject,
3735
interval,
3836
timer
3937
} from 'rxjs';
@@ -66,18 +64,14 @@ export default class SocketDaemon extends Daemon {
6664
constructor() {
6765
super();
6866
this.selectedProtocol = PROTOCOL.HTTP;
69-
this.agentInfo = {};
70-
this.agentFound = new BehaviorSubject(null);
71-
this.wsConnected = new BehaviorSubject(null);
72-
this.error = new Subject();
73-
74-
this.wsConnected
75-
.subscribe(wsConnected => {
76-
if (wsConnected) {
67+
68+
this.channelOpen
69+
.subscribe(channelOpen => {
70+
if (channelOpen) {
7771
this.initSocket();
7872
interval(POLLING_INTERVAL)
7973
.pipe(startWith(0))
80-
.pipe(takeUntil(this.wsConnected.pipe(filter(status => !status))))
74+
.pipe(takeUntil(this.channelOpen.pipe(filter(status => !status))))
8175
.subscribe(() => this.socket.emit('command', 'list'));
8276
}
8377
else {
@@ -170,13 +164,13 @@ export default class SocketDaemon extends Daemon {
170164
this.socket.emit('command', 'downloadtool windows-drivers latest arduino keep');
171165
this.socket.emit('command', 'downloadtool bossac 1.7.0 arduino keep');
172166

173-
this.wsConnected.next(true);
167+
this.channelOpen.next(true);
174168
});
175169

176170
this.socket.on('error', error => this.error.next(error));
177171

178172
this.socket.on('disconnect', () => {
179-
this.wsConnected.next(false);
173+
this.channelOpen.next(false);
180174
});
181175
}
182176

test/app.jsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class App extends React.Component {
2323
this.state = {
2424
error: '',
2525
agentStatus: false,
26-
wsStatus: false,
26+
channelStatus: false,
2727
serialDevices: [],
2828
networkDevices: [],
2929
agentInfo: '',
@@ -49,8 +49,8 @@ class App extends React.Component {
4949
});
5050
});
5151

52-
daemon.wsConnected.subscribe(status => {
53-
this.setState({ wsStatus: status });
52+
daemon.channelOpen.subscribe(status => {
53+
this.setState({ channelStatus: status });
5454
});
5555

5656
daemon.error.subscribe(this.showError);
@@ -171,28 +171,28 @@ class App extends React.Component {
171171
<h1>Test Arduino Create Plugin</h1>
172172

173173
<p>
174-
Agent status: <span id="agent-status" className={ this.state.agentStatus ? 'found' : 'not-found' }>
174+
Agent status: <span className={ this.state.agentStatus ? 'found' : 'not-found' }>
175175
{ this.state.agentStatus ? 'Found' : 'Not found' }
176176
</span>
177177
</p>
178178
<p>
179-
Web socket status: <span id="ws-status" className={ this.state.wsStatus ? 'found' : 'not-found' }>
180-
{ this.state.wsStatus ? 'Connected' : 'Not connected' }
179+
Web socket status: <span className={ this.state.channelStatus ? 'found' : 'not-found' }>
180+
{ this.state.channelStatus ? 'Connected' : 'Not connected' }
181181
</span>
182182
</p>
183183

184-
<pre id="agent-info">
184+
<pre>
185185
{ this.state.agentInfo }
186186
</pre>
187187

188188
<div className="section">
189189
<h2>Devices</h2>
190190
<strong>serial:</strong>
191-
<ul id="serial-list">
191+
<ul>
192192
{ listSerialDevices }
193193
</ul>
194194
<strong>network:</strong>
195-
<ul id="network-list">
195+
<ul>
196196
{ listNetworkDevices }
197197
</ul>
198198
<p id="error"></p>

0 commit comments

Comments
 (0)