mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 10:21:53 +00:00
move client from separate repo
This commit is contained in:
committed by
Aiden McClelland
parent
d2f542a8f3
commit
9ad59a4d1a
28
client/lib/source/ws-source.ts
Normal file
28
client/lib/source/ws-source.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Observable } from 'rxjs'
|
||||
import { webSocket, WebSocketSubject, WebSocketSubjectConfig } from 'rxjs/webSocket'
|
||||
import { UpdateReal } from '../sequence-store'
|
||||
import { Source } from './source'
|
||||
|
||||
export class WebsocketSource<T> implements Source<T> {
|
||||
private websocket$: WebSocketSubject<UpdateReal<T>>
|
||||
|
||||
constructor (
|
||||
readonly url: string,
|
||||
) {
|
||||
const fullConfig: WebSocketSubjectConfig<UpdateReal<T>> = {
|
||||
url,
|
||||
openObserver: {
|
||||
next: () => console.log('WebSocket connection open'),
|
||||
},
|
||||
closeObserver: {
|
||||
next: () => console.log('WebSocket connection closed'),
|
||||
},
|
||||
closingObserver: {
|
||||
next: () => console.log('Websocket subscription cancelled, websocket closing'),
|
||||
},
|
||||
}
|
||||
this.websocket$ = webSocket(fullConfig)
|
||||
}
|
||||
|
||||
watch$ (): Observable<UpdateReal<T>> { return this.websocket$.asObservable() }
|
||||
}
|
||||
Reference in New Issue
Block a user