@churchapps/apphelper 0.4.31 → 0.4.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,22 +12,40 @@ export declare class NotificationService {
12
12
  private loadTimeout;
13
13
  private constructor();
14
14
  static getInstance(): NotificationService;
15
+ /**
16
+ * Initialize the notification service with user context
17
+ */
15
18
  /**
16
19
  * Initialize the notification service with user context
17
20
  */
18
21
  initialize(context: UserContextInterface): Promise<void>;
22
+ /**
23
+ * Register websocket handlers for real-time notification updates
24
+ */
25
+ /**
26
+ * Register websocket handlers for real-time notification updates
27
+ */
19
28
  /**
20
29
  * Register websocket handlers for real-time notification updates
21
30
  */
22
31
  private registerWebSocketHandlers;
32
+ /**
33
+ * Load notification counts from the API with debouncing
34
+ */
23
35
  /**
24
36
  * Load notification counts from the API with debouncing
25
37
  */
26
38
  private debouncedLoadNotificationCounts;
39
+ /**
40
+ * Load notification counts from the API
41
+ */
27
42
  /**
28
43
  * Load notification counts from the API
29
44
  */
30
45
  loadNotificationCounts(): Promise<void>;
46
+ /**
47
+ * Update counts and notify all listeners
48
+ */
31
49
  /**
32
50
  * Update counts and notify all listeners
33
51
  */
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationService.d.ts","sourceRoot":"","sources":["../../src/helpers/NotificationService.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEtE,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAsB;IAC7C,OAAO,CAAC,MAAM,CAA4D;IAC1E,OAAO,CAAC,SAAS,CAAmD;IACpE,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,WAAW,CAAoB;IAEvC,OAAO;IAEP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,yBAAyB;IAsDjC;;OAEG;IACH;;OAEG;IACH,OAAO,CAAC,+BAA+B;IAcvC;;OAEG;IACH;;OAEG;IACG,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;IA8B7C;;OAEG;IACH;;OAEG;IACH,OAAO,CAAC,YAAY;IA6BpB;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,GAAG,MAAM,IAAI;IAYrE;;OAEG;IACH,SAAS,IAAI,kBAAkB;IAI/B;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B;;OAEG;IACH,OAAO,IAAI,IAAI;IAsBf;;OAEG;IACH,OAAO,IAAI,OAAO;CAGnB"}
@@ -14,35 +14,62 @@ export class NotificationService {
14
14
  }
15
15
  return NotificationService.instance;
16
16
  }
17
+ /**
18
+ * Initialize the notification service with user context
19
+ */
17
20
  /**
18
21
  * Initialize the notification service with user context
19
22
  */
20
23
  async initialize(context) {
21
- if (this.isInitialized)
24
+ if (this.isInitialized) {
25
+ console.log('🔔 NotificationService: Already initialized, skipping');
22
26
  return;
27
+ }
28
+ console.log('🔔 NotificationService: Starting initialization with context:', {
29
+ hasUser: !!context?.user,
30
+ hasPerson: !!context?.person,
31
+ hasUserChurch: !!context?.userChurch,
32
+ personId: context?.person?.id,
33
+ churchId: context?.userChurch?.church?.id
34
+ });
23
35
  try {
24
36
  // Store current person ID for conversation counting
25
37
  this.currentPersonId = context?.person?.id || null;
38
+ console.log('👤 NotificationService: Set current person ID:', this.currentPersonId);
26
39
  // Initialize WebSocket connection
40
+ console.log('🔌 NotificationService: Initializing SocketHelper...');
27
41
  await SocketHelper.init();
28
42
  // Set person/church context for websocket
29
43
  if (context?.person?.id && context?.userChurch?.church?.id) {
44
+ console.log('🔗 NotificationService: Setting person/church context in SocketHelper');
30
45
  SocketHelper.setPersonChurch({
31
46
  personId: context.person.id,
32
47
  churchId: context.userChurch.church.id
33
48
  });
34
49
  }
50
+ else {
51
+ console.warn('⚠️ NotificationService: Missing person/church IDs, cannot set socket context');
52
+ }
35
53
  // Register handlers for notification updates
54
+ console.log('📋 NotificationService: Registering WebSocket handlers');
36
55
  this.registerWebSocketHandlers();
37
56
  // Load initial notification counts
57
+ console.log('📊 NotificationService: Loading initial notification counts');
38
58
  await this.loadNotificationCounts();
39
59
  this.isInitialized = true;
60
+ console.log('✅ NotificationService: Initialization complete');
40
61
  }
41
62
  catch (error) {
42
63
  console.error("❌ Failed to initialize NotificationService:", error);
43
64
  throw error;
44
65
  }
45
66
  }
67
+ /**
68
+ * Register websocket handlers for real-time notification updates
69
+ */
70
+ /**
71
+ * Register websocket handlers for real-time notification updates
72
+ */
46
73
  /**
47
74
  * Register websocket handlers for real-time notification updates
48
75
  */
@@ -50,12 +77,28 @@ export class NotificationService {
50
77
  // Handler for new private messages
51
78
  SocketHelper.addHandler("privateMessage", "NotificationService-PM", (data) => {
52
79
  console.log('🔔 NotificationService: New private message received, updating counts');
53
- this.debouncedLoadNotificationCounts();
80
+ console.log('📨 Private message data:', data);
81
+ console.log('🔄 NotificationService: About to call debouncedLoadNotificationCounts...');
82
+ try {
83
+ this.debouncedLoadNotificationCounts();
84
+ console.log('✅ NotificationService: debouncedLoadNotificationCounts called successfully');
85
+ }
86
+ catch (error) {
87
+ console.error('❌ NotificationService: Error calling debouncedLoadNotificationCounts:', error);
88
+ }
54
89
  });
55
90
  // Handler for general notifications
56
91
  SocketHelper.addHandler("notification", "NotificationService-Notification", (data) => {
57
92
  console.log('🔔 NotificationService: New notification received, updating counts');
58
- this.debouncedLoadNotificationCounts();
93
+ console.log('📨 Notification data:', data);
94
+ console.log('🔄 NotificationService: About to call debouncedLoadNotificationCounts...');
95
+ try {
96
+ this.debouncedLoadNotificationCounts();
97
+ console.log('✅ NotificationService: debouncedLoadNotificationCounts called successfully');
98
+ }
99
+ catch (error) {
100
+ console.error('❌ NotificationService: Error calling debouncedLoadNotificationCounts:', error);
101
+ }
59
102
  });
60
103
  // Handler for message updates that could affect notification counts
61
104
  SocketHelper.addHandler("message", "NotificationService-MessageUpdate", (data) => {
@@ -63,7 +106,19 @@ export class NotificationService {
63
106
  if (data?.message?.personId === this.currentPersonId ||
64
107
  data?.notifyPersonId === this.currentPersonId) {
65
108
  console.log('🔔 NotificationService: Message update affecting current user, updating counts');
66
- this.debouncedLoadNotificationCounts();
109
+ console.log('📨 Message update data:', data);
110
+ console.log('🔄 NotificationService: About to call debouncedLoadNotificationCounts...');
111
+ try {
112
+ this.debouncedLoadNotificationCounts();
113
+ console.log('✅ NotificationService: debouncedLoadNotificationCounts called successfully');
114
+ }
115
+ catch (error) {
116
+ console.error('❌ NotificationService: Error calling debouncedLoadNotificationCounts:', error);
117
+ }
118
+ }
119
+ else {
120
+ console.log('🔕 NotificationService: Message update not for current user, ignoring');
121
+ console.log('📨 Message personId:', data?.message?.personId, 'Current personId:', this.currentPersonId);
67
122
  }
68
123
  });
69
124
  // Handler for reconnect events
@@ -72,54 +127,84 @@ export class NotificationService {
72
127
  this.loadNotificationCounts(); // Don't debounce reconnect - need immediate update
73
128
  });
74
129
  }
