@@ -34,8 +34,8 @@ import {
34
34
BehaviorSubject ,
35
35
interval
36
36
} from 'rxjs' ;
37
- import { parseMessage , initSocket , initPluginUrl } from './readMessages ' ;
38
- import { debug } from 'util' ;
37
+ import ReaderWriter from './reader-writer ' ;
38
+
39
39
// Required agent version
40
40
const MIN_VERSION = '1.1.71' ;
41
41
@@ -64,7 +64,33 @@ export default class SocketDaemon {
64
64
65
65
this . agentDiscoveryStatus = new BehaviorSubject ( AGENT_STATUS_NOT_FOUND ) ;
66
66
this . wsConnectionStatus = new BehaviorSubject ( WS_STATUS_DISCONNECTED ) ;
67
+ this . devicesListStatus = new Subject ( ) ;
67
68
this . wsError = new Subject ( ) ;
69
+
70
+ this . devicesList = {
71
+ serial : [ ] ,
72
+ network : [ ]
73
+ } ;
74
+
75
+ this . devicesListStatus . subscribe ( devicesInfo => {
76
+ if ( devicesInfo . Network ) {
77
+ this . devicesList . network = devicesInfo . Ports ;
78
+ }
79
+ else {
80
+ this . devicesList . serial = devicesInfo . Ports ;
81
+ }
82
+ console . log ( this . devicesList ) ;
83
+ } ) ;
84
+
85
+ this . readerWriter = null ;
86
+ this . wsConnectionStatus . subscribe ( status => {
87
+ if ( status === WS_STATUS_CONNECTED ) {
88
+ this . readerWriter = new ReaderWriter ( this . socket , this . agentInfo [ this . selectedProtocol ] , this . devicesListStatus ) ;
89
+ }
90
+ else {
91
+ this . readerWriter = null ;
92
+ }
93
+ } ) ;
68
94
}
69
95
70
96
/**
@@ -100,7 +126,6 @@ export default class SocketDaemon {
100
126
* @return {object } info - The agent info values.
101
127
*/
102
128
tryPorts ( hostname ) {
103
- console . log ( 'tryPorts\n' ) ;
104
129
const pluginLookups = [ ] ;
105
130
106
131
for ( let port = LOOKUP_PORT_START ; port < LOOKUP_PORT_END ; port += 1 ) {
@@ -121,7 +146,6 @@ export default class SocketDaemon {
121
146
if ( r . response . url . indexOf ( PROTOCOL . HTTPS ) === 0 ) {
122
147
this . selectedProtocol = PROTOCOL . HTTPS ;
123
148
}
124
- initPluginUrl ( this . agentInfo [ this . selectedProtocol ] ) ;
125
149
return true ;
126
150
}
127
151
return false ;
@@ -149,8 +173,6 @@ export default class SocketDaemon {
149
173
this . socket = io ( address , { reconnection : false , forceNew : true } ) ;
150
174
151
175
this . socket . on ( 'connect' , ( ) => {
152
- initSocket ( this . socket ) ;
153
-
154
176
// On connect download windows drivers which are indispensable for detection of boards
155
177
this . socket . emit ( 'command' , 'downloadtool windows-drivers latest arduino keep' ) ;
156
178
this . socket . emit ( 'command' , 'downloadtool bossac 1.7.0 arduino keep' ) ;
@@ -173,9 +195,6 @@ export default class SocketDaemon {
173
195
this . wsConnectionStatus . next ( WS_STATUS_DISCONNECTED ) ;
174
196
this . findAgent ( ) ;
175
197
} ) ;
176
-
177
- // Parse messages
178
- this . socket . on ( 'message' , parseMessage ) ;
179
198
}
180
199
181
200
/**
@@ -188,7 +207,10 @@ export default class SocketDaemon {
188
207
}
189
208
190
209
return fetch ( `${ this . agentInfo [ this . selectedProtocol ] } /update` , {
191
- method : 'POST'
210
+ method : 'POST' ,
211
+ headers : {
212
+ 'Content-Type' : 'text/plain; charset=utf-8'
213
+ }
192
214
} ) . then ( ( ) => reject ( ) ) ; // We reject the promise because the daemon will be restarted, we need to continue looking for the port
193
215
} ) ;
194
216
}
0 commit comments