Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 58 additions & 18 deletions apps/meteor/ee/server/startup/federation.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,75 @@
import { api, FederationMatrix as FederationMatrixService } from '@rocket.chat/core-services';
import { FederationMatrix, setupFederationMatrix } from '@rocket.chat/federation-matrix';
import { FederationMatrix, configureFederationMatrixSettings, setupFederationMatrix } from '@rocket.chat/federation-matrix';
import { InstanceStatus } from '@rocket.chat/instance-status';
import { License } from '@rocket.chat/license';
import { Logger } from '@rocket.chat/logger';

import { settings } from '../../../app/settings/server';
import { StreamerCentral } from '../../../server/modules/streamer/streamer.module';
import { registerFederationRoutes } from '../api/federation';

const logger = new Logger('Federation');

export const startFederationService = async (): Promise<void> => {
let serviceEnabled = false;

const configureFederation = async () => {
// only registers the typing listener if the service is enabled
serviceEnabled = (await License.hasModule('federation')) && settings.get('Federation_Service_Enabled');
if (!serviceEnabled) {
return;
}

try {
const isEnabled = await setupFederationMatrix(InstanceStatus.id());
configureFederationMatrixSettings({
instanceId: InstanceStatus.id(),
domain: settings.get('Federation_Service_Domain'),
signingKey: settings.get('Federation_Service_Matrix_Signing_Key'),
signingAlgorithm: settings.get('Federation_Service_Matrix_Signing_Algorithm'),
signingVersion: settings.get('Federation_Service_Matrix_Signing_Version'),
allowedEncryptedRooms: settings.get('Federation_Service_Join_Encrypted_Rooms'),
allowedNonPrivateRooms: settings.get('Federation_Service_Join_Non_Private_Rooms'),
processEDUTyping: settings.get('Federation_Service_EDU_Process_Typing'),
processEDUPresence: settings.get('Federation_Service_EDU_Process_Presence'),
});
} catch (error) {
logger.error('Failed to start federation-matrix service:', error);
}
};

api.registerService(new FederationMatrix());
export const startFederationService = async (): Promise<void> => {
api.registerService(new FederationMatrix());

await registerFederationRoutes();
await registerFederationRoutes();

// only registers the typing listener if the service is enabled
if (!isEnabled) {
// TODO move to service/setup?
StreamerCentral.on('broadcast', (name, eventName, args) => {
if (!serviceEnabled) {
return;
}

// TODO move to service/setup?
StreamerCentral.on('broadcast', (name, eventName, args) => {
if (name === 'notify-room' && eventName.endsWith('user-activity')) {
const [rid] = eventName.split('/');
const [user, activity] = args;
void FederationMatrixService.notifyUserTyping(rid, user, activity.includes('user-typing'));
}
});
} catch (error) {
logger.error('Failed to start federation-matrix service:', error);
}
if (name === 'notify-room' && eventName.endsWith('user-activity')) {
const [rid] = eventName.split('/');
const [user, activity] = args;
void FederationMatrixService.notifyUserTyping(rid, user, activity.includes('user-typing'));
}
});

await setupFederationMatrix();

settings.watchMultiple(
[
'Federation_Service_Enabled',
'Federation_Service_Domain',
'Federation_Service_EDU_Process_Typing',
'Federation_Service_EDU_Process_Presence',
'Federation_Service_Matrix_Signing_Key',
'Federation_Service_Matrix_Signing_Algorithm',
'Federation_Service_Matrix_Signing_Version',
'Federation_Service_Join_Encrypted_Rooms',
'Federation_Service_Join_Non_Private_Rooms',
],
async () => {
await configureFederation();
},
);
};
2 changes: 1 addition & 1 deletion apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
"@rocket.chat/emitter": "~0.31.25",
"@rocket.chat/favicon": "workspace:^",
"@rocket.chat/federation-matrix": "workspace:^",
"@rocket.chat/federation-sdk": "0.2.0",
"@rocket.chat/federation-sdk": "0.3.0",
"@rocket.chat/freeswitch": "workspace:^",
"@rocket.chat/fuselage": "~0.66.4",
"@rocket.chat/fuselage-forms": "~0.1.0",
Expand Down
4 changes: 2 additions & 2 deletions ee/packages/federation-matrix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@rocket.chat/core-services": "workspace:^",
"@rocket.chat/core-typings": "workspace:^",
"@rocket.chat/emitter": "^0.31.25",
"@rocket.chat/federation-sdk": "0.2.0",
"@rocket.chat/federation-sdk": "0.3.0",
"@rocket.chat/http-router": "workspace:^",
"@rocket.chat/license": "workspace:^",
"@rocket.chat/models": "workspace:^",
Expand All @@ -47,7 +47,7 @@
"emojione": "^4.5.0",
"marked": "^16.1.2",
"mongodb": "6.16.0",
"pino": "^9.11.0",
"pino": "^8.21.0",
"reflect-metadata": "^0.2.2",
"sanitize-html": "~2.17.0",
"tsyringe": "^4.10.0",
Expand Down
Loading
Loading