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
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();
}
}
}
25 changes: 20 additions & 5 deletions server/services/voip/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { IQueueMembershipDetails, IRegistrationInfo, isIExtensionDetails } from
import { IQueueDetails, IQueueSummary } from '../../../definition/ACDQueues';
import { getServerConfigDataFromSettings } from './lib/Helper';
import { IManagementServerConnectionStatus } from '../../../definition/IVoipServerConnectivityStatus';
import { settings } from '../../../app/settings/server';

export class VoipService extends ServiceClassInternal implements IVoipService {
protected name = 'voip';
Expand All @@ -31,11 +32,25 @@ 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();
}

private async init(): Promise<void> {
settings.watch('VoIP_Enabled', (value) => {
try {
if (value) {
this.logger.info('Starting VoIP service');
Promise.await(this.commandHandler.initConnection(CommandType.AMI));
murtaza98 marked this conversation as resolved.
Show resolved Hide resolved
murtaza98 marked this conversation as resolved.
Show resolved Hide resolved
this.logger.info('VoIP service started');
} else {
this.logger.info('Stopping VoIP service');
Promise.await(this.commandHandler.stop());
this.logger.info('VoIP service stopped');
}
} catch (error) {
this.logger.error({ msg: `Error while ${value ? 'initializing' : 'destroying'} the connector.`, err: error });
}
});
}

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