@churchapps/apphelper 0.6.4 → 0.6.5
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.
|
@@ -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;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,UAOnE;IAED,MAAM,CAAC,qBAAqB,
|
|
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,UAOnE;IAED,MAAM,CAAC,qBAAqB,aAY3B;IAED,MAAM,CAAC,IAAI,sBAyCV;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,aAcb;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"}
|
|
@@ -23,23 +23,7 @@ SocketHelper.createAlertConnection = () => {
|
|
|
23
23
|
socketId: _a.socketId,
|
|
24
24
|
personId: _a.personIdChurchId.personId
|
|
25
25
|
};
|
|
26
|
-
ApiHelper.postAnonymous("/connections", [connection], "MessagingApi")
|
|
27
|
-
}).catch((error) => {
|
|
28
|
-
console.error("❌ Failed to create alert connection:", error);
|
|
29
|
-
console.error("❌ Error details:", {
|
|
30
|
-
status: error.status,
|
|
31
|
-
message: error.message,
|
|
32
|
-
response: error.response
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
console.warn('⚠️ SocketHelper: Cannot create alert connection - missing data:', {
|
|
38
|
-
hasPersonId: !!_a.personIdChurchId.personId,
|
|
39
|
-
hasSocketId: !!_a.socketId,
|
|
40
|
-
personId: _a.personIdChurchId.personId,
|
|
41
|
-
socketId: _a.socketId
|
|
42
|
-
});
|
|
26
|
+
ApiHelper.postAnonymous("/connections", [connection], "MessagingApi");
|
|
43
27
|
}
|
|
44
28
|
};
|
|
45
29
|
SocketHelper.init = async () => {
|
|
@@ -49,55 +33,32 @@ SocketHelper.init = async () => {
|
|
|
49
33
|
try {
|
|
50
34
|
_a.socket.close();
|
|
51
35
|
}
|
|
52
|
-
catch
|
|
53
|
-
console.error("❌ Error closing existing socket:", e);
|
|
54
|
-
}
|
|
36
|
+
catch { /* ignore */ }
|
|
55
37
|
}
|
|
56
38
|
await new Promise((resolve, reject) => {
|
|
57
|
-
let hasReceivedSocketId = false;
|
|
58
|
-
let messageCount = 0;
|
|
59
39
|
try {
|
|
60
40
|
_a.socket = new WebSocket(CommonEnvironmentHelper.MessagingApiSocket);
|
|
61
41
|
_a.socket.onmessage = (event) => {
|
|
62
42
|
if (_a.isCleanedUp)
|
|
63
43
|
return;
|
|
64
|
-
messageCount++;
|
|
65
|
-
console.log("[SocketHelper.onmessage] Received message #" + messageCount + ":", event.data.substring(0, 200));
|
|
66
44
|
try {
|
|
67
45
|
const payload = JSON.parse(event.data);
|
|
68
|
-
console.log("[SocketHelper.onmessage] Parsed payload - action:", payload.action, "data:", JSON.stringify(payload.data).substring(0, 100));
|
|
69
|
-
if (payload.action === 'socketId') {
|
|
70
|
-
hasReceivedSocketId = true;
|
|
71
|
-
}
|
|
72
46
|
_a.handleMessage(payload);
|
|
73
47
|
}
|
|
74
|
-
catch
|
|
75
|
-
console.error("❌ Error parsing socket message:", error);
|
|
76
|
-
console.error("❌ Raw message was:", event.data);
|
|
77
|
-
}
|
|
48
|
+
catch { /* ignore parse errors */ }
|
|
78
49
|
};
|
|
79
|
-
_a.socket.onopen = async (
|
|
80
|
-
// Send the getId request
|
|
50
|
+
_a.socket.onopen = async () => {
|
|
81
51
|
_a.socket.send("getId");
|
|
82
|
-
// Wait longer to see if we get a response
|
|
83
52
|
setTimeout(() => {
|
|
84
|
-
if (!hasReceivedSocketId) {
|
|
85
|
-
console.warn('⚠️ SocketHelper: No socket ID received after 3 seconds');
|
|
86
|
-
}
|
|
87
53
|
resolve(null);
|
|
88
54
|
}, 3000);
|
|
89
55
|
};
|
|
90
|
-
_a.socket.onclose = async (
|
|
91
|
-
// Socket closed
|
|
92
|
-
};
|
|
56
|
+
_a.socket.onclose = async () => { };
|
|
93
57
|
_a.socket.onerror = (error) => {
|
|
94
|
-
console.error('❌ SocketHelper: WebSocket connection error:', error);
|
|
95
|
-
console.error('❌ SocketHelper: Messages received before error:', messageCount);
|
|
96
58
|
reject(error);
|
|
97
59
|
};
|
|
98
60
|
}
|
|
99
61
|
catch (error) {
|
|
100
|
-
console.error('❌ SocketHelper: Error initializing socket:', error);
|
|
101
62
|
reject(error);
|
|
102
63
|
}
|
|
103
64
|
});
|
|
@@ -124,29 +85,24 @@ SocketHelper.handleMessage = (payload) => {
|
|
|
124
85
|
if (_a.isCleanedUp)
|
|
125
86
|
return;
|
|
126
87
|
try {
|
|
127
|
-
console.log("[SocketHelper.handleMessage] Processing action:", payload.action);
|
|
128
|
-
console.log("[SocketHelper.handleMessage] Registered handlers:", _a.actionHandlers.map(h => ({ id: h.id, action: h.action })));
|
|
129
88
|
if (payload.action === "socketId") {
|
|
130
89
|
_a.socketId = payload.data;
|
|
131
|
-
console.log("[SocketHelper.handleMessage] Set socketId:", _a.socketId);
|
|
132
90
|
_a.createAlertConnection();
|
|
133
91
|
}
|
|
134
92
|
else {
|
|
135
93
|
const matchingHandlers = ArrayHelper.getAll(_a.actionHandlers, "action", payload.action);
|
|
136
|
-
console.log("[SocketHelper.handleMessage] Found", matchingHandlers.length, "matching handlers for action:", payload.action);
|
|
137
94
|
matchingHandlers.forEach((handler) => {
|
|
138
95
|
try {
|
|
139
|
-
console.log("[SocketHelper.handleMessage] Calling handler:", handler.id);
|
|
140
96
|
handler.handleMessage(payload.data);
|
|
141
97
|
}
|
|
142
98
|
catch (error) {
|
|
143
|
-
console.error(
|
|
99
|
+
console.error(`Error in handler ${handler.id}:`, error);
|
|
144
100
|
}
|
|
145
101
|
});
|
|
146
102
|
}
|
|
147
103
|
}
|
|
148
104
|
catch (error) {
|
|
149
|
-
console.error("
|
|
105
|
+
console.error("Error handling socket message:", error);
|
|
150
106
|
}
|
|
151
107
|
};
|
|
152
108
|
SocketHelper.cleanup = () => {
|
|
@@ -156,14 +112,11 @@ SocketHelper.cleanup = () => {
|
|
|
156
112
|
try {
|
|
157
113
|
_a.socket.close();
|
|
158
114
|
}
|
|
159
|
-
catch
|
|
160
|
-
console.error("Error closing socket:", error);
|
|
161
|
-
}
|
|
115
|
+
catch { /* ignore */ }
|
|
162
116
|
}
|
|
163
|
-
// Clear references
|
|
117
|
+
// Clear references but preserve handlers - they should persist across reconnects
|
|
164
118
|
_a.socket = null;
|
|
165
119
|
_a.socketId = null;
|
|
166
|
-
_a.actionHandlers = [];
|
|
167
120
|
_a.personIdChurchId = { personId: "", churchId: "" };
|
|
168
121
|
};
|
|
169
122
|
SocketHelper.disconnect = () => {
|
|
@@ -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;;;AAGjB,2BAAc,GAAmC,EAAE,AAArC,CAAsC;AAC5C,6BAAgB,GAA2C,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,AAAzE,CAA0E;AAC1F,wBAAW,GAAY,KAAK,AAAjB,CAAkB;AAErC,4BAAe,GAAG,CAAC,EAA0C,EAAE,EAAE;IAEvE,IAAI,EAAE,EAAE,QAAQ,IAAI,EAAE,CAAC,QAAQ,IAAI,EAAE,CAAC,QAAQ,KAAK,EAAI,CAAC,gBAAgB,CAAC,QAAQ,IAAI,EAAE,CAAC,QAAQ,KAAK,EAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QACrI,EAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B,EAAI,CAAC,qBAAqB,EAAE,CAAC;IAC9B,CAAC;SAAM,CAAC;IACR,CAAC;AACF,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AgB,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
|
@@ -17,7 +17,6 @@ export class SocketHelper {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
static createAlertConnection = () => {
|
|
20
|
-
|
|
21
20
|
if (SocketHelper.personIdChurchId.personId && SocketHelper.socketId) {
|
|
22
21
|
const connection: ConnectionInterface = {
|
|
23
22
|
conversationId: "alerts",
|
|
@@ -27,23 +26,7 @@ export class SocketHelper {
|
|
|
27
26
|
personId: SocketHelper.personIdChurchId.personId
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
ApiHelper.postAnonymous("/connections", [connection], "MessagingApi").then((response: any) => {
|
|
32
|
-
}).catch((error: any) => {
|
|
33
|
-
console.error("❌ Failed to create alert connection:", error);
|
|
34
|
-
console.error("❌ Error details:", {
|
|
35
|
-
status: error.status,
|
|
36
|
-
message: error.message,
|
|
37
|
-
response: error.response
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
console.warn('⚠️ SocketHelper: Cannot create alert connection - missing data:', {
|
|
42
|
-
hasPersonId: !!SocketHelper.personIdChurchId.personId,
|
|
43
|
-
hasSocketId: !!SocketHelper.socketId,
|
|
44
|
-
personId: SocketHelper.personIdChurchId.personId,
|
|
45
|
-
socketId: SocketHelper.socketId
|
|
46
|
-
});
|
|
29
|
+
ApiHelper.postAnonymous("/connections", [connection], "MessagingApi");
|
|
47
30
|
}
|
|
48
31
|
}
|
|
49
32
|
|
|
@@ -54,66 +37,37 @@ export class SocketHelper {
|
|
|
54
37
|
if (SocketHelper.socket && SocketHelper.socket.readyState !== SocketHelper.socket.CLOSED) {
|
|
55
38
|
try {
|
|
56
39
|
SocketHelper.socket.close();
|
|
57
|
-
} catch
|
|
58
|
-
console.error("❌ Error closing existing socket:", e);
|
|
59
|
-
}
|
|
40
|
+
} catch { /* ignore */ }
|
|
60
41
|
}
|
|
61
42
|
|
|
62
|
-
|
|
63
43
|
await new Promise((resolve, reject) => {
|
|
64
|
-
let hasReceivedSocketId = false;
|
|
65
|
-
let messageCount = 0;
|
|
66
|
-
|
|
67
44
|
try {
|
|
68
45
|
SocketHelper.socket = new WebSocket(CommonEnvironmentHelper.MessagingApiSocket);
|
|
69
46
|
|
|
70
47
|
SocketHelper.socket.onmessage = (event) => {
|
|
71
48
|
if (SocketHelper.isCleanedUp) return;
|
|
72
49
|
|
|
73
|
-
messageCount++;
|
|
74
|
-
console.log("[SocketHelper.onmessage] Received message #" + messageCount + ":", event.data.substring(0, 200));
|
|
75
|
-
|
|
76
50
|
try {
|
|
77
51
|
const payload = JSON.parse(event.data);
|
|
78
|
-
console.log("[SocketHelper.onmessage] Parsed payload - action:", payload.action, "data:", JSON.stringify(payload.data).substring(0, 100));
|
|
79
|
-
|
|
80
|
-
if (payload.action === 'socketId') {
|
|
81
|
-
hasReceivedSocketId = true;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
52
|
SocketHelper.handleMessage(payload);
|
|
85
|
-
} catch
|
|
86
|
-
console.error("❌ Error parsing socket message:", error);
|
|
87
|
-
console.error("❌ Raw message was:", event.data);
|
|
88
|
-
}
|
|
53
|
+
} catch { /* ignore parse errors */ }
|
|
89
54
|
};
|
|
90
55
|
|
|
91
|
-
SocketHelper.socket.onopen = async (
|
|
92
|
-
|
|
93
|
-
// Send the getId request
|
|
56
|
+
SocketHelper.socket.onopen = async () => {
|
|
94
57
|
SocketHelper.socket.send("getId");
|
|
95
58
|
|
|
96
|
-
// Wait longer to see if we get a response
|
|
97
59
|
setTimeout(() => {
|
|
98
|
-
if (!hasReceivedSocketId) {
|
|
99
|
-
console.warn('⚠️ SocketHelper: No socket ID received after 3 seconds');
|
|
100
|
-
}
|
|
101
60
|
resolve(null);
|
|
102
61
|
}, 3000);
|
|
103
62
|
};
|
|
104
63
|
|
|
105
|
-
SocketHelper.socket.onclose = async (
|
|
106
|
-
// Socket closed
|
|
107
|
-
};
|
|
64
|
+
SocketHelper.socket.onclose = async () => { };
|
|
108
65
|
|
|
109
66
|
SocketHelper.socket.onerror = (error) => {
|
|
110
|
-
console.error('❌ SocketHelper: WebSocket connection error:', error);
|
|
111
|
-
console.error('❌ SocketHelper: Messages received before error:', messageCount);
|
|
112
67
|
reject(error);
|
|
113
68
|
};
|
|
114
69
|
|
|
115
70
|
} catch (error) {
|
|
116
|
-
console.error('❌ SocketHelper: Error initializing socket:', error);
|
|
117
71
|
reject(error);
|
|
118
72
|
}
|
|
119
73
|
});
|
|
@@ -144,29 +98,22 @@ export class SocketHelper {
|
|
|
144
98
|
if (SocketHelper.isCleanedUp) return;
|
|
145
99
|
|
|
146
100
|
try {
|
|
147
|
-
console.log("[SocketHelper.handleMessage] Processing action:", payload.action);
|
|
148
|
-
console.log("[SocketHelper.handleMessage] Registered handlers:", SocketHelper.actionHandlers.map(h => ({ id: h.id, action: h.action })));
|
|
149
|
-
|
|
150
101
|
if (payload.action === "socketId") {
|
|
151
102
|
SocketHelper.socketId = payload.data;
|
|
152
|
-
console.log("[SocketHelper.handleMessage] Set socketId:", SocketHelper.socketId);
|
|
153
103
|
SocketHelper.createAlertConnection();
|
|
154
104
|
}
|
|
155
105
|
else {
|
|
156
106
|
const matchingHandlers = ArrayHelper.getAll(SocketHelper.actionHandlers, "action", payload.action);
|
|
157
|
-
console.log("[SocketHelper.handleMessage] Found", matchingHandlers.length, "matching handlers for action:", payload.action);
|
|
158
|
-
|
|
159
107
|
matchingHandlers.forEach((handler) => {
|
|
160
108
|
try {
|
|
161
|
-
console.log("[SocketHelper.handleMessage] Calling handler:", handler.id);
|
|
162
109
|
handler.handleMessage(payload.data);
|
|
163
110
|
} catch (error) {
|
|
164
|
-
console.error(
|
|
111
|
+
console.error(`Error in handler ${handler.id}:`, error);
|
|
165
112
|
}
|
|
166
113
|
});
|
|
167
114
|
}
|
|
168
115
|
} catch (error) {
|
|
169
|
-
console.error("
|
|
116
|
+
console.error("Error handling socket message:", error);
|
|
170
117
|
}
|
|
171
118
|
}
|
|
172
119
|
|
|
@@ -177,15 +124,12 @@ export class SocketHelper {
|
|
|
177
124
|
if (SocketHelper.socket && SocketHelper.socket.readyState !== SocketHelper.socket.CLOSED) {
|
|
178
125
|
try {
|
|
179
126
|
SocketHelper.socket.close();
|
|
180
|
-
} catch
|
|
181
|
-
console.error("Error closing socket:", error);
|
|
182
|
-
}
|
|
127
|
+
} catch { /* ignore */ }
|
|
183
128
|
}
|
|
184
129
|
|
|
185
|
-
// Clear references
|
|
130
|
+
// Clear references but preserve handlers - they should persist across reconnects
|
|
186
131
|
SocketHelper.socket = null;
|
|
187
132
|
SocketHelper.socketId = null;
|
|
188
|
-
SocketHelper.actionHandlers = [];
|
|
189
133
|
SocketHelper.personIdChurchId = { personId: "", churchId: "" };
|
|
190
134
|
}
|
|
191
135
|
|