@hmcts/ccd-case-ui-toolkit 7.3.0-exui-2906-activity-tracker-5 → 7.3.0-exui-2906-activity-tracker-6
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.
|
@@ -2201,6 +2201,9 @@ class ActivitySocketService {
|
|
|
2201
2201
|
connect_error;
|
|
2202
2202
|
disconnect;
|
|
2203
2203
|
connected = new BehaviorSubject(false);
|
|
2204
|
+
lastViewEmit = { caseId: '', time: 0 };
|
|
2205
|
+
lastEditEmit = { caseId: '', time: 0 };
|
|
2206
|
+
emitCooldownMs = 250; // ignore duplicate emits within 250ms
|
|
2204
2207
|
socket;
|
|
2205
2208
|
pUser;
|
|
2206
2209
|
get user() {
|
|
@@ -2225,24 +2228,108 @@ class ActivitySocketService {
|
|
|
2225
2228
|
watchCases(caseIds) {
|
|
2226
2229
|
this.socket.emit('watch', { caseIds });
|
|
2227
2230
|
}
|
|
2231
|
+
// public viewCase(caseId: string, isViewing?: boolean): void {
|
|
2232
|
+
// // only emit if viewing is true and socket is connected
|
|
2233
|
+
// if(isViewing && this.socket && this.connected.value) {
|
|
2234
|
+
// console.log('viewCase emit');
|
|
2235
|
+
// this.socket.emit('view', { caseId });
|
|
2236
|
+
// }
|
|
2237
|
+
// }
|
|
2238
|
+
// public stopCase(caseId: string, isStopping?: boolean): void {
|
|
2239
|
+
// // only emit if stopping is true
|
|
2240
|
+
// if(isStopping) {
|
|
2241
|
+
// this.socket.emit('stop', { caseId });
|
|
2242
|
+
// }
|
|
2243
|
+
// }
|
|
2244
|
+
// public editCase(caseId: string, isEditing?: boolean): void {
|
|
2245
|
+
// // only emit if editing is true and socket is connected
|
|
2246
|
+
// if(isEditing && this.socket && this.connected.value) {
|
|
2247
|
+
// console.log('editCase emit');
|
|
2248
|
+
// this.socket.emit('edit', { caseId });
|
|
2249
|
+
// }
|
|
2250
|
+
// }
|
|
2251
|
+
// keep small wrappers to avoid breaking callers
|
|
2228
2252
|
viewCase(caseId, isViewing) {
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2253
|
+
if (isViewing) {
|
|
2254
|
+
this.startViewing(caseId);
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
editCase(caseId, isEditing) {
|
|
2258
|
+
if (isEditing) {
|
|
2259
|
+
this.startEditing(caseId);
|
|
2233
2260
|
}
|
|
2234
2261
|
}
|
|
2235
2262
|
stopCase(caseId, isStopping) {
|
|
2236
|
-
// only emit if stopping is true
|
|
2237
2263
|
if (isStopping) {
|
|
2264
|
+
this.stopViewing(caseId);
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* Start viewing a case (explicit).
|
|
2269
|
+
* Only emits when socket exists and is connected.
|
|
2270
|
+
*/
|
|
2271
|
+
startViewing(caseId) {
|
|
2272
|
+
if (!caseId) {
|
|
2273
|
+
return;
|
|
2274
|
+
}
|
|
2275
|
+
if (!this.socket || !this.connected.value) {
|
|
2276
|
+
return;
|
|
2277
|
+
} // defensive
|
|
2278
|
+
const now = Date.now();
|
|
2279
|
+
if (this.lastViewEmit.caseId === caseId && (now - this.lastViewEmit.time) < this.emitCooldownMs) {
|
|
2280
|
+
return; // duplicate within cooldown
|
|
2281
|
+
}
|
|
2282
|
+
console.log('startViewing emit');
|
|
2283
|
+
try {
|
|
2284
|
+
this.socket.emit('view', { caseId });
|
|
2285
|
+
this.lastViewEmit = { caseId, time: now };
|
|
2286
|
+
}
|
|
2287
|
+
catch (e) {
|
|
2288
|
+
console.warn('startViewing emit failed', e);
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
/**
|
|
2292
|
+
* Stop viewing a case (explicit).
|
|
2293
|
+
* Safe no-op if socket not connected.
|
|
2294
|
+
*/
|
|
2295
|
+
stopViewing(caseId) {
|
|
2296
|
+
if (!caseId) {
|
|
2297
|
+
return;
|
|
2298
|
+
}
|
|
2299
|
+
if (!this.socket || !this.connected.value) {
|
|
2300
|
+
return;
|
|
2301
|
+
}
|
|
2302
|
+
try {
|
|
2238
2303
|
this.socket.emit('stop', { caseId });
|
|
2304
|
+
if (this.lastViewEmit.caseId === caseId) {
|
|
2305
|
+
this.lastViewEmit = { caseId: '', time: 0 };
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
catch (e) {
|
|
2309
|
+
console.warn('stopViewing emit failed', e);
|
|
2239
2310
|
}
|
|
2240
2311
|
}
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2312
|
+
/**
|
|
2313
|
+
* Start editing a case (explicit).
|
|
2314
|
+
*/
|
|
2315
|
+
startEditing(caseId) {
|
|
2316
|
+
if (!caseId) {
|
|
2317
|
+
return;
|
|
2318
|
+
}
|
|
2319
|
+
if (!this.socket || !this.connected.value) {
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
const now = Date.now();
|
|
2323
|
+
if (this.lastEditEmit.caseId === caseId && (now - this.lastEditEmit.time) < this.emitCooldownMs) {
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
console.log('startEditing emit', caseId);
|
|
2327
|
+
try {
|
|
2245
2328
|
this.socket.emit('edit', { caseId });
|
|
2329
|
+
this.lastEditEmit = { caseId, time: now };
|
|
2330
|
+
}
|
|
2331
|
+
catch (e) {
|
|
2332
|
+
console.warn('startEditing emit failed', e);
|
|
2246
2333
|
}
|
|
2247
2334
|
}
|
|
2248
2335
|
init() {
|