|
|
|
@ -1,7 +1,7 @@ |
|
|
|
import {Injectable} from "@angular/core"; |
|
|
|
import {WebSocketSubject} from "rxjs/internal/observable/dom/WebSocketSubject"; |
|
|
|
import {webSocket} from "rxjs/webSocket"; |
|
|
|
import {BehaviorSubject} from "rxjs"; |
|
|
|
import {BehaviorSubject, delay, retryWhen, tap} from "rxjs"; |
|
|
|
|
|
|
|
export const WS_EVENT_CHANNEL = 0; |
|
|
|
export const WS_EVENT_NODE = 1; |
|
|
|
@ -18,6 +18,7 @@ export const WAIT_CONFIG = 1; |
|
|
|
export const AVAILABLE = 2; |
|
|
|
export const ERR = 3; |
|
|
|
export const RECONNECT = 4; |
|
|
|
export const WS_ERR = 5; |
|
|
|
|
|
|
|
interface MeshNodeShort { |
|
|
|
id: number; |
|
|
|
@ -33,7 +34,7 @@ interface MeshChannel { |
|
|
|
providedIn: 'root' |
|
|
|
}) |
|
|
|
export class MeshtasticService { |
|
|
|
private socket$?: WebSocketSubject<any>; |
|
|
|
private socket$?: any; |
|
|
|
public channels: MeshChannel[] = []; |
|
|
|
public nodes: MeshNodeShort[] = []; |
|
|
|
public messages = new BehaviorSubject('{}') |
|
|
|
@ -56,7 +57,13 @@ export class MeshtasticService { |
|
|
|
} |
|
|
|
|
|
|
|
private connect() { |
|
|
|
this.socket$ = webSocket(`ws://${location.host}/mesh/ws`) |
|
|
|
this.socket$ = webSocket(`ws://${location.host}/mesh/ws`).pipe( |
|
|
|
retryWhen(errors => errors.pipe( |
|
|
|
tap(err => {console.log('WebSocket error, reconnecting...', err); this.state = WS_ERR;}), |
|
|
|
delay(3000) |
|
|
|
)) |
|
|
|
); |
|
|
|
|
|
|
|
this.socket$.subscribe( |
|
|
|
(parsed: {type: number, event: number, data: any}) => { |
|
|
|
switch (parsed.event) { |
|
|
|
@ -94,8 +101,7 @@ export class MeshtasticService { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
(err) => {} |
|
|
|
} |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|