Skip to content

Commit 7ccf61a

Browse files
committed
Some nitpicks II
1 parent 3033a25 commit 7ccf61a

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/js/protocols/CapacitorTcp.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff 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) {

0 commit comments

Comments
 (0)