Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-lehnen-rc committed Feb 28, 2022
2 parents 3357a92 + d50e3ec commit 5ec0fa9
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
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();
},
);
4 changes: 4 additions & 0 deletions client/lib/voip/VoIPUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,4 +652,8 @@ export class VoIPUser extends Emitter<VoipEvents> implements OutgoingRequestDele
getAggregator(): QueueAggregator | undefined {
return this.queueInfo;
}

getRegistrarState(): string | undefined {
return this.registerer?.state.toString().toLocaleLowerCase();
}
}
19 changes: 13 additions & 6 deletions client/sidebar/sections/components/OmnichannelCallToggleReady.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export const OmnichannelCallToggleReady = (): ReactElement => {
} as const;
const voipClient = useCallClient();

useEffect(() => {
let agentEnabled = false;
const state = voipClient.getRegistrarState();
if (state === 'registered') {
agentEnabled = true;
}
setAgentEnabled(agentEnabled);
setRegistered(agentEnabled);
}, [voipClient]);
// TODO: move registration flow to context provider
const handleVoipCallStatusChange = useMutableCallback((): void => {
// TODO: backend set voip call status
Expand All @@ -31,23 +40,21 @@ export const OmnichannelCallToggleReady = (): ReactElement => {
});

const onUnregistrationError = useMutableCallback((): void => {
voipClient.off('unregistrationerror', onUnregistrationError);
setRegistered(false);
setAgentEnabled(false);
});

const onUnregistered = useMutableCallback((): void => {
setRegistered(!registered);
voipClient.off('unregistered', onUnregistered);
voipClient.off('registrationerror', onUnregistrationError);
});

const onRegistrationError = useMutableCallback((): void => {
voipClient.off('registrationerror', onRegistrationError);
setRegistered(false);
setAgentEnabled(false);
});

const onRegistered = useMutableCallback((): void => {
setRegistered(!registered);
voipClient.off('registered', onRegistered);
voipClient.off('registrationerror', onRegistrationError);
});

useEffect(() => {
Expand Down
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

0 comments on commit 5ec0fa9

Please sign in to comment.