diff options
author | crupest <crupest@outlook.com> | 2021-05-17 21:02:31 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-05-17 21:02:31 +0800 |
commit | c7528bfdfa920f1e2e5de2876c4bb7691419d7d6 (patch) | |
tree | 88ba1e1af79738fb00277f7033586e0c07041db9 /FrontEnd/src/app/services/timeline.ts | |
parent | 7d847632c59e247189f9039385aac1d630e87212 (diff) | |
download | timeline-c7528bfdfa920f1e2e5de2876c4bb7691419d7d6.tar.gz timeline-c7528bfdfa920f1e2e5de2876c4bb7691419d7d6.tar.bz2 timeline-c7528bfdfa920f1e2e5de2876c4bb7691419d7d6.zip |
feat: Prepare for connection status badge.
Diffstat (limited to 'FrontEnd/src/app/services/timeline.ts')
-rw-r--r-- | FrontEnd/src/app/services/timeline.ts | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/FrontEnd/src/app/services/timeline.ts b/FrontEnd/src/app/services/timeline.ts index b19dcbe9..d8c0ae00 100644 --- a/FrontEnd/src/app/services/timeline.ts +++ b/FrontEnd/src/app/services/timeline.ts @@ -22,8 +22,13 @@ export const timelineVisibilityTooltipTranslationMap: Record< export function getTimelinePostUpdate$( timelineName: string -): Observable<string> { +): Observable<{ update: boolean; state: HubConnectionState }> { return new Observable((subscriber) => { + subscriber.next({ + update: false, + state: HubConnectionState.Connecting, + }); + const token = getHttpToken(); const connection = new HubConnectionBuilder() .withUrl("/api/hub/timeline", { @@ -34,17 +39,38 @@ export function getTimelinePostUpdate$( const handler = (tn: string): void => { if (timelineName === tn) { - subscriber.next(tn); + subscriber.next({ update: true, state: connection.state }); } }; + connection.onclose(() => { + subscriber.next({ + update: false, + state: HubConnectionState.Disconnected, + }); + }); + + connection.onreconnecting(() => { + subscriber.next({ + update: false, + state: HubConnectionState.Reconnecting, + }); + }); + + connection.onreconnected(() => { + subscriber.next({ + update: false, + state: HubConnectionState.Connected, + }); + }); + connection.on("OnTimelinePostChanged", handler); - void connection - .start() - .then(() => - connection.invoke("SubscribeTimelinePostChange", timelineName) - ); + void connection.start().then(() => { + subscriber.next({ update: false, state: HubConnectionState.Connected }); + + return connection.invoke("SubscribeTimelinePostChange", timelineName); + }); return () => { connection.off("OnTimelinePostChanged", handler); |