diff --git a/apps/meteor/ee/server/local-services/voip-freeswitch/service.ts b/apps/meteor/ee/server/local-services/voip-freeswitch/service.ts index 8bc0f7c9b4fe..2eccecc96a00 100644 --- a/apps/meteor/ee/server/local-services/voip-freeswitch/service.ts +++ b/apps/meteor/ee/server/local-services/voip-freeswitch/service.ts @@ -1,27 +1,29 @@ import { type IVoipFreeSwitchService, ServiceClassInternal } from '@rocket.chat/core-services'; -import type { FreeSwitchExtension, ISetting, SettingValue } from '@rocket.chat/core-typings'; +import type { FreeSwitchExtension } from '@rocket.chat/core-typings'; import { getDomain, getUserPassword, getExtensionList, getExtensionDetails } from '@rocket.chat/freeswitch'; +import { settings } from '../../../../app/settings/server'; + export class VoipFreeSwitchService extends ServiceClassInternal implements IVoipFreeSwitchService { protected name = 'voip-freeswitch'; - constructor(private getSetting: (id: ISetting['_id']) => T) { + constructor() { super(); } private getConnectionSettings(): { host: string; port: number; password: string; timeout: number } { - if (!this.getSetting('VoIP_TeamCollab_Enabled') && !process.env.FREESWITCHIP) { + if (!settings.get('VoIP_TeamCollab_Enabled') && !process.env.FREESWITCHIP) { throw new Error('VoIP is disabled.'); } - const host = process.env.FREESWITCHIP || this.getSetting('VoIP_TeamCollab_FreeSwitch_Host'); + const host = process.env.FREESWITCHIP || settings.get('VoIP_TeamCollab_FreeSwitch_Host'); if (!host) { throw new Error('VoIP is not properly configured.'); } - const port = this.getSetting('VoIP_TeamCollab_FreeSwitch_Port') || 8021; - const timeout = this.getSetting('VoIP_TeamCollab_FreeSwitch_Timeout') || 3000; - const password = this.getSetting('VoIP_TeamCollab_FreeSwitch_Password'); + const port = settings.get('VoIP_TeamCollab_FreeSwitch_Port') || 8021; + const timeout = settings.get('VoIP_TeamCollab_FreeSwitch_Timeout') || 3000; + const password = settings.get('VoIP_TeamCollab_FreeSwitch_Password'); return { host, diff --git a/apps/meteor/ee/server/startup/services.ts b/apps/meteor/ee/server/startup/services.ts index c7cd0491bda9..efaf1ab8be68 100644 --- a/apps/meteor/ee/server/startup/services.ts +++ b/apps/meteor/ee/server/startup/services.ts @@ -1,7 +1,6 @@ import { api } from '@rocket.chat/core-services'; import { License } from '@rocket.chat/license'; -import { settings } from '../../../app/settings/server/cached'; import { isRunningMs } from '../../../server/lib/isRunningMs'; import { FederationService } from '../../../server/services/federation/service'; import { LicenseService } from '../../app/license/server/license.internalService'; @@ -19,7 +18,7 @@ api.registerService(new LDAPEEService()); api.registerService(new LicenseService()); api.registerService(new MessageReadsService()); api.registerService(new OmnichannelEE()); -api.registerService(new VoipFreeSwitchService((id) => settings.get(id))); +api.registerService(new VoipFreeSwitchService()); // when not running micro services we want to start up the instance intercom if (!isRunningMs()) { diff --git a/apps/meteor/tests/unit/server/lib/freeswitch.tests.ts b/apps/meteor/tests/unit/server/lib/freeswitch.tests.ts index bb020995c7f8..c78568dcee7b 100644 --- a/apps/meteor/tests/unit/server/lib/freeswitch.tests.ts +++ b/apps/meteor/tests/unit/server/lib/freeswitch.tests.ts @@ -1,11 +1,13 @@ import { expect } from 'chai'; import { describe } from 'mocha'; +import proxyquire from 'proxyquire'; +import sinon from 'sinon'; -import { settings } from '../../../../app/settings/server/cached'; -import { VoipFreeSwitchService } from '../../../../ee/server/local-services/voip-freeswitch/service'; - -const VoipFreeSwitch = new VoipFreeSwitchService((id) => settings.get(id)); +const { VoipFreeSwitchService } = proxyquire.noCallThru().load('../../../../ee/server/local-services/voip-freeswitch/service', { + '../../../../app/settings/server': { get: sinon.stub() }, +}); +const VoipFreeSwitch = new VoipFreeSwitchService(); // Those tests still need a proper freeswitch environment configured in order to run // So for now they are being deliberately skipped on CI describe.skip('VoIP', () => {