Skip to content

Commit

Permalink
chore: Stop injecting settings' getter on FreeSwitch service (#34201)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman authored Dec 17, 2024
1 parent 7edc3db commit 0fcdc3e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
16 changes: 9 additions & 7 deletions apps/meteor/ee/server/local-services/voip-freeswitch/service.ts
Original file line number Diff line number Diff line change
@@ -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: <T extends SettingValue = SettingValue>(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<string>('VoIP_TeamCollab_FreeSwitch_Host');
const host = process.env.FREESWITCHIP || settings.get<string>('VoIP_TeamCollab_FreeSwitch_Host');
if (!host) {
throw new Error('VoIP is not properly configured.');
}

const port = this.getSetting<number>('VoIP_TeamCollab_FreeSwitch_Port') || 8021;
const timeout = this.getSetting<number>('VoIP_TeamCollab_FreeSwitch_Timeout') || 3000;
const password = this.getSetting<string>('VoIP_TeamCollab_FreeSwitch_Password');
const port = settings.get<number>('VoIP_TeamCollab_FreeSwitch_Port') || 8021;
const timeout = settings.get<number>('VoIP_TeamCollab_FreeSwitch_Timeout') || 3000;
const password = settings.get<string>('VoIP_TeamCollab_FreeSwitch_Password');

return {
host,
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/ee/server/startup/services.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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()) {
Expand Down
10 changes: 6 additions & 4 deletions apps/meteor/tests/unit/server/lib/freeswitch.tests.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down

0 comments on commit 0fcdc3e

Please sign in to comment.