(token)
| 13 | let socketIoClient; |
| 14 | |
| 15 | export 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 | }, |
no test coverage detected