@@ -19,13 +19,20 @@ export default class WebSerialDaemon extends Daemon {
1919 this . agentFound . next ( true ) ;
2020 this . channelOpenStatus . next ( true ) ;
2121 this . uploader = uploader ;
22+ this . connectedPorts = [ ] ;
2223
23- this . _populateSupportedBoards ( ) ;
24+ this . init ( ) ;
2425 }
2526
26- _populateSupportedBoards ( ) {
27+ init ( ) {
2728 const supportedBoards = this . uploader . getSupportedBoards ( ) ;
2829 this . appMessages . next ( { supportedBoards } ) ;
30+
31+ this . uploader . listBoards ( ) . then ( ports => {
32+ this . connectedPorts = ports ;
33+ this . appMessages . next ( { ports } ) ;
34+ } ) ;
35+
2936 }
3037
3138 // eslint-disable-next-line class-methods-use-this
@@ -41,10 +48,35 @@ export default class WebSerialDaemon extends Daemon {
4148 } ) ;
4249 // this.handleListMessage(message);
4350 }
44-
45- if ( message . supportedBoards ) {
51+ else if ( message . supportedBoards ) {
4652 this . supportedBoards . next ( message . supportedBoards ) ;
4753 }
54+ else if ( message . connectedSerialPort ) {
55+ console . dir ( '******** BEGIN: web-serial-daemon:68 ********' ) ;
56+ console . dir ( message . connectedSerialPort , { depth : null , colors : true } ) ;
57+
58+ const port = this . uploader . getBoardInfoFromSerialPort ( message . connectedSerialPort ) ;
59+ this . connectedPorts . push ( port ) ;
60+ console . dir ( this . connectedPorts , { depth : null , colors : true } ) ;
61+ console . dir ( '******** END: web-serial-daemon:68 ********' ) ;
62+ this . devicesList . next ( {
63+ serial : this . connectedPorts ,
64+ network : [ ]
65+ } ) ;
66+ }
67+ else if ( message . disconnectedSerialPort ) {
68+ console . dir ( '******** BEGIN: web-serial-daemon:79 ********' ) ;
69+ console . dir ( message . disconnectedSerialPort , { depth : null , colors : true } ) ;
70+ const port = this . uploader . getBoardInfoFromSerialPort ( message . disconnectedSerialPort ) ;
71+ this . connectedPorts = this . connectedPorts . filter ( connectedPort => connectedPort . Name !== port . Name ) ;
72+ console . dir ( this . connectedPorts , { depth : null , colors : true } ) ;
73+ console . dir ( '******** END: web-serial-daemon:79 ********' ) ;
74+ console . dir ( this . connectedPorts , { depth : null , colors : true } ) ;
75+ this . devicesList . next ( {
76+ serial : this . connectedPorts ,
77+ network : [ ]
78+ } ) ;
79+ }
4880 }
4981
5082 /**
@@ -90,6 +122,15 @@ export default class WebSerialDaemon extends Daemon {
90122 } ) ;
91123 }
92124
125+ /** A proxy method to get info from the specified SerialPort object */
126+ getBoardInfoFromSerialPort ( serialPort ) {
127+ return this . uploader . getBoardInfoFromSerialPort ( serialPort ) ;
128+ }
129+
130+ connectToSerialDevice ( ) {
131+ return this . uploader . connectToSerialDevice ( ) ;
132+ }
133+
93134 /**
94135 * @param {object } uploadPayload
95136 * TODO: document param's shape
0 commit comments