Various fixes
This commit is contained in:
@@ -30,7 +30,7 @@ const OpCodes = {
|
||||
export default class SwimTrackerWebsocketConnection {
|
||||
constructor(swimTrackerHost, onData, onStarted, onStopped, onWifiStateInfo, onConnect, onDisconnect) {
|
||||
this.swimTrackerHost = swimTrackerHost;
|
||||
|
||||
|
||||
this.onData = onData;
|
||||
this.onStarted = onStarted;
|
||||
this.onStopped = onStopped;
|
||||
@@ -41,6 +41,7 @@ export default class SwimTrackerWebsocketConnection {
|
||||
const wsOptions = {
|
||||
maxReconnectionDelay: 4000
|
||||
};
|
||||
|
||||
this.ws = new ReconnectingWebSocket(`ws://${swimTrackerHost}:81`, [], wsOptions);
|
||||
this.ws.onmessage = this._onMessage;
|
||||
this.ws.onopen = this.onConnect;
|
||||
@@ -58,6 +59,15 @@ export default class SwimTrackerWebsocketConnection {
|
||||
this._wifiScanPromises = [];
|
||||
}
|
||||
|
||||
close() {
|
||||
this.ws.onmessage = null;
|
||||
this.ws.onopen = null;
|
||||
this.ws.onclose = null;
|
||||
this.ws.onerror = null;
|
||||
this.ws.close();
|
||||
this.ws = null;
|
||||
}
|
||||
|
||||
sendStartCommand() {
|
||||
this._sendMsg(OpCodes.START_SESSION);
|
||||
}
|
||||
@@ -95,6 +105,7 @@ export default class SwimTrackerWebsocketConnection {
|
||||
}
|
||||
|
||||
wifiSetModeSTA(ssid, password) {
|
||||
console.log("Setting sta mode", ssid, password);
|
||||
this._sendMsg(OpCodes.WIFI_STATE_SET, {
|
||||
"sta_ssid": ssid,
|
||||
"sta_password": password,
|
||||
@@ -108,7 +119,7 @@ export default class SwimTrackerWebsocketConnection {
|
||||
msg = new Uint8Array([code, ...serializedData]);
|
||||
} else {
|
||||
msg = new Uint8Array(1);
|
||||
msg[0] = OpCodes.WIFI_TRIGGER_SCAN;
|
||||
msg[0] = code;
|
||||
}
|
||||
this.ws.send(msg);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user