mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 02:11:54 +00:00
removes temps, massive refactor
This commit is contained in:
committed by
Aiden McClelland
parent
0dcbb3956e
commit
950773e542
@@ -1,21 +1,27 @@
|
||||
import { Observable } from 'rxjs'
|
||||
import { webSocket, WebSocketSubject, WebSocketSubjectConfig } from 'rxjs/webSocket'
|
||||
import { UpdateReal } from '../sequence-store'
|
||||
import { Update } from '../types'
|
||||
import { Source } from './source'
|
||||
|
||||
export class WebsocketSource<T> implements Source<T> {
|
||||
private websocket$: WebSocketSubject<UpdateReal<T>>
|
||||
private websocket$: WebSocketSubject<Update<T>>
|
||||
|
||||
constructor (
|
||||
readonly url: string,
|
||||
) {
|
||||
const fullConfig: WebSocketSubjectConfig<UpdateReal<T>> = {
|
||||
const fullConfig: WebSocketSubjectConfig<Update<T>> = {
|
||||
url,
|
||||
openObserver: {
|
||||
next: () => console.log('WebSocket connection open'),
|
||||
next: () => {
|
||||
console.log('WebSocket connection open')
|
||||
this.websocket$.next('open message' as any)
|
||||
},
|
||||
},
|
||||
closeObserver: {
|
||||
next: () => console.log('WebSocket connection closed'),
|
||||
next: () => {
|
||||
console.log('WebSocket connection closed')
|
||||
// @TODO re-open websocket on retry loop
|
||||
},
|
||||
},
|
||||
closingObserver: {
|
||||
next: () => console.log('Websocket subscription cancelled, websocket closing'),
|
||||
@@ -24,5 +30,5 @@ export class WebsocketSource<T> implements Source<T> {
|
||||
this.websocket$ = webSocket(fullConfig)
|
||||
}
|
||||
|
||||
watch$ (): Observable<UpdateReal<T>> { return this.websocket$.asObservable() }
|
||||
watch$ (): Observable<Update<T>> { return this.websocket$.asObservable() }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user