MCPcopy
hub / github.com/linuxfoundation/crowd.dev / connectSocket

Function connectSocket

frontend/src/modules/auth/auth-socket.js:15–119  ·  view source on GitHub ↗
(token)

Source from the content-addressed store, hash-verified

13let socketIoClient;
14
15export const connectSocket = (token) => {
16 if (socketIoClient && socketIoClient.connected) {
17 socketIoClient.disconnect();
18 }
19 const currentTenant = computed(
20 () => store.getters['auth/currentTenant'],
21 );
22 const currentUser = computed(
23 () => store.getters['auth/currentUser'],
24 );
25
26 const path = config.env === 'production' || config.env === 'staging'
27 ? '/api/socket.io'
28 : '/socket.io';
29
30 socketIoClient = io(`${config.websocketsUrl}/user`, {
31 path,
32 query: {
33 token,
34 },
35 transports: ['websocket'],
36 forceNew: true,
37 });
38
39 socketIoClient.on('connect', () => {
40 console.info('Socket connected');
41 });
42
43 socketIoClient.on('disconnect', () => {
44 console.info('Socket disconnected');
45 });
46
47 socketIoClient.on('integration-completed', (data) => {
48 console.info('Integration onboarding done', data);
49 store.dispatch(
50 'integration/doFind',
51 JSON.parse(data).integrationId,
52 );
53 });
54
55 socketIoClient.on(
56 'tenant-plan-upgraded',
57 async (data) => {
58 console.info(
59 'Tenant plan is upgraded. Force a hard refresh!',
60 data,
61 );
62 let parsed = data;
63 if (typeof data === 'string') {
64 parsed = JSON.parse(data);
65 }
66
67 await store.dispatch('auth/doRefreshCurrentUser');
68
69 Message.success(
70 `Successfully upgraded to ${parsed.plan} plan`,
71 );
72 },

Callers 2

doInitFunction · 0.90

Calls 10

getEnrichmentMaxFunction · 0.90
onMethod · 0.80
infoMethod · 0.80
closeAllMethod · 0.80
fetchMembersFunction · 0.50
parseMethod · 0.45
successMethod · 0.45
findMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected