remove connection status from lib

This commit is contained in:
Matt Hill
2021-07-05 20:36:44 -06:00
committed by Aiden McClelland
parent eb4a24e797
commit d84752007d
6 changed files with 45 additions and 66 deletions

View File

@@ -1,16 +1,14 @@
import { BehaviorSubject, Observable } from 'rxjs'
import { Observable } from 'rxjs'
import { webSocket, WebSocketSubject, WebSocketSubjectConfig } from 'rxjs/webSocket'
import { ConnectionStatus, Update } from '../types'
import { Update } from '../types'
import { Source } from './source'
export class WebsocketSource<T> implements Source<T> {
connectionStatus$ = new BehaviorSubject(ConnectionStatus.Initializing)
private websocket$: WebSocketSubject<Update<T>> | undefined
constructor (
private readonly url: string,
) {
}
) { }
watch$ (): Observable<Update<T>> {
const fullConfig: WebSocketSubjectConfig<Update<T>> = {
@@ -18,21 +16,9 @@ export class WebsocketSource<T> implements Source<T> {
openObserver: {
next: () => {
console.log('WebSocket connection open')
this.connectionStatus$.next(ConnectionStatus.Connected)
this.websocket$!.next('open message' as any)
},
},
closeObserver: {
next: () => {
this.connectionStatus$.next(ConnectionStatus.Disconnected)
console.log('WebSocket connection closed')
},
},
closingObserver: {
next: () => {
console.log('Websocket subscription cancelled, websocket closing')
},
},
}
this.websocket$ = webSocket(fullConfig)
return this.websocket$