130
+ /**
131
+ * Load notification counts from the API with debouncing
132
+ */
75
133
  /**
76
134
  * Load notification counts from the API with debouncing
77
135
  */
78
136
  debouncedLoadNotificationCounts() {
137
+ console.log('⏰ NotificationService: Debounced load triggered');
79
138
  if (this.loadTimeout) {
139
+ console.log('⏰ NotificationService: Clearing existing timeout');
80
140
  clearTimeout(this.loadTimeout);
81
141
  }
82
142
  this.loadTimeout = setTimeout(() => {
143
+ console.log('⏰ NotificationService: Timeout expired, loading counts...');
83
144
  this.loadNotificationCounts();
84
145
  }, 300); // 300ms debounce
85
146
  }
147
+ /**
148
+ * Load notification counts from the API
149
+ */
86
150
  /**
87
151
  * Load notification counts from the API
88
152
  */
89
153
  async loadNotificationCounts() {
154
+ console.log('📊 NotificationService: Loading notification counts from API...');
90
155
  try {
91
156
  // Use the unreadCount endpoint which returns both notification and PM counts
157
+ console.log('🌐 NotificationService: Making API call to /notifications/unreadCount');
92
158
  const counts = await ApiHelper.get("/notifications/unreadCount", "MessagingApi");
159
+ console.log('📊 NotificationService: API response:', counts);
93
160
  const newCounts = {
94
161
  notificationCount: counts?.notificationCount || 0,
95
162
  pmCount: counts?.pmCount || 0
96
163
  };
164
+ console.log('🔄 NotificationService: Updating counts:', newCounts);
97
165
  // Update counts and notify listeners
98
166
  this.updateCounts(newCounts);
99
167
  }
100
168
  catch (error) {
101
169
  console.error("❌ Failed to load notification counts:", error);
170
+ console.error("❌ Error details:", {
171
+ message: error.message,
172
+ status: error.status,
173
+ response: error.response
174
+ });
102
175
  // Don't throw - just log the error and keep existing counts
103
176
  }
104
177
  }
178
+ /**
179
+ * Update counts and notify all listeners
180
+ */
105
181
  /**
106
182
  * Update counts and notify all listeners
107
183
  */
108
184
  updateCounts(newCounts) {
185
+ console.log('🔔 NotificationService: updateCounts called with:', newCounts);
186
+ console.log('🔔 NotificationService: Current counts:', this.counts);
187
+ console.log('🔔 NotificationService: Number of listeners:', this.listeners.length);
109
188
  const countsChanged = this.counts.notificationCount !== newCounts.notificationCount ||
110
189
  this.counts.pmCount !== newCounts.pmCount;
190
+ console.log('🔄 NotificationService: Counts changed?', countsChanged);
111
191
  if (countsChanged) {
112
192
  this.counts = { ...newCounts };
193
+ console.log('✅ NotificationService: Counts updated, notifying listeners...');
113
194
  // Notify all listeners
114
- this.listeners.forEach(listener => {
195
+ this.listeners.forEach((listener, index) => {
115
196
  try {
197
+ console.log(`📢 NotificationService: Calling listener ${index + 1}/${this.listeners.length}`);
116
198
  listener(this.counts);
117
199
  }
118
200
  catch (error) {
119
- console.error("❌ Error in notification listener:", error);
201
+ console.error(`❌ Error in notification listener ${index}:`, error);
120
202
  }
121
203
  });
122
204
  }
205
+ else {
206
+ console.log('⚪ NotificationService: Counts unchanged, not notifying listeners');
207
+ }
123
208
  }
124
209
  /**
125
210
  * Subscribe to notification count changes
@@ -1 +1 @@
1
- {"version":3,"file":"N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 -1 +1 @@
1
- {"version":3,"file":"SocketHelper.d.ts","sourceRoot":"","sources":["../../src/helpers/SocketHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,4BAA4B,EAAE,sBAAsB,EAAmD,MAAM,qBAAqB,CAAC;AAEjK,qBAAa,YAAY;IACvB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IACzB,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,cAAc,EAAE,4BAA4B,EAAE,CAAM;IAC3D,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAkE;IACjG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAkB;IAE5C,MAAM,CAAC,eAAe,GAAI,IAAI;QAAC,QAAQ,EAAC,MAAM,CAAC;QAAC,QAAQ,EAAC,MAAM,CAAA;KAAC,UAK/D;IAED,MAAM,CAAC,qBAAqB,aAQ3B;IAED,MAAM,CAAC,IAAI,sBA+CV;IAED,MAAM,CAAC,UAAU,GAAI,QAAQ,MAAM,EAAE,IAAI,MAAM,EAAE,eAAe,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,UAOlF;IAED,MAAM,CAAC,aAAa,GAAI,IAAI,MAAM,UAEjC;IAED,MAAM,CAAC,sBAAsB,GAAI,QAAQ,MAAM,UAE9C;IAED,MAAM,CAAC,gBAAgB,aAEtB;IAED,MAAM,CAAC,aAAa,GAAI,SAAS,sBAAsB,UAqBtD;IAED,MAAM,CAAC,OAAO,aAiBb;IAED,MAAM,CAAC,UAAU,aAEhB;IAED,MAAM,CAAC,WAAW,QAAO,OAAO,CAE/B;IAED,MAAM,CAAC,kBAAkB,QAAO,MAAM,CAerC;IAGD,MAAM,CAAC,kBAAkB,mBAmBxB;CAEF"}
1
+ {"version":3,"file":"SocketHelper.d.ts","sourceRoot":"","sources":["../../src/helpers/SocketHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,4BAA4B,EAAE,sBAAsB,EAAmD,MAAM,qBAAqB,CAAC;AAEjK,qBAAa,YAAY;IACxB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;IACzB,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,cAAc,EAAE,4BAA4B,EAAE,CAAM;IAC3D,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA0E;IACzG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAkB;IAE5C,MAAM,CAAC,eAAe,GAAI,IAAI;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,UAUnE;IAED,MAAM,CAAC,qBAAqB,aAmC3B;IAED,MAAM,CAAC,IAAI,sBAuHV;IAED,MAAM,CAAC,UAAU,GAAI,QAAQ,MAAM,EAAE,IAAI,MAAM,EAAE,eAAe,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,UAOlF;IAED,MAAM,CAAC,aAAa,GAAI,IAAI,MAAM,UAEjC;IAED,MAAM,CAAC,sBAAsB,GAAI,QAAQ,MAAM,UAE9C;IAED,MAAM,CAAC,gBAAgB,aAEtB;IAED,MAAM,CAAC,aAAa,GAAI,SAAS,sBAAsB,UA2BtD;IAED,MAAM,CAAC,OAAO,aAiBb;IAED,MAAM,CAAC,UAAU,aAEhB;IAED,MAAM,CAAC,WAAW,QAAO,OAAO,CAE/B;IAED,MAAM,CAAC,kBAAkB,QAAO,MAAM,CAerC;IAGD,MAAM,CAAC,kBAAkB,mBAmBxB;CAED"}
@@ -7,23 +7,56 @@ SocketHelper.actionHandlers = [];
7
7
  SocketHelper.personIdChurchId = { personId: "", churchId: "" };
8
8
  SocketHelper.isCleanedUp = false;
9
9
  SocketHelper.setPersonChurch = (pc) => {
10
+ console.log('👤 SocketHelper: Setting person/church context:', pc);
10
11
  if (pc?.personId && pc.personId && pc.churchId !== _a.personIdChurchId.churchId && pc.personId !== _a.personIdChurchId.personId) {
11
12
  _a.personIdChurchId = pc;
13
+ console.log('🔗 SocketHelper: Person/church context updated, creating alert connection');
12
14
  _a.createAlertConnection();
13
15
  }
16
+ else {
17
+ console.log('⚠️ SocketHelper: Person/church context unchanged or invalid');
18
+ }
14
19
  };
15
20
  SocketHelper.createAlertConnection = () => {
21
+ console.log('🔗 SocketHelper: Attempting to create alert connection...');
22
+ console.log('🆔 Socket ID:', _a.socketId);
23
+ console.log('👤 Person ID:', _a.personIdChurchId.personId);
24
+ console.log('⛪ Church ID:', _a.personIdChurchId.churchId);
16
25
  if (_a.personIdChurchId.personId && _a.socketId) {
17
- const connection = { conversationId: "alerts", churchId: _a.personIdChurchId.churchId, displayName: "Test", socketId: _a.socketId, personId: _a.personIdChurchId.personId };
18
- ApiHelper.postAnonymous("/connections", [connection], "MessagingApi").catch((error) => {
26
+ const connection = {
27
+ conversationId: "alerts",
28
+ churchId: _a.personIdChurchId.churchId,
29
+ displayName: "Test",
30
+ socketId: _a.socketId,
31
+ personId: _a.personIdChurchId.personId
32
+ };
33
+ console.log('🔗 SocketHelper: Creating alert connection with data:', connection);
34
+ ApiHelper.postAnonymous("/connections", [connection], "MessagingApi").then((response) => {
35
+ console.log('✅ SocketHelper: Alert connection created successfully:', response);
36
+ }).catch((error) => {
19
37
  console.error("❌ Failed to create alert connection:", error);
38
+ console.error("❌ Error details:", {
39
+ status: error.status,
40
+ message: error.message,
41
+ response: error.response
42
+ });
43
+ });
44
+ }
45
+ else {
46
+ console.warn('⚠️ SocketHelper: Cannot create alert connection - missing data:', {
47
+ hasPersonId: !!_a.personIdChurchId.personId,
48
+ hasSocketId: !!_a.socketId,
49
+ personId: _a.personIdChurchId.personId,
50
+ socketId: _a.socketId
20
51
  });
21
52
  }
22
53
  };
23
54
  SocketHelper.init = async () => {
55
+ console.log('🔌 SocketHelper: Starting initialization...');
24
56
  _a.cleanup();
25
57
  _a.isCleanedUp = false;
26
58
  if (_a.socket && _a.socket.readyState !== _a.socket.CLOSED) {
59
+ console.log('🔌 SocketHelper: Closing existing socket connection');
27
60
  try {
28
61
  _a.socket.close();
29
62
  }
@@ -31,35 +64,100 @@ SocketHelper.init = async () => {
31
64
  console.error("❌ Error closing existing socket:", e);
32
65
  }
33
66
  }
67
+ console.log('🔌 SocketHelper: Connecting to:', CommonEnvironmentHelper.MessagingApiSocket);
34
68
  await new Promise((resolve, reject) => {
69
+ let hasReceivedSocketId = false;
70
+ let messageCount = 0;
35
71
  try {
36
72
  _a.socket = new WebSocket(CommonEnvironmentHelper.MessagingApiSocket);
37
73
  _a.socket.onmessage = (event) => {
74
+ console.log("🔔 SocketHelper: onmessage event triggered");
38
75
  if (_a.isCleanedUp)
39
76
  return;
77
+ messageCount++;
78
+ console.log(`📨 SocketHelper: Raw message #${messageCount} received:`, event.data);
79
+ console.log(`📨 SocketHelper: Message timestamp:`, new Date().toISOString());
80
+ console.log(`📨 SocketHelper: Message size:`, event.data.length, 'characters');
40
81
  try {
41
82
  const payload = JSON.parse(event.data);
83
+ console.log(`📨 SocketHelper: Parsed message #${messageCount}:`, payload);
84
+ console.log(`📨 SocketHelper: Message action:`, payload.action);
85
+ console.log(`📨 SocketHelper: Message data type:`, typeof payload.data);
86
+ if (payload.action === 'socketId') {
87
+ hasReceivedSocketId = true;
88
+ console.log('🆔 SocketHelper: Socket ID received!', payload.data);
89
+ }
90
+ // Log all message types we receive
91
+ switch (payload.action) {
92
+ case 'socketId':
93
+ console.log('🆔 Message type: Socket ID assignment');
94
+ break;
95
+ case 'privateMessage':
96
+ console.log('💬 Message type: Private message notification');
97
+ break;
98
+ case 'notification':
99
+ console.log('🔔 Message type: General notification');
100
+ break;
101
+ case 'message':
102
+ console.log('📩 Message type: Message update');
103
+ break;
104
+ case 'reconnect':
105
+ console.log('🔄 Message type: Reconnection signal');
106
+ break;
107
+ default:
108
+ console.log('❓ Message type: Unknown action -', payload.action);
109
+ }
42
110
  _a.handleMessage(payload);
43
111
  }
44
112
  catch (error) {
45
113
  console.error("❌ Error parsing socket message:", error);
114
+ console.error("❌ Raw message was:", event.data);
46
115
  }
47
116
  };
48
117
  _a.socket.onopen = async (e) => {
49
- _a.socket.send("getId"); // Request socket ID
50
- setTimeout(() => { resolve(null); }, 500);
118
+ console.log('✅ SocketHelper: WebSocket connection opened');
119
+ console.log('🔌 SocketHelper: Connection URL:', _a.socket.url);
120
+ console.log('🔌 SocketHelper: Connection protocol:', _a.socket.protocol);
121
+ // Send the getId request
122
+ console.log('🔌 SocketHelper: Sending getId request...');
123
+ _a.socket.send("getId");
124
+ console.log('🔌 SocketHelper: getId request sent');
125
+ // Wait longer to see if we get a response
126
+ setTimeout(() => {
127
+ if (!hasReceivedSocketId) {
128
+ console.warn('⚠️ SocketHelper: No socket ID received after 3 seconds');
129
+ console.log('🔍 SocketHelper: Socket state:', _a.socket.readyState);
130
+ console.log('🔍 SocketHelper: Messages received so far:', messageCount);
131
+ }
132
+ resolve(null);
133
+ }, 3000);
51
134
  };
52
135
  _a.socket.onclose = async (e) => {
53
- console.log("🔌 WebSocket connection closed");
54
- // No retry logic - just log the closure
136
+ console.log('🔒 SocketHelper: WebSocket connection closed', {
137
+ code: e.code,
138
+ reason: e.reason,
139
+ wasClean: e.wasClean,
140
+ timestamp: new Date().toISOString(),
141
+ totalMessagesReceived: messageCount
142
+ });
143
+ // Log common close codes for debugging
144
+ if (e.code === 1005)
145
+ console.log('🔍 Close code 1005: No status received (normal for some servers)');
146
+ else if (e.code === 1006)
147
+ console.log('🔍 Close code 1006: Abnormal closure');
148
+ else if (e.code === 1000)
149
+ console.log('🔍 Close code 1000: Normal closure');
150
+ else
151
+ console.log('🔍 Close code:', e.code);
55
152
  };
56
153
  _a.socket.onerror = (error) => {
57
- console.error("❌ WebSocket connection error:", error);
154
+ console.error('SocketHelper: WebSocket connection error:', error);
155
+ console.error('❌ SocketHelper: Messages received before error:', messageCount);
58
156
  reject(error);
59
157
  };
60
158
  }
61
159
  catch (error) {
62
- console.error("❌ Error initializing socket:", error);
160
+ console.error('SocketHelper: Error initializing socket:', error);
63
161
  reject(error);
64
162
  }
65
163
  });
@@ -86,14 +184,18 @@ SocketHelper.handleMessage = (payload) => {
86
184
  if (_a.isCleanedUp)
87
185
  return;
88
186
  try {
187
+ console.log('🔄 SocketHelper: Processing message with action:', payload.action);
89
188
  if (payload.action === "socketId") {
189
+ console.log('🆔 SocketHelper: Received socket ID:', payload.data);
90
190
  _a.socketId = payload.data;
91
191
  _a.createAlertConnection();
92
192
  }
93
193
  else {
94
194
  const matchingHandlers = ArrayHelper.getAll(_a.actionHandlers, "action", payload.action);
195
+ console.log(`📬 SocketHelper: Found ${matchingHandlers.length} handlers for action: ${payload.action}`);
95
196
  matchingHandlers.forEach((handler) => {
96
197
  try {
198
+ console.log(`🏃 SocketHelper: Executing handler ${handler.id} for action: ${payload.action}`);
97
199
  handler.handleMessage(payload.data);
98
200
  }
99
201
  catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"SocketHelper.js","sourceRoot":"","sources":["../../src/helpers/SocketHelper.ts"],"names":[],"mappings":";AAAA,OAAO,EAA6E,SAAS,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAEjK,MAAM,OAAO,YAAY;;;AAGhB,2BAAc,GAAmC,EAAE,AAArC,CAAsC;AAC5C,6BAAgB,GAAuC,EAAC,QAAQ,EAAC,EAAE,EAAE,QAAQ,EAAC,EAAE,EAAC,AAAjE,CAAkE;AAClF,wBAAW,GAAY,KAAK,AAAjB,CAAkB;AAErC,4BAAe,GAAG,CAAC,EAAsC,EAAE,EAAE;IAClE,IAAI,EAAE,EAAE,QAAQ,IAAI,EAAE,CAAC,QAAQ,IAAI,EAAE,CAAC,QAAQ,KAAG,EAAI,CAAC,gBAAgB,CAAC,QAAQ,IAAI,EAAE,CAAC,QAAQ,KAAG,EAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAChI,EAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B,EAAI,CAAC,qBAAqB,EAAE,CAAC;IAC/B,CAAC;AACH,CAAC,AALqB,CAKrB;AAEM,kCAAq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B,CAAC,kBAAkB,EAAE,GAAG,EAAE;YAClD,IAAI,QAAQ,CAAC,eAAe,KAAK,QAAQ,EAAE,CAAC;gBAC3C,4CAA4C;gBAC5C,0BAA0B;YAC3B,CAAC;QACF,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IAChB,CAAC;AACF,CAAC,AAnBwB,CAmBxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churchapps/apphelper",
3
- "version": "0.4.31",
3
+ "version": "0.4.32",
4
4
  "description": "Library of helper functions for React and NextJS ChurchApps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,34 +23,56 @@ export class NotificationService {
23
23
  return NotificationService.instance;
24
24
  }
25
25
 
26
+ /**
27
+ * Initialize the notification service with user context
28
+ */
26
29
  /**
27
30
  * Initialize the notification service with user context
28
31
  */
29
32
  async initialize(context: UserContextInterface): Promise<void> {
30
- if (this.isInitialized) return;
33
+ if (this.isInitialized) {
34
+ console.log('🔔 NotificationService: Already initialized, skipping');
35
+ return;
36
+ }
37
+
38
+ console.log('🔔 NotificationService: Starting initialization with context:', {
39
+ hasUser: !!context?.user,
40
+ hasPerson: !!context?.person,
41
+ hasUserChurch: !!context?.userChurch,
42
+ personId: context?.person?.id,
43
+ churchId: context?.userChurch?.church?.id
44
+ });
31
45
 
32
46
  try {
33
47
  // Store current person ID for conversation counting
34
48
  this.currentPersonId = context?.person?.id || null;
49
+ console.log('👤 NotificationService: Set current person ID:', this.currentPersonId);
35
50
 
36
51
  // Initialize WebSocket connection
52
+ console.log('🔌 NotificationService: Initializing SocketHelper...');
37
53
  await SocketHelper.init();
38
54
 
39
55
  // Set person/church context for websocket
40
56
  if (context?.person?.id && context?.userChurch?.church?.id) {
57
+ console.log('🔗 NotificationService: Setting person/church context in SocketHelper');
41
58
  SocketHelper.setPersonChurch({
42
59
  personId: context.person.id,
43
60
  churchId: context.userChurch.church.id
44
61
  });
62
+ } else {
63
+ console.warn('⚠️ NotificationService: Missing person/church IDs, cannot set socket context');
45
64
  }
46
65
 
47
66
  // Register handlers for notification updates
67
+ console.log('📋 NotificationService: Registering WebSocket handlers');
48
68
  this.registerWebSocketHandlers();
49
69
 
50
70
  // Load initial notification counts
71
+ console.log('📊 NotificationService: Loading initial notification counts');
51
72
  await this.loadNotificationCounts();
52
73
 
53
74
  this.isInitialized = true;
75
+ console.log('✅ NotificationService: Initialization complete');
54
76
 
55
77
  } catch (error) {
56
78
  console.error("❌ Failed to initialize NotificationService:", error);
@@ -58,6 +80,12 @@ export class NotificationService {
58
80
  }
59
81
  }
60
82
 
83
+ /**
84
+ * Register websocket handlers for real-time notification updates
85
+ */
86
+ /**
87
+ * Register websocket handlers for real-time notification updates
88
+ */
61
89
  /**
62
90
  * Register websocket handlers for real-time notification updates
63
91
  */
@@ -65,13 +93,27 @@ export class NotificationService {
65
93
  // Handler for new private messages
66
94
  SocketHelper.addHandler("privateMessage", "NotificationService-PM", (data: any) => {
67
95
  console.log('🔔 NotificationService: New private message received, updating counts');
68
- this.debouncedLoadNotificationCounts();
96
+ console.log('📨 Private message data:', data);
97
+ console.log('🔄 NotificationService: About to call debouncedLoadNotificationCounts...');
98
+ try {
99
+ this.debouncedLoadNotificationCounts();
100
+ console.log('✅ NotificationService: debouncedLoadNotificationCounts called successfully');
101
+ } catch (error) {
102
+ console.error('❌ NotificationService: Error calling debouncedLoadNotificationCounts:', error);
103
+ }
69
104
  });
70
105
 
71
106
  // Handler for general notifications
72
107
  SocketHelper.addHandler("notification", "NotificationService-Notification", (data: any) => {
73
108
  console.log('🔔 NotificationService: New notification received, updating counts');
74
- this.debouncedLoadNotificationCounts();
109
+ console.log('📨 Notification data:', data);
110
+ console.log('🔄 NotificationService: About to call debouncedLoadNotificationCounts...');
111
+ try {
112
+ this.debouncedLoadNotificationCounts();
113
+ console.log('✅ NotificationService: debouncedLoadNotificationCounts called successfully');
114
+ } catch (error) {
115
+ console.error('❌ NotificationService: Error calling debouncedLoadNotificationCounts:', error);
116
+ }
75
117
  });
76
118
 
77
119
  // Handler for message updates that could affect notification counts
@@ -80,7 +122,17 @@ export class NotificationService {
80
122
  if (data?.message?.personId === this.currentPersonId ||
81
123
  data?.notifyPersonId === this.currentPersonId) {
82
124
  console.log('🔔 NotificationService: Message update affecting current user, updating counts');
83
- this.debouncedLoadNotificationCounts();
125
+ console.log('📨 Message update data:', data);
126
+ console.log('🔄 NotificationService: About to call debouncedLoadNotificationCounts...');
127
+ try {
128
+ this.debouncedLoadNotificationCounts();
129
+ console.log('✅ NotificationService: debouncedLoadNotificationCounts called successfully');
130
+ } catch (error) {
131
+ console.error('❌ NotificationService: Error calling debouncedLoadNotificationCounts:', error);
132
+ }
133
+ } else {
134
+ console.log('🔕 NotificationService: Message update not for current user, ignoring');
135
+ console.log('📨 Message personId:', data?.message?.personId, 'Current personId:', this.currentPersonId);
84
136
  }
85
137
  });
86
138
 
@@ -91,60 +143,94 @@ export class NotificationService {
91
143
  });
92
144
  }
93
145
 
146
+ /**
147
+ * Load notification counts from the API with debouncing
148
+ */
94
149
  /**
95
150
  * Load notification counts from the API with debouncing
96
151
  */
97
152
  private debouncedLoadNotificationCounts(): void {
153
+ console.log('⏰ NotificationService: Debounced load triggered');
154
+
98
155
  if (this.loadTimeout) {
156
+ console.log('⏰ NotificationService: Clearing existing timeout');
99
157
  clearTimeout(this.loadTimeout);
100
158
  }
101
159
 
102
160
  this.loadTimeout = setTimeout(() => {
161
+ console.log('⏰ NotificationService: Timeout expired, loading counts...');
103
162
  this.loadNotificationCounts();
104
163
  }, 300); // 300ms debounce
105
164
  }
106
165
 
166
+ /**
167
+ * Load notification counts from the API
168
+ */
107
169
  /**
108
170
  * Load notification counts from the API
109
171
  */
110
172
  async loadNotificationCounts(): Promise<void> {
173
+ console.log('📊 NotificationService: Loading notification counts from API...');
174
+
111
175
  try {
112
176
  // Use the unreadCount endpoint which returns both notification and PM counts
177
+ console.log('🌐 NotificationService: Making API call to /notifications/unreadCount');
113
178
  const counts = await ApiHelper.get("/notifications/unreadCount", "MessagingApi");
179
+ console.log('📊 NotificationService: API response:', counts);
114
180
 
115
181
  const newCounts = {
116
182
  notificationCount: counts?.notificationCount || 0,
117
183
  pmCount: counts?.pmCount || 0
118
184
  };
119
185
 
186
+ console.log('🔄 NotificationService: Updating counts:', newCounts);
187
+
120
188
  // Update counts and notify listeners
121
189
  this.updateCounts(newCounts);
122
190
 
123
191
  } catch (error) {
124
192
  console.error("❌ Failed to load notification counts:", error);
193
+ console.error("❌ Error details:", {
194
+ message: error.message,
195
+ status: error.status,
196
+ response: error.response
197
+ });
125
198
  // Don't throw - just log the error and keep existing counts
126
199
  }
127
200
  }
128
201
 
202
+ /**
203
+ * Update counts and notify all listeners
204
+ */
129
205
  /**
130
206
  * Update counts and notify all listeners
131
207
  */
132
208
  private updateCounts(newCounts: NotificationCounts): void {
209
+ console.log('🔔 NotificationService: updateCounts called with:', newCounts);
210
+ console.log('🔔 NotificationService: Current counts:', this.counts);
211
+ console.log('🔔 NotificationService: Number of listeners:', this.listeners.length);
212
+
133
213
  const countsChanged =
134
214
  this.counts.notificationCount !== newCounts.notificationCount ||
135
215
  this.counts.pmCount !== newCounts.pmCount;
136
216
 
217
+ console.log('🔄 NotificationService: Counts changed?', countsChanged);
218
+
137
219
  if (countsChanged) {
138
220
  this.counts = { ...newCounts };
221
+ console.log('✅ NotificationService: Counts updated, notifying listeners...');
139
222
 
140
223
  // Notify all listeners
141
- this.listeners.forEach(listener => {
224
+ this.listeners.forEach((listener, index) => {
142
225
  try {
226
+ console.log(`📢 NotificationService: Calling listener ${index + 1}/${this.listeners.length}`);
143
227
  listener(this.counts);
144
228
  } catch (error) {
145
- console.error("❌ Error in notification listener:", error);
229
+ console.error(`❌ Error in notification listener ${index}:`, error);
146
230
  }
147
231
  });
232
+ } else {
233
+ console.log('⚪ NotificationService: Counts unchanged, not notifying listeners');
148
234
  }
149
235
  }
150
236
 
@@ -1,186 +1,296 @@
1
1
  import { ConnectionInterface, SocketActionHandlerInterface, SocketPayloadInterface, ApiHelper, ArrayHelper, CommonEnvironmentHelper } from "@churchapps/helpers";
2
2
 
3
3
  export class SocketHelper {
4
- static socket: WebSocket;
5
- static socketId: string;
6
- static actionHandlers: SocketActionHandlerInterface[] = [];
7
- private static personIdChurchId: {personId:string, churchId:string} = {personId:"", churchId:""};
8
- private static isCleanedUp: boolean = false;
9
-
10
- static setPersonChurch = (pc: {personId:string, churchId:string}) => {
11
- if (pc?.personId && pc.personId && pc.churchId!==this.personIdChurchId.churchId && pc.personId!==this.personIdChurchId.personId) {
12
- this.personIdChurchId = pc;
13
- this.createAlertConnection();
14
- }
15
- }
16
-
17
- static createAlertConnection = () => {
18
- if (SocketHelper.personIdChurchId.personId && SocketHelper.socketId) {
19
- const connection: ConnectionInterface = { conversationId: "alerts", churchId: SocketHelper.personIdChurchId.churchId, displayName: "Test", socketId: SocketHelper.socketId, personId:SocketHelper.personIdChurchId.personId }
20
-
21
- ApiHelper.postAnonymous("/connections", [connection], "MessagingApi").catch((error: any) => {
22
- console.error("❌ Failed to create alert connection:", error);
23
- });
24
- }
25
- }
26
-
27
- static init = async () => {
28
- SocketHelper.cleanup();
29
- SocketHelper.isCleanedUp = false;
30
-
31
- if (SocketHelper.socket && SocketHelper.socket.readyState !== SocketHelper.socket.CLOSED) {
32
- try {
33
- SocketHelper.socket.close();
34
- } catch (e) {
35
- console.error("❌ Error closing existing socket:", e);
36
- }
37
- }
38
-
39
- await new Promise((resolve, reject) => {
40
- try {
41
- SocketHelper.socket = new WebSocket(CommonEnvironmentHelper.MessagingApiSocket);
42
-
43
- SocketHelper.socket.onmessage = (event) => {
44
- if (SocketHelper.isCleanedUp) return;
45
-
46
- try {
47
- const payload = JSON.parse(event.data);
48
- SocketHelper.handleMessage(payload);
49
- } catch (error) {
50
- console.error("❌ Error parsing socket message:", error);
51
- }
52
- };
53
-
54
- SocketHelper.socket.onopen = async (e) => {
55
- SocketHelper.socket.send("getId"); // Request socket ID
56
- setTimeout(() => { resolve(null); }, 500);
57
- };
58
-
59
- SocketHelper.socket.onclose = async (e) => {
60
- console.log("🔌 WebSocket connection closed");
61
- // No retry logic - just log the closure
62
- };
63
-
64
- SocketHelper.socket.onerror = (error) => {
65
- console.error("❌ WebSocket connection error:", error);
66
- reject(error);
67
- };
68
-
69
- } catch (error) {
70
- console.error("❌ Error initializing socket:", error);
71
- reject(error);
72
- }
73
- });
74
- }
75
-
76
- static addHandler = (action: string, id: string, handleMessage: (data: any) => void) => {
77
- const existing = ArrayHelper.getOne(SocketHelper.actionHandlers, "id", id);
78
- if (existing !== null) {
79
- existing.handleMessage = handleMessage;
80
- } else {
81
- SocketHelper.actionHandlers.push({ action, id, handleMessage });
82
- }
83
- }
84
-
85
- static removeHandler = (id: string) => {
86
- SocketHelper.actionHandlers = SocketHelper.actionHandlers.filter(handler => handler.id !== id);
87
- }
88
-
89
- static removeHandlersByAction = (action: string) => {
90
- SocketHelper.actionHandlers = SocketHelper.actionHandlers.filter(handler => handler.action !== action);
91
- }
92
-
93
- static clearAllHandlers = () => {
94
- SocketHelper.actionHandlers = [];
95
- }
96
-
97
- static handleMessage = (payload: SocketPayloadInterface) => {
98
- if (SocketHelper.isCleanedUp) return;
99
-
100
- try {
101
- if (payload.action==="socketId") {
102
- SocketHelper.socketId = payload.data;
103
- SocketHelper.createAlertConnection();
104
- }
105
- else {
106
- const matchingHandlers = ArrayHelper.getAll(SocketHelper.actionHandlers, "action", payload.action);
107
- matchingHandlers.forEach((handler) => {
108
- try {
109
- handler.handleMessage(payload.data);
110
- } catch (error) {
111
- console.error(`❌ Error in handler ${handler.id}:`, error);
112
- }
113
- });
114
- }
115
- } catch (error) {
116
- console.error("❌ Error handling socket message:", error);
117
- }
118
- }
119
-
120
- static cleanup = () => {
121
- SocketHelper.isCleanedUp = true;
122
-
123
- // Close socket connection
124
- if (SocketHelper.socket && SocketHelper.socket.readyState !== SocketHelper.socket.CLOSED) {
125
- try {
126
- SocketHelper.socket.close();
127
- } catch (error) {
128
- console.error("Error closing socket:", error);
129
- }
130
- }
131
-
132
- // Clear references
133
- SocketHelper.socket = null;
134
- SocketHelper.socketId = null;
135
- SocketHelper.actionHandlers = [];
136
- SocketHelper.personIdChurchId = {personId:"", churchId:""};
137
- }
138
-
139
- static disconnect = () => {
140
- SocketHelper.cleanup();
141
- }
142
-
143
- static isConnected = (): boolean => {
144
- return SocketHelper.socket && SocketHelper.socket.readyState === SocketHelper.socket.OPEN;
145
- }
146
-
147
- static getConnectionState = (): string => {
148
- if (!SocketHelper.socket) return "UNINITIALIZED";
149
-
150
- switch (SocketHelper.socket.readyState) {
151
- case SocketHelper.socket.CONNECTING:
152
- return "CONNECTING";
153
- case SocketHelper.socket.OPEN:
154
- return "OPEN";
155
- case SocketHelper.socket.CLOSING:
156
- return "CLOSING";
157
- case SocketHelper.socket.CLOSED:
158
- return "CLOSED";
159
- default:
160
- return "UNKNOWN";
161
- }
162
- }
163
-
164
- // Global cleanup on window unload
165
- static setupGlobalCleanup = () => {
166
- if (typeof window !== "undefined") {
167
- const cleanup = () => {
168
- SocketHelper.cleanup();
169
- };
170
-
171
- window.addEventListener("beforeunload", cleanup);
172
- window.addEventListener("unload", cleanup);
173
-
174
- // Also cleanup on page visibility change (when tab is closed)
175
- document.addEventListener("visibilitychange", () => {
176
- if (document.visibilityState === "hidden") {
177
- // Optional: cleanup when tab becomes hidden
178
- // SocketHelper.cleanup();
179
- }
180
- });
181
-
182
- return cleanup;
183
- }
184
- }
4
+ static socket: WebSocket;
5
+ static socketId: string;
6
+ static actionHandlers: SocketActionHandlerInterface[] = [];
7
+ private static personIdChurchId: { personId: string, churchId: string } = { personId: "", churchId: "" };
8
+ private static isCleanedUp: boolean = false;
9
+
10
+ static setPersonChurch = (pc: { personId: string, churchId: string }) => {
11
+ console.log('👤 SocketHelper: Setting person/church context:', pc);
12
+
13
+ if (pc?.personId && pc.personId && pc.churchId !== this.personIdChurchId.churchId && pc.personId !== this.personIdChurchId.personId) {
14
+ this.personIdChurchId = pc;
15
+ console.log('🔗 SocketHelper: Person/church context updated, creating alert connection');
16
+ this.createAlertConnection();
17
+ } else {
18
+ console.log('⚠️ SocketHelper: Person/church context unchanged or invalid');
19
+ }
20
+ }
21
+
22
+ static createAlertConnection = () => {
23
+ console.log('🔗 SocketHelper: Attempting to create alert connection...');
24
+ console.log('🆔 Socket ID:', SocketHelper.socketId);
25
+ console.log('👤 Person ID:', SocketHelper.personIdChurchId.personId);
26
+ console.log('⛪ Church ID:', SocketHelper.personIdChurchId.churchId);
27
+
28
+ if (SocketHelper.personIdChurchId.personId && SocketHelper.socketId) {
29
+ const connection: ConnectionInterface = {
30
+ conversationId: "alerts",
31
+ churchId: SocketHelper.personIdChurchId.churchId,
32
+ displayName: "Test",
33
+ socketId: SocketHelper.socketId,
34
+ personId: SocketHelper.personIdChurchId.personId
35
+ }
36
+
37
+ console.log('🔗 SocketHelper: Creating alert connection with data:', connection);
38
+
39
+ ApiHelper.postAnonymous("/connections", [connection], "MessagingApi").then((response: any) => {
40
+ console.log('✅ SocketHelper: Alert connection created successfully:', response);
41
+ }).catch((error: any) => {
42
+ console.error("❌ Failed to create alert connection:", error);
43
+ console.error("❌ Error details:", {
44
+ status: error.status,
45
+ message: error.message,
46
+ response: error.response
47
+ });
48
+ });
49
+ } else {
50
+ console.warn('⚠️ SocketHelper: Cannot create alert connection - missing data:', {
51
+ hasPersonId: !!SocketHelper.personIdChurchId.personId,
52
+ hasSocketId: !!SocketHelper.socketId,
53
+ personId: SocketHelper.personIdChurchId.personId,
54
+ socketId: SocketHelper.socketId
55
+ });
56
+ }
57
+ }
58
+
59
+ static init = async () => {
60
+ console.log('🔌 SocketHelper: Starting initialization...');
61
+ SocketHelper.cleanup();
62
+ SocketHelper.isCleanedUp = false;
63
+
64
+ if (SocketHelper.socket && SocketHelper.socket.readyState !== SocketHelper.socket.CLOSED) {
65
+ console.log('🔌 SocketHelper: Closing existing socket connection');
66
+ try {
67
+ SocketHelper.socket.close();
68
+ } catch (e) {
69
+ console.error("❌ Error closing existing socket:", e);
70
+ }
71
+ }
72
+
73
+ console.log('🔌 SocketHelper: Connecting to:', CommonEnvironmentHelper.MessagingApiSocket);
74
+
75
+ await new Promise((resolve, reject) => {
76
+ let hasReceivedSocketId = false;
77
+ let messageCount = 0;
78
+
79
+ try {
80
+ SocketHelper.socket = new WebSocket(CommonEnvironmentHelper.MessagingApiSocket);
81
+
82
+ SocketHelper.socket.onmessage = (event) => {
83
+ console.log("🔔 SocketHelper: onmessage event triggered");
84
+ if (SocketHelper.isCleanedUp) return;
85
+
86
+ messageCount++;
87
+ console.log(`📨 SocketHelper: Raw message #${messageCount} received:`, event.data);
88
+ console.log(`📨 SocketHelper: Message timestamp:`, new Date().toISOString());
89
+ console.log(`📨 SocketHelper: Message size:`, event.data.length, 'characters');
90
+
91
+ try {
92
+ const payload = JSON.parse(event.data);
93
+ console.log(`📨 SocketHelper: Parsed message #${messageCount}:`, payload);
94
+ console.log(`📨 SocketHelper: Message action:`, payload.action);
95
+ console.log(`📨 SocketHelper: Message data type:`, typeof payload.data);
96
+
97
+ if (payload.action === 'socketId') {
98
+ hasReceivedSocketId = true;
99
+ console.log('🆔 SocketHelper: Socket ID received!', payload.data);
100
+ }
101
+
102
+ // Log all message types we receive
103
+ switch (payload.action) {
104
+ case 'socketId':
105
+ console.log('🆔 Message type: Socket ID assignment');
106
+ break;
107
+ case 'privateMessage':
108
+ console.log('💬 Message type: Private message notification');
109
+ break;
110
+ case 'notification':
111
+ console.log('🔔 Message type: General notification');
112
+ break;
113
+ case 'message':
114
+ console.log('📩 Message type: Message update');
115
+ break;
116
+ case 'reconnect':
117
+ console.log('🔄 Message type: Reconnection signal');
118
+ break;
119
+ default:
120
+ console.log('❓ Message type: Unknown action -', payload.action);
121
+ }
122
+
123
+ SocketHelper.handleMessage(payload);
124
+ } catch (error) {
125
+ console.error("❌ Error parsing socket message:", error);
126
+ console.error("❌ Raw message was:", event.data);
127
+ }
128
+ };
129
+
130
+ SocketHelper.socket.onopen = async (e) => {
131
+ console.log('✅ SocketHelper: WebSocket connection opened');
132
+ console.log('🔌 SocketHelper: Connection URL:', SocketHelper.socket.url);
133
+ console.log('🔌 SocketHelper: Connection protocol:', SocketHelper.socket.protocol);
134
+
135
+ // Send the getId request
136
+ console.log('🔌 SocketHelper: Sending getId request...');
137
+ SocketHelper.socket.send("getId");
138
+ console.log('🔌 SocketHelper: getId request sent');
139
+
140
+ // Wait longer to see if we get a response
141
+ setTimeout(() => {
142
+ if (!hasReceivedSocketId) {
143
+ console.warn('⚠️ SocketHelper: No socket ID received after 3 seconds');
144
+ console.log('🔍 SocketHelper: Socket state:', SocketHelper.socket.readyState);
145
+ console.log('🔍 SocketHelper: Messages received so far:', messageCount);
146
+ }
147
+ resolve(null);
148
+ }, 3000);
149
+ };
150
+
151
+ SocketHelper.socket.onclose = async (e) => {
152
+ console.log('🔒 SocketHelper: WebSocket connection closed', {
153
+ code: e.code,
154
+ reason: e.reason,
155
+ wasClean: e.wasClean,
156
+ timestamp: new Date().toISOString(),
157
+ totalMessagesReceived: messageCount
158
+ });
159
+
160
+ // Log common close codes for debugging
161
+ if (e.code === 1005) console.log('🔍 Close code 1005: No status received (normal for some servers)');
162
+ else if (e.code === 1006) console.log('🔍 Close code 1006: Abnormal closure');
163
+ else if (e.code === 1000) console.log('🔍 Close code 1000: Normal closure');
164
+ else console.log('🔍 Close code:', e.code);
165
+ };
166
+
167
+ SocketHelper.socket.onerror = (error) => {
168
+ console.error('❌ SocketHelper: WebSocket connection error:', error);
169
+ console.error('❌ SocketHelper: Messages received before error:', messageCount);
170
+ reject(error);
171
+ };
172
+
173
+ } catch (error) {
174
+ console.error('❌ SocketHelper: Error initializing socket:', error);
175
+ reject(error);
176
+ }
177
+ });
178
+ }
179
+
180
+ static addHandler = (action: string, id: string, handleMessage: (data: any) => void) => {
181
+ const existing = ArrayHelper.getOne(SocketHelper.actionHandlers, "id", id);
182
+ if (existing !== null) {
183
+ existing.handleMessage = handleMessage;
184
+ } else {
185
+ SocketHelper.actionHandlers.push({ action, id, handleMessage });
186
+ }
187
+ }
188
+
189
+ static removeHandler = (id: string) => {
190
+ SocketHelper.actionHandlers = SocketHelper.actionHandlers.filter(handler => handler.id !== id);
191
+ }
192
+
193
+ static removeHandlersByAction = (action: string) => {
194
+ SocketHelper.actionHandlers = SocketHelper.actionHandlers.filter(handler => handler.action !== action);
195
+ }
196
+
197
+ static clearAllHandlers = () => {
198
+ SocketHelper.actionHandlers = [];
199
+ }
200
+
201
+ static handleMessage = (payload: SocketPayloadInterface) => {
202
+ if (SocketHelper.isCleanedUp) return;
203
+
204
+ try {
205
+ console.log('🔄 SocketHelper: Processing message with action:', payload.action);
206
+
207
+ if (payload.action === "socketId") {
208
+ console.log('🆔 SocketHelper: Received socket ID:', payload.data);
209
+ SocketHelper.socketId = payload.data;
210
+ SocketHelper.createAlertConnection();
211
+ }
212
+ else {
213
+ const matchingHandlers = ArrayHelper.getAll(SocketHelper.actionHandlers, "action", payload.action);
214
+ console.log(`📬 SocketHelper: Found ${matchingHandlers.length} handlers for action: ${payload.action}`);
215
+
216
+ matchingHandlers.forEach((handler) => {
217
+ try {
218
+ console.log(`🏃 SocketHelper: Executing handler ${handler.id} for action: ${payload.action}`);
219
+ handler.handleMessage(payload.data);
220
+ } catch (error) {
221
+ console.error(`❌ Error in handler ${handler.id}:`, error);
222
+ }
223
+ });
224
+ }
225
+ } catch (error) {
226
+ console.error("❌ Error handling socket message:", error);
227
+ }
228
+ }
229
+
230
+ static cleanup = () => {
231
+ SocketHelper.isCleanedUp = true;
232
+
233
+ // Close socket connection
234
+ if (SocketHelper.socket && SocketHelper.socket.readyState !== SocketHelper.socket.CLOSED) {
235
+ try {
236
+ SocketHelper.socket.close();
237
+ } catch (error) {
238
+ console.error("Error closing socket:", error);
239
+ }
240
+ }
241
+
242
+ // Clear references
243
+ SocketHelper.socket = null;
244
+ SocketHelper.socketId = null;
245
+ SocketHelper.actionHandlers = [];
246
+ SocketHelper.personIdChurchId = { personId: "", churchId: "" };
247
+ }
248
+
249
+ static disconnect = () => {
250
+ SocketHelper.cleanup();
251
+ }
252
+
253
+ static isConnected = (): boolean => {
254
+ return SocketHelper.socket && SocketHelper.socket.readyState === SocketHelper.socket.OPEN;
255
+ }
256
+
257
+ static getConnectionState = (): string => {
258
+ if (!SocketHelper.socket) return "UNINITIALIZED";
259
+
260
+ switch (SocketHelper.socket.readyState) {
261
+ case SocketHelper.socket.CONNECTING:
262
+ return "CONNECTING";
263
+ case SocketHelper.socket.OPEN:
264
+ return "OPEN";
265
+ case SocketHelper.socket.CLOSING:
266
+ return "CLOSING";
267
+ case SocketHelper.socket.CLOSED:
268
+ return "CLOSED";
269
+ default:
270
+ return "UNKNOWN";
271
+ }
272
+ }
273
+
274
+ // Global cleanup on window unload
275
+ static setupGlobalCleanup = () => {
276
+ if (typeof window !== "undefined") {
277
+ const cleanup = () => {
278
+ SocketHelper.cleanup();
279
+ };
280
+
281
+ window.addEventListener("beforeunload", cleanup);
282
+ window.addEventListener("unload", cleanup);
283
+
284
+ // Also cleanup on page visibility change (when tab is closed)
285
+ document.addEventListener("visibilitychange", () => {
286
+ if (document.visibilityState === "hidden") {
287
+ // Optional: cleanup when tab becomes hidden
288
+ // SocketHelper.cleanup();
289
+ }
290
+ });
291
+
292
+ return cleanup;
293
+ }
294
+ }
185
295
 
186
296
  }