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 | 0fc36c865ba46cab42b67e52153cd6115d8087ab (patch) | |
| tree | 7278cf3438479d52a22047df1967a2c293614cc1 /FrontEnd/src/app/services/timeline.ts | |
| parent | 8f6ec55a827c2ebbacd23cedc0b2d674be052106 (diff) | |
| download | timeline-0fc36c865ba46cab42b67e52153cd6115d8087ab.tar.gz timeline-0fc36c865ba46cab42b67e52153cd6115d8087ab.tar.bz2 timeline-0fc36c865ba46cab42b67e52153cd6115d8087ab.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);  | 
