|
1 | 1 | import { api, FederationMatrix as FederationMatrixService } from '@rocket.chat/core-services'; |
2 | | -import { FederationMatrix, setupFederationMatrix } from '@rocket.chat/federation-matrix'; |
| 2 | +import { FederationMatrix, configureFederationMatrixSettings, setupFederationMatrix } from '@rocket.chat/federation-matrix'; |
3 | 3 | import { InstanceStatus } from '@rocket.chat/instance-status'; |
| 4 | +import { License } from '@rocket.chat/license'; |
4 | 5 | import { Logger } from '@rocket.chat/logger'; |
5 | 6 |
|
| 7 | +import { settings } from '../../../app/settings/server'; |
6 | 8 | import { StreamerCentral } from '../../../server/modules/streamer/streamer.module'; |
7 | 9 | import { registerFederationRoutes } from '../api/federation'; |
8 | 10 |
|
9 | 11 | const logger = new Logger('Federation'); |
10 | 12 |
|
11 | | -export const startFederationService = async (): Promise<void> => { |
| 13 | +let serviceEnabled = false; |
| 14 | + |
| 15 | +const configureFederation = async () => { |
| 16 | + // only registers the typing listener if the service is enabled |
| 17 | + serviceEnabled = (await License.hasModule('federation')) && settings.get('Federation_Service_Enabled'); |
| 18 | + if (!serviceEnabled) { |
| 19 | + return; |
| 20 | + } |
| 21 | + |
12 | 22 | try { |
13 | | - const isEnabled = await setupFederationMatrix(InstanceStatus.id()); |
| 23 | + configureFederationMatrixSettings({ |
| 24 | + instanceId: InstanceStatus.id(), |
| 25 | + domain: settings.get('Federation_Service_Domain'), |
| 26 | + signingKey: settings.get('Federation_Service_Matrix_Signing_Key'), |
| 27 | + signingAlgorithm: settings.get('Federation_Service_Matrix_Signing_Algorithm'), |
| 28 | + signingVersion: settings.get('Federation_Service_Matrix_Signing_Version'), |
| 29 | + allowedEncryptedRooms: settings.get('Federation_Service_Join_Encrypted_Rooms'), |
| 30 | + allowedNonPrivateRooms: settings.get('Federation_Service_Join_Non_Private_Rooms'), |
| 31 | + processEDUTyping: settings.get('Federation_Service_EDU_Process_Typing'), |
| 32 | + processEDUPresence: settings.get('Federation_Service_EDU_Process_Presence'), |
| 33 | + }); |
| 34 | + } catch (error) { |
| 35 | + logger.error('Failed to start federation-matrix service:', error); |
| 36 | + } |
| 37 | +}; |
14 | 38 |
|
15 | | - api.registerService(new FederationMatrix()); |
| 39 | +export const startFederationService = async (): Promise<void> => { |
| 40 | + api.registerService(new FederationMatrix()); |
16 | 41 |
|
17 | | - await registerFederationRoutes(); |
| 42 | + await registerFederationRoutes(); |
18 | 43 |
|
19 | | - // only registers the typing listener if the service is enabled |
20 | | - if (!isEnabled) { |
| 44 | + // TODO move to service/setup? |
| 45 | + StreamerCentral.on('broadcast', (name, eventName, args) => { |
| 46 | + if (!serviceEnabled) { |
21 | 47 | return; |
22 | 48 | } |
23 | 49 |
|
24 | | - // TODO move to service/setup? |
25 | | - StreamerCentral.on('broadcast', (name, eventName, args) => { |
26 | | - if (name === 'notify-room' && eventName.endsWith('user-activity')) { |
27 | | - const [rid] = eventName.split('/'); |
28 | | - const [user, activity] = args; |
29 | | - void FederationMatrixService.notifyUserTyping(rid, user, activity.includes('user-typing')); |
30 | | - } |
31 | | - }); |
32 | | - } catch (error) { |
33 | | - logger.error('Failed to start federation-matrix service:', error); |
34 | | - } |
| 50 | + if (name === 'notify-room' && eventName.endsWith('user-activity')) { |
| 51 | + const [rid] = eventName.split('/'); |
| 52 | + const [user, activity] = args; |
| 53 | + void FederationMatrixService.notifyUserTyping(rid, user, activity.includes('user-typing')); |
| 54 | + } |
| 55 | + }); |
| 56 | + |
| 57 | + await setupFederationMatrix(); |
| 58 | + |
| 59 | + settings.watchMultiple( |
| 60 | + [ |
| 61 | + 'Federation_Service_Enabled', |
| 62 | + 'Federation_Service_Domain', |
| 63 | + 'Federation_Service_EDU_Process_Typing', |
| 64 | + 'Federation_Service_EDU_Process_Presence', |
| 65 | + 'Federation_Service_Matrix_Signing_Key', |
| 66 | + 'Federation_Service_Matrix_Signing_Algorithm', |
| 67 | + 'Federation_Service_Matrix_Signing_Version', |
| 68 | + 'Federation_Service_Join_Encrypted_Rooms', |
| 69 | + 'Federation_Service_Join_Non_Private_Rooms', |
| 70 | + ], |
| 71 | + async () => { |
| 72 | + await configureFederation(); |
| 73 | + }, |
| 74 | + ); |
35 | 75 | }; |
0 commit comments