@bit.rhplus/signal 0.0.12 → 0.0.13
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.
- package/SignalProvider.jsx +0 -16
- package/dist/SignalProvider.js +0 -16
- package/dist/SignalProvider.js.map +1 -1
- package/dist/useEventEmitter.js +0 -18
- package/dist/useEventEmitter.js.map +1 -1
- package/dist/useSignalListener.js +0 -45
- package/dist/useSignalListener.js.map +1 -1
- package/package.json +2 -2
- package/useEventEmitter.js +2 -19
- package/useSignalListener.js +1 -51
- /package/dist/{preview-1763315539949.js → preview-1764335014038.js} +0 -0
package/SignalProvider.jsx
CHANGED
|
@@ -36,32 +36,19 @@ export function SignalProvider({
|
|
|
36
36
|
|
|
37
37
|
React.useEffect(() => {
|
|
38
38
|
if (!connection) {
|
|
39
|
-
// eslint-disable-next-line no-console
|
|
40
|
-
console.log('[SignalProvider] No connection yet');
|
|
41
39
|
return;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
// eslint-disable-next-line no-console
|
|
45
|
-
console.log('[SignalProvider] Starting SignalR connection...');
|
|
46
42
|
|
|
47
43
|
const startConnection = async () => {
|
|
48
44
|
try {
|
|
49
45
|
await connection.start();
|
|
50
|
-
// eslint-disable-next-line no-console
|
|
51
|
-
console.log('[SignalProvider] ✅ SignalR connected successfully!');
|
|
52
46
|
|
|
53
47
|
connection.on("Signal", message => {
|
|
54
|
-
// eslint-disable-next-line no-console
|
|
55
|
-
console.log('[SignalProvider] 📨 Message received from server:', message);
|
|
56
48
|
emit("Signal", message);
|
|
57
|
-
// eslint-disable-next-line no-console
|
|
58
|
-
console.log('[SignalProvider] 📤 Message emitted to listeners');
|
|
59
49
|
});
|
|
60
50
|
|
|
61
|
-
// eslint-disable-next-line no-console
|
|
62
|
-
console.log('[SignalProvider] Subscribed to "Signal" event on connection');
|
|
63
51
|
} catch (e) {
|
|
64
|
-
// eslint-disable-next-line no-console
|
|
65
52
|
console.error('[SignalProvider] ❌ Failed to start connection:', e);
|
|
66
53
|
}
|
|
67
54
|
};
|
|
@@ -70,10 +57,7 @@ export function SignalProvider({
|
|
|
70
57
|
|
|
71
58
|
/* eslint-disable consistent-return */
|
|
72
59
|
return () => {
|
|
73
|
-
// eslint-disable-next-line no-console
|
|
74
|
-
console.log('[SignalProvider] Stopping connection...');
|
|
75
60
|
connection.stop().catch(e => {
|
|
76
|
-
// eslint-disable-next-line no-console
|
|
77
61
|
console.error('[SignalProvider] Error stopping connection:', e);
|
|
78
62
|
});
|
|
79
63
|
};
|
package/dist/SignalProvider.js
CHANGED
|
@@ -22,39 +22,23 @@ export function SignalProvider({ children, authority, endpoint, accessToken, req
|
|
|
22
22
|
}, [accessToken]); // Oprava: odstraněná nadbytečná čárka ve závislostech
|
|
23
23
|
React.useEffect(() => {
|
|
24
24
|
if (!connection) {
|
|
25
|
-
// eslint-disable-next-line no-console
|
|
26
|
-
console.log('[SignalProvider] No connection yet');
|
|
27
25
|
return;
|
|
28
26
|
}
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
|
-
console.log('[SignalProvider] Starting SignalR connection...');
|
|
31
27
|
const startConnection = async () => {
|
|
32
28
|
try {
|
|
33
29
|
await connection.start();
|
|
34
|
-
// eslint-disable-next-line no-console
|
|
35
|
-
console.log('[SignalProvider] ✅ SignalR connected successfully!');
|
|
36
30
|
connection.on("Signal", message => {
|
|
37
|
-
// eslint-disable-next-line no-console
|
|
38
|
-
console.log('[SignalProvider] 📨 Message received from server:', message);
|
|
39
31
|
emit("Signal", message);
|
|
40
|
-
// eslint-disable-next-line no-console
|
|
41
|
-
console.log('[SignalProvider] 📤 Message emitted to listeners');
|
|
42
32
|
});
|
|
43
|
-
// eslint-disable-next-line no-console
|
|
44
|
-
console.log('[SignalProvider] Subscribed to "Signal" event on connection');
|
|
45
33
|
}
|
|
46
34
|
catch (e) {
|
|
47
|
-
// eslint-disable-next-line no-console
|
|
48
35
|
console.error('[SignalProvider] ❌ Failed to start connection:', e);
|
|
49
36
|
}
|
|
50
37
|
};
|
|
51
38
|
startConnection();
|
|
52
39
|
/* eslint-disable consistent-return */
|
|
53
40
|
return () => {
|
|
54
|
-
// eslint-disable-next-line no-console
|
|
55
|
-
console.log('[SignalProvider] Stopping connection...');
|
|
56
41
|
connection.stop().catch(e => {
|
|
57
|
-
// eslint-disable-next-line no-console
|
|
58
42
|
console.error('[SignalProvider] Error stopping connection:', e);
|
|
59
43
|
});
|
|
60
44
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignalProvider.js","sourceRoot":"","sources":["../SignalProvider.jsx"],"names":[],"mappings":";AAAA,oBAAoB;AACpB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AAEvD,MAAM,UAAU,cAAc,CAAC,EAC7B,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,WAAW,EACX,mBAAmB,EACnB,QAAQ,EACR,WAAW,GAAG,KAAK,EACpB;IACC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,eAAe,EAAE,CAAC;IACvC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEzD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,IAAI,mBAAmB,IAAI,CAAC,WAAW,EAAE,CAAC;YACxC,OAAO,CAAC,uCAAuC;QACjD,CAAC;QAED,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,kBAAkB,EAAE,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7E,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,QAAQ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,CAAC;YACf,IAAI,CAAC;gBACH,MAAM,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE;oBAChC,SAAS;oBACT,OAAO;iBACR,CAAC,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,uCAAuC;YACzC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,YAC1C,QAAQ,GACc,CAC1B,CAAC;AACJ,CAAC"}
|
package/dist/useEventEmitter.js
CHANGED
|
@@ -4,32 +4,14 @@ export function useEventEmitter() {
|
|
|
4
4
|
const listeners = React.useRef(new Map());
|
|
5
5
|
const emit = React.useCallback((event, data) => {
|
|
6
6
|
const eventListenersToEmit = listeners.current.get(event) || [];
|
|
7
|
-
// eslint-disable-next-line no-console
|
|
8
|
-
console.log('[useEventEmitter] emit()', {
|
|
9
|
-
event,
|
|
10
|
-
data,
|
|
11
|
-
listenerCount: eventListenersToEmit.length
|
|
12
|
-
});
|
|
13
7
|
eventListenersToEmit.forEach(listener => listener(data));
|
|
14
|
-
// eslint-disable-next-line no-console
|
|
15
|
-
console.log('[useEventEmitter] All listeners called');
|
|
16
8
|
}, []);
|
|
17
9
|
const on = React.useCallback((event, listener) => {
|
|
18
10
|
const eventListeners = listeners.current.get(event) || [];
|
|
19
11
|
listeners.current.set(event, [...eventListeners, listener]);
|
|
20
|
-
// eslint-disable-next-line no-console
|
|
21
|
-
console.log('[useEventEmitter] on() - Listener registered', {
|
|
22
|
-
event,
|
|
23
|
-
totalListeners: listeners.current.get(event).length
|
|
24
|
-
});
|
|
25
12
|
return () => {
|
|
26
13
|
const eventListenersToRemove = listeners.current.get(event) || [];
|
|
27
14
|
listeners.current.set(event, eventListenersToRemove.filter(l => l !== listener));
|
|
28
|
-
// eslint-disable-next-line no-console
|
|
29
|
-
console.log('[useEventEmitter] Listener unregistered', {
|
|
30
|
-
event,
|
|
31
|
-
remainingListeners: listeners.current.get(event).length
|
|
32
|
-
});
|
|
33
15
|
};
|
|
34
16
|
});
|
|
35
17
|
return { emit, on };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEventEmitter.js","sourceRoot":"","sources":["../useEventEmitter.js"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,UAAU,eAAe;IAC7B,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;IAE1C,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC7C,MAAM,oBAAoB,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAChE,
|
|
1
|
+
{"version":3,"file":"useEventEmitter.js","sourceRoot":"","sources":["../useEventEmitter.js"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,UAAU,eAAe;IAC7B,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;IAE1C,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC7C,MAAM,oBAAoB,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAChE,oBAAoB,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3D,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,MAAM,EAAE,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;QAC/C,MAAM,cAAc,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1D,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,cAAc,EAAE,QAAQ,CAAC,CAAC,CAAC;QAE5D,OAAO,GAAG,EAAE;YACV,MAAM,sBAAsB,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;YAClE,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC;QACnF,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,EAAC,IAAI,EAAE,EAAE,EAAC,CAAC;AACpB,CAAC"}
|
|
@@ -8,76 +8,31 @@ export function useSignalListeners(eventNames, callback, enableConsole = false)
|
|
|
8
8
|
const consoleRef = React.useRef(enableConsole);
|
|
9
9
|
const eventNamesRef = React.useRef(eventNames);
|
|
10
10
|
const { on } = React.useContext(SignalContext);
|
|
11
|
-
// eslint-disable-next-line no-console
|
|
12
|
-
console.log('[useSignalListeners] 1. Hook initialized', {
|
|
13
|
-
eventNames,
|
|
14
|
-
hasCallback: !!callback,
|
|
15
|
-
consoleEnabled: enableConsole,
|
|
16
|
-
hasOn: !!on
|
|
17
|
-
});
|
|
18
11
|
// Aktualizace refů při každém renderu
|
|
19
12
|
React.useEffect(() => {
|
|
20
|
-
// eslint-disable-next-line no-console
|
|
21
|
-
console.log('[useSignalListeners] 2. Refs updated', {
|
|
22
|
-
eventNames,
|
|
23
|
-
consoleEnabled: enableConsole
|
|
24
|
-
});
|
|
25
13
|
listenerCallback.current = callback;
|
|
26
14
|
consoleRef.current = enableConsole;
|
|
27
15
|
eventNamesRef.current = eventNames;
|
|
28
16
|
});
|
|
29
17
|
// Přihlášení a odhlášení od signálů - spustí se pouze jednou
|
|
30
18
|
React.useEffect(() => {
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
|
-
console.log('[useSignalListeners] 3. Setting up listener', {
|
|
33
|
-
hasOn: !!on,
|
|
34
|
-
eventNames: eventNamesRef.current
|
|
35
|
-
});
|
|
36
19
|
if (!on) {
|
|
37
|
-
// eslint-disable-next-line no-console
|
|
38
20
|
console.warn('[useSignalListeners] 4. No "on" function - cannot subscribe!');
|
|
39
21
|
return;
|
|
40
22
|
}
|
|
41
23
|
// Funkce, která se spustí, když přijde signál
|
|
42
24
|
const onSignal = (data) => {
|
|
43
|
-
// eslint-disable-next-line no-console
|
|
44
|
-
console.log('[useSignalListeners] 5. Signal received!', {
|
|
45
|
-
receivedEventName: data?.eventName,
|
|
46
|
-
expectedEventNames: eventNamesRef.current,
|
|
47
|
-
matches: eventNamesRef.current.includes(data?.eventName),
|
|
48
|
-
fullData: data
|
|
49
|
-
});
|
|
50
25
|
if (eventNamesRef.current.includes(data.eventName)) {
|
|
51
|
-
// eslint-disable-next-line no-console
|
|
52
|
-
console.log('[useSignalListeners] 6. Event name matches - processing', data.eventName);
|
|
53
26
|
// Logování pokud je console === true
|
|
54
27
|
if (consoleRef.current === true) {
|
|
55
|
-
// eslint-disable-next-line no-console
|
|
56
28
|
console.log('[SignalR]', data.eventName, data);
|
|
57
29
|
}
|
|
58
|
-
// eslint-disable-next-line no-console
|
|
59
|
-
console.log('[useSignalListeners] 7. Calling callback');
|
|
60
30
|
listenerCallback.current(data);
|
|
61
31
|
}
|
|
62
|
-
else {
|
|
63
|
-
// eslint-disable-next-line no-console
|
|
64
|
-
console.log('[useSignalListeners] 6. Event name does NOT match - ignoring', {
|
|
65
|
-
received: data.eventName,
|
|
66
|
-
expected: eventNamesRef.current
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
32
|
};
|
|
70
|
-
// eslint-disable-next-line no-console
|
|
71
|
-
console.log('[useSignalListeners] 8. Subscribing to "Signal" event');
|
|
72
33
|
const unsubscribe = on("Signal", onSignal);
|
|
73
|
-
// eslint-disable-next-line no-console
|
|
74
|
-
console.log('[useSignalListeners] 9. Subscribed successfully', {
|
|
75
|
-
hasUnsubscribe: !!unsubscribe
|
|
76
|
-
});
|
|
77
34
|
// Při unmountu komponenty se odhlásíme od poslechu na signál
|
|
78
35
|
return () => {
|
|
79
|
-
// eslint-disable-next-line no-console
|
|
80
|
-
console.log('[useSignalListeners] 10. Unsubscribing');
|
|
81
36
|
unsubscribe();
|
|
82
37
|
};
|
|
83
38
|
}, [on]); // Pouze 'on' jako závislost - registruje se jen jednou
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSignalListener.js","sourceRoot":"","sources":["../useSignalListener.js"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qDAAqD;AACrD,MAAM,UAAU,kBAAkB,CAAC,UAAU,EAAE,QAAQ,EAAE,aAAa,GAAG,KAAK;IAC5E,gEAAgE;IAChE,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;IAC/C,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IAE/C,sCAAsC;IACtC,
|
|
1
|
+
{"version":3,"file":"useSignalListener.js","sourceRoot":"","sources":["../useSignalListener.js"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,qDAAqD;AACrD,MAAM,U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AO,GAAG,EAAE;YACV,WAAW,EAAE,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,uDAAuD;AACnE,CAAC;AAED,mCAAmC;AACnC,MAAM,UAAU,iBAAiB,CAAC,SAAS,EAAE,QAAQ,EAAE,aAAa,GAAG,KAAK;IAC1E,gEAAgE;IAChE,kBAAkB,CAAC,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;AAC3D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bit.rhplus/signal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"homepage": "https://bit.cloud/remote-scope/signal",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "remote-scope",
|
|
8
8
|
"name": "signal",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.13"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@microsoft/signalr": "8.0.0"
|
package/useEventEmitter.js
CHANGED
|
@@ -5,34 +5,17 @@ export function useEventEmitter() {
|
|
|
5
5
|
const listeners = React.useRef(new Map());
|
|
6
6
|
|
|
7
7
|
const emit = React.useCallback((event, data) => {
|
|
8
|
-
const eventListenersToEmit = listeners.current.get(event) || [];
|
|
9
|
-
// eslint-disable-next-line no-console
|
|
10
|
-
console.log('[useEventEmitter] emit()', {
|
|
11
|
-
event,
|
|
12
|
-
data,
|
|
13
|
-
listenerCount: eventListenersToEmit.length
|
|
14
|
-
});
|
|
8
|
+
const eventListenersToEmit = listeners.current.get(event) || [];
|
|
15
9
|
eventListenersToEmit.forEach(listener => listener(data));
|
|
16
|
-
// eslint-disable-next-line no-console
|
|
17
|
-
console.log('[useEventEmitter] All listeners called');
|
|
18
10
|
}, [])
|
|
19
11
|
|
|
20
12
|
const on = React.useCallback((event, listener) => {
|
|
21
13
|
const eventListeners = listeners.current.get(event) || [];
|
|
22
14
|
listeners.current.set(event, [...eventListeners, listener]);
|
|
23
|
-
|
|
24
|
-
console.log('[useEventEmitter] on() - Listener registered', {
|
|
25
|
-
event,
|
|
26
|
-
totalListeners: listeners.current.get(event).length
|
|
27
|
-
});
|
|
15
|
+
|
|
28
16
|
return () => {
|
|
29
17
|
const eventListenersToRemove = listeners.current.get(event) || [];
|
|
30
18
|
listeners.current.set(event, eventListenersToRemove.filter(l => l !== listener));
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
|
-
console.log('[useEventEmitter] Listener unregistered', {
|
|
33
|
-
event,
|
|
34
|
-
remainingListeners: listeners.current.get(event).length
|
|
35
|
-
});
|
|
36
19
|
}
|
|
37
20
|
})
|
|
38
21
|
|
package/useSignalListener.js
CHANGED
|
@@ -10,21 +10,8 @@ export function useSignalListeners(eventNames, callback, enableConsole = false)
|
|
|
10
10
|
const eventNamesRef = React.useRef(eventNames);
|
|
11
11
|
const { on } = React.useContext(SignalContext);
|
|
12
12
|
|
|
13
|
-
// eslint-disable-next-line no-console
|
|
14
|
-
console.log('[useSignalListeners] 1. Hook initialized', {
|
|
15
|
-
eventNames,
|
|
16
|
-
hasCallback: !!callback,
|
|
17
|
-
consoleEnabled: enableConsole,
|
|
18
|
-
hasOn: !!on
|
|
19
|
-
});
|
|
20
|
-
|
|
21
13
|
// Aktualizace refů při každém renderu
|
|
22
|
-
React.useEffect(() => {
|
|
23
|
-
// eslint-disable-next-line no-console
|
|
24
|
-
console.log('[useSignalListeners] 2. Refs updated', {
|
|
25
|
-
eventNames,
|
|
26
|
-
consoleEnabled: enableConsole
|
|
27
|
-
});
|
|
14
|
+
React.useEffect(() => {
|
|
28
15
|
listenerCallback.current = callback;
|
|
29
16
|
consoleRef.current = enableConsole;
|
|
30
17
|
eventNamesRef.current = eventNames;
|
|
@@ -32,62 +19,25 @@ export function useSignalListeners(eventNames, callback, enableConsole = false)
|
|
|
32
19
|
|
|
33
20
|
// Přihlášení a odhlášení od signálů - spustí se pouze jednou
|
|
34
21
|
React.useEffect(() => {
|
|
35
|
-
// eslint-disable-next-line no-console
|
|
36
|
-
console.log('[useSignalListeners] 3. Setting up listener', {
|
|
37
|
-
hasOn: !!on,
|
|
38
|
-
eventNames: eventNamesRef.current
|
|
39
|
-
});
|
|
40
|
-
|
|
41
22
|
if (!on) {
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
23
|
console.warn('[useSignalListeners] 4. No "on" function - cannot subscribe!');
|
|
44
24
|
return;
|
|
45
25
|
}
|
|
46
26
|
|
|
47
27
|
// Funkce, která se spustí, když přijde signál
|
|
48
28
|
const onSignal = (data) => {
|
|
49
|
-
// eslint-disable-next-line no-console
|
|
50
|
-
console.log('[useSignalListeners] 5. Signal received!', {
|
|
51
|
-
receivedEventName: data?.eventName,
|
|
52
|
-
expectedEventNames: eventNamesRef.current,
|
|
53
|
-
matches: eventNamesRef.current.includes(data?.eventName),
|
|
54
|
-
fullData: data
|
|
55
|
-
});
|
|
56
|
-
|
|
57
29
|
if (eventNamesRef.current.includes(data.eventName)) {
|
|
58
|
-
// eslint-disable-next-line no-console
|
|
59
|
-
console.log('[useSignalListeners] 6. Event name matches - processing', data.eventName);
|
|
60
|
-
|
|
61
30
|
// Logování pokud je console === true
|
|
62
31
|
if (consoleRef.current === true) {
|
|
63
|
-
// eslint-disable-next-line no-console
|
|
64
32
|
console.log('[SignalR]', data.eventName, data);
|
|
65
33
|
}
|
|
66
|
-
|
|
67
|
-
// eslint-disable-next-line no-console
|
|
68
|
-
console.log('[useSignalListeners] 7. Calling callback');
|
|
69
34
|
listenerCallback.current(data);
|
|
70
|
-
} else {
|
|
71
|
-
// eslint-disable-next-line no-console
|
|
72
|
-
console.log('[useSignalListeners] 6. Event name does NOT match - ignoring', {
|
|
73
|
-
received: data.eventName,
|
|
74
|
-
expected: eventNamesRef.current
|
|
75
|
-
});
|
|
76
35
|
}
|
|
77
36
|
};
|
|
78
37
|
|
|
79
|
-
// eslint-disable-next-line no-console
|
|
80
|
-
console.log('[useSignalListeners] 8. Subscribing to "Signal" event');
|
|
81
38
|
const unsubscribe = on("Signal", onSignal);
|
|
82
|
-
// eslint-disable-next-line no-console
|
|
83
|
-
console.log('[useSignalListeners] 9. Subscribed successfully', {
|
|
84
|
-
hasUnsubscribe: !!unsubscribe
|
|
85
|
-
});
|
|
86
|
-
|
|
87
39
|
// Při unmountu komponenty se odhlásíme od poslechu na signál
|
|
88
40
|
return () => {
|
|
89
|
-
// eslint-disable-next-line no-console
|
|
90
|
-
console.log('[useSignalListeners] 10. Unsubscribing');
|
|
91
41
|
unsubscribe();
|
|
92
42
|
};
|
|
93
43
|
}, [on]); // Pouze 'on' jako závislost - registruje se jen jednou
|
|
File without changes
|