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: Refresh server connection when MI server settings change #24649

Merged
merged 1 commit into from
Feb 28, 2022
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
4 changes: 2 additions & 2 deletions app/lib/server/startup/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3160,7 +3160,7 @@ settingsRegistry.addGroup('Call_Center', function () {
});
this.section('Server_Configuration', function () {
this.add('VoIP_Server_Host', '', {
type: 'password',
type: 'string',
public: true,
enableQuery: {
_id: 'VoIP_Enabled',
Expand All @@ -3176,7 +3176,7 @@ settingsRegistry.addGroup('Call_Center', function () {
},
});
this.add('VoIP_Server_Name', '', {
type: 'int',
type: 'string',
public: true,
enableQuery: {
_id: 'VoIP_Enabled',
Expand Down
13 changes: 13 additions & 0 deletions app/voip/server/startup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import debounce from 'lodash.debounce';

import { settings } from '../../settings/server';
import { Voip } from '../../../server/sdk';

const debouncedRefresh = debounce(Voip.refresh, 1000);

settings.watch('VoIP_Enabled', (value: boolean) => {
return value ? Voip.init() : Voip.stop();
});

settings.changeMultiple(
['VoIP_Management_Server_Host', 'VoIP_Management_Server_Port', 'VoIP_Management_Server_Username', 'VoIP_Management_Server_Password'],
(_values) => {
// Here, if 4 settings are changed at once, we're getting 4 diff callbacks. The good part is that all callbacks are fired almost instantly
// So to avoid stopping/starting voip too often, we debounce the call and restart 1 second after the last setting has reached us.
return debouncedRefresh();
},
);
1 change: 1 addition & 0 deletions server/sdk/types/IVoipService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface IVoipService {
cachedQueueDetails(): () => Promise<{ name: string; members: string[] }[]>;
init(): Promise<void>;
stop(): Promise<void>;
refresh(): Promise<void>;
}
5 changes: 5 additions & 0 deletions server/services/voip/connector/asterisk/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ export class CommandHandler {
}

stop(): void {
if (!this.continuousMonitor) {
// service is already stopped or was never initialized
return;
}

this.continuousMonitor.cleanMonitor();
for (const connection of this.connections.values()) {
connection.closeConnection();
Expand Down
10 changes: 8 additions & 2 deletions server/services/voip/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class VoipService extends ServiceClassInternal implements IVoipService {
await this.commandHandler.initConnection(CommandType.AMI);
this.logger.info('VoIP service started');
} catch (err) {
this.logger.error('Error initializing VOIP service', err);
this.logger.error({ msg: 'Error initializing VOIP service', err });
}
}

Expand All @@ -61,10 +61,16 @@ export class VoipService extends ServiceClassInternal implements IVoipService {
this.commandHandler.stop();
this.logger.info('VoIP service stopped');
} catch (err) {
this.logger.error('Error stopping VoIP service', err);
this.logger.error({ msg: 'Error stopping VoIP service', err });
}
}

async refresh(): Promise<void> {
this.logger.info('Restarting VoIP service due to settings changes');
await this.stop();
await this.init();
}

getServerConfigData(type: ServerType): IVoipCallServerConfig | IVoipManagementServerConfig {
return getServerConfigDataFromSettings(type);
}
Expand Down