@@ -3,13 +3,13 @@ import { WebSocketsService } from './WebSocketsService';
3
3
import { NotificationSubscription , getConstWhitelist } from './web-sockets-helper' ;
4
4
import { Application , CurrentPage , CurrentPageSubKey } from './constants' ;
5
5
6
- export function useWebsocket ( application : Application , currentPage : CurrentPage , handleFunction : ( msgParts : string [ ] ) => void , projectId ?: string , subKey ?: CurrentPageSubKey ) {
6
+ export function useWebsocket ( userOrgId : string , application : Application , currentPage : CurrentPage , handleFunction : ( msgParts : string [ ] ) => void , projectId ?: string , subKey ?: CurrentPageSubKey ) {
7
7
8
8
const _projectId = useMemo ( ( ) => projectId || "GLOBAL" , [ projectId ] ) ;
9
9
const _subKey = useMemo ( ( ) => subKey || CurrentPageSubKey . NONE , [ subKey ] ) ;
10
10
const __whitelist = useMemo ( ( ) => getConstWhitelist ( application ) , [ application ] ) ;
11
-
12
11
useEffect ( ( ) => {
12
+ if ( ! userOrgId ) return ;
13
13
if ( ! __whitelist [ currentPage ] ) {
14
14
console . error ( `The combination of ${ currentPage } and ${ application } does not exist in the whitelist` ) ;
15
15
return ;
@@ -22,12 +22,13 @@ export function useWebsocket(application: Application, currentPage: CurrentPage,
22
22
23
23
WebSocketsService . subscribeToNotification ( currentPage , nos , _subKey ) ;
24
24
25
- return ( ) => WebSocketsService . unsubscribeFromNotification ( currentPage , projectId , _subKey ) ;
26
- } , [ _projectId , _subKey , application ] ) ;
25
+ return ( ) => { if ( userOrgId ) WebSocketsService . unsubscribeFromNotification ( currentPage , projectId , _subKey ) } ;
26
+ } , [ userOrgId , _projectId , _subKey , application ] ) ;
27
27
28
28
useEffect ( ( ) => {
29
+ if ( ! userOrgId ) return ;
29
30
WebSocketsService . updateFunctionPointer ( projectId , currentPage , handleFunction , subKey )
30
- } , [ handleFunction ] ) ;
31
+ } , [ userOrgId , handleFunction ] ) ;
31
32
32
33
33
34
}
0 commit comments