File tree Expand file tree Collapse file tree 1 file changed +6
-8
lines changed
Expand file tree Collapse file tree 1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ class CapacitorTcp extends EventTarget {
3939
4040 this . address = "http://localhost:5761" ;
4141
42- this . socket = null ;
4342 this . plugin = BetaflightTcp ;
4443
4544 this . connect = this . connect . bind ( this ) ;
@@ -115,7 +114,7 @@ class CapacitorTcp extends EventTarget {
115114 } else {
116115 throw new Error ( "Connect failed" ) ;
117116 }
118- this . dispatchEvent ( new CustomEvent ( "connect" , { detail : this . address } ) ) ; // TODO need to check result detail
117+ this . dispatchEvent ( new CustomEvent ( "connect" , { detail : this . address } ) ) ;
119118 } catch ( e ) {
120119 console . error ( `${ this . logHead } Failed to connect to socket: ${ e } ` ) ;
121120 this . connected = false ;
@@ -124,20 +123,19 @@ class CapacitorTcp extends EventTarget {
124123 }
125124
126125 async disconnect ( ) {
126+ this . connected = false ;
127+ this . bytesReceived = 0 ;
128+ this . bytesSent = 0 ;
129+
127130 try {
128131 const res = await this . plugin . disconnect ( ) ;
129132 if ( res . success ) {
130- this . connected = false ;
133+ this . dispatchEvent ( new CustomEvent ( "disconnect" , { detail : true } ) ) ;
131134 }
132- this . dispatchEvent ( new CustomEvent ( "disconnect" , { detail : true } ) ) ;
133135 } catch ( e ) {
134136 console . error ( `${ this . logHead } Failed to close connection: ${ e } ` ) ;
135137 this . dispatchEvent ( new CustomEvent ( "disconnect" , { detail : false } ) ) ;
136138 }
137-
138- this . connected = false ;
139- this . bytesReceived = 0 ;
140- this . bytesSent = 0 ;
141139 }
142140
143141 async send ( data , cb ) {
You can’t perform that action at this time.
0 commit comments