44 * Created Date: 2026-04-08 17:59:41
55 * Author: 3urobeat
66 *
7- * Last Modified: 2026-04-28 21:58:59
7+ * Last Modified: 2026-04-29 17:45:11
88 * Modified By: 3urobeat
99 *
1010 * Copyright (c) 2026 3urobeat <https://github.com/3urobeat>
1818import { SubscriptionEventAction , SubscriptionEventType , type SubscriptionEvent } from "../model/api" ;
1919import { NotificationLevel , NotificationType , type NotificationData } from "../model/notification" ;
2020import { emitSubscriptionEvent } from "./events" ;
21+ import { State } from "./state" ;
2122
2223let serverSubscriptionEventStream : EventSource | undefined ;
2324
@@ -29,6 +30,8 @@ let serverSubscriptionEventStream: EventSource | undefined;
2930function handleServerSubscriptionConnected ( event : unknown ) { // eslint-disable-line @typescript-eslint/no-unused-vars
3031 console . debug ( "[DEBUG] Server Subscription: Connected!" ) ;
3132
33+ useState ( State . SERVER_SUBSCRIPTION_CONNECTED ) . value = true ;
34+
3235 emitNotificationShowEvent ( {
3336 level : NotificationLevel . DEBUG ,
3437 title : "Server Subscription" ,
@@ -93,6 +96,8 @@ function handleServerSubscriptionError(err: unknown) {
9396export function establishServerSubscriptionConnection ( ) {
9497 if ( serverSubscriptionEventStream ) throw ( "EventStream is not null, close it first" ) ;
9598
99+ useState ( State . SERVER_SUBSCRIPTION_CONNECTED ) . value = false ;
100+
96101 if ( getServerSettingsFromServer ( ) . value . document ! . serverSubscriptionEnabled ) {
97102 console . debug ( "[DEBUG] establishServerSubscriptionConnection: Attempting to connect..." ) ;
98103
@@ -114,4 +119,5 @@ export function closeServerSubscriptionConnection() {
114119 serverSubscriptionEventStream . close ( ) ;
115120 serverSubscriptionEventStream = undefined ;
116121 }
122+ useState ( State . SERVER_SUBSCRIPTION_CONNECTED ) . value = false ;
117123}
0 commit comments