forked from singlesly/bingx-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpong.ts
More file actions
21 lines (20 loc) · 650 Bytes
/
Copy pathpong.ts
File metadata and controls
21 lines (20 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { filter, Observable, OperatorFunction, Subject, tap } from 'rxjs';
import { WebSocketSubject } from 'rxjs/webSocket';
import { HeartbeatInterface } from 'bingx-api/bingx-socket/interfaces/heartbeat.interface';
export function pong<T>(
socket$: WebSocketSubject<T>,
listener$?: Subject<HeartbeatInterface>,
): OperatorFunction<T, T> {
return (source$: Observable<T>) =>
source$.pipe(
tap((msg) => {
if (msg === 'Ping') {
listener$?.next({
timestamp: Date.now(),
});
return socket$.next('Pong' as T);
}
}),
filter((message) => message !== 'Ping'),
);
}