Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: Prevent connect to asterisk when VoIP is disabled #24601

Merged
merged 8 commits into from
Feb 25, 2022
6 changes: 6 additions & 0 deletions app/voip/server/startup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { settings } from '../../settings/server';
import { Voip } from '../../../server/sdk';

settings.watch('VoIP_Enabled', (value: boolean) => {
return value ? Voip.init() : Voip.stop();
});
1 change: 1 addition & 0 deletions server/importPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ import '../app/reactions/server';
import '../app/livechat/server';
import '../app/custom/server';
import '../app/authentication/server';
import '../app/voip/server/startup';
2 changes: 2 additions & 0 deletions server/sdk/types/IVoipService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export interface IVoipService {
checkManagementConnection(host: string, port: string, userName: string, password: string): Promise<IManagementServerConnectionStatus>;
checkCallserverConnection(websocketUrl: string, protocol?: string): Promise<IManagementServerConnectionStatus>;
cachedQueueDetails(): () => Promise<{ name: string; members: string[] }[]>;
init(): Promise<void>;
stop(): Promise<void>;
}
3 changes: 3 additions & 0 deletions server/services/voip/connector/asterisk/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,8 @@ export class CommandHandler {

stop(): void {
this.continuousMonitor.cleanMonitor();
for (const connection of this.connections.values()) {
connection.closeConnection();
}
}
}
18 changes: 13 additions & 5 deletions server/services/voip/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ export class VoipService extends ServiceClassInternal implements IVoipService {

this.logger = new Logger('VoIPService');
this.commandHandler = new CommandHandler(db);
try {
Promise.await(this.commandHandler.initConnection(CommandType.AMI));
} catch (error) {
this.logger.error({ msg: `Error while initialising the connector. error = ${error}` });
}
this.init();
}

async init(): Promise<void> {
this.logger.info('Starting VoIP service');
await this.commandHandler.initConnection(CommandType.AMI);
this.logger.info('VoIP service started');
}

async stop(): Promise<void> {
this.logger.info('Stopping VoIP service');
await this.commandHandler.stop();
this.logger.info('VoIP service stopped');
}

getServerConfigData(type: ServerType): IVoipCallServerConfig | IVoipManagementServerConfig {
Expand Down
1 change: 1 addition & 0 deletions tests/end-to-end/api/02-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ describe('[Channels]', function () {
});

describe('[/channels.files]', () => {
before(() => updateSetting('VoIP_Enabled', true));
const createVoipRoom = async () => {
const testUser = await createUser({ roles: ['user', 'livechat-agent'] });
const visitor = await createVisitor();
Expand Down