Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $ npm install

### Using it

See https://github.com/salesforce/demo-scv-connector
See https://github.com/salesforce-misc/byo-demo-connector

## Testing
Lint all the source code and run all the unit tests:
Expand Down
2 changes: 1 addition & 1 deletion dist/scv-connector-base.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/scv-connector-base.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@salesforce/scv-connector-base",
"version": "4.4.5",
"version": "4.6.8",
"description": "Salesforce Service Cloud Connector Base",
"main": "dist/scv-connector-base.js",
"private": false,
Expand Down
47 changes: 38 additions & 9 deletions src/main/baseConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import constants from './constants.js';
import { CONNECTOR_CONFIG_EXPOSED_FIELDS, CONNECTOR_CONFIG_EXPOSED_FIELDS_STARTSWITH, CONNECTOR_CONFIG_EXCEPTION_FIELDS } from './constants.js';
import { Validator, GenericResult, InitResult, CallResult, HangupResult, HoldToggleResult, ContactsResult, PhoneContactsResult, MuteToggleResult,
ParticipantResult, RecordingToggleResult, AgentConfigResult, ActiveCallsResult, SignedRecordingUrlResult, LogoutResult,
VendorConnector, Contact, AudioStats, SuperviseCallResult, SupervisorHangupResult, AgentStatusInfo, SupervisedCallInfo,
VendorConnector, Contact, AudioStats, SuperviseCallResult, SupervisorHangupResult, AgentStatusInfo, SupervisedCallInfo,
SharedCapabilitiesResult, VoiceCapabilitiesResult, AgentVendorStatusInfo, StateChangeResult, CustomError, DialOptions, ShowStorageAccessResult,
AudioDevicesResult, ACWInfo } from './types';
AudioDevicesResult, ACWInfo, SetAgentConfigResult } from './types';
import { enableMos, getMOS, initAudioStats, updateAudioStats } from './mosUtil';
import { log, getLogs } from './logger';

Expand Down Expand Up @@ -185,7 +185,11 @@ async function setConnectorReady() {
[constants.VOICE_CAPABILITIES_TYPE.HAS_GET_EXTERNAL_SPEAKER] : voiceCapabilitiesResult.hasGetExternalSpeakerDeviceSetting,
[constants.VOICE_CAPABILITIES_TYPE.HAS_SET_EXTERNAL_SPEAKER] : voiceCapabilitiesResult.hasSetExternalSpeakerDeviceSetting,
[constants.VOICE_CAPABILITIES_TYPE.HAS_GET_EXTERNAL_MICROPHONE] : voiceCapabilitiesResult.hasGetExternalMicrophoneDeviceSetting,
[constants.VOICE_CAPABILITIES_TYPE.HAS_SET_EXTERNAL_MICROPHONE] : voiceCapabilitiesResult.hasSetExternalMicrophoneDeviceSetting
[constants.VOICE_CAPABILITIES_TYPE.HAS_SET_EXTERNAL_MICROPHONE] : voiceCapabilitiesResult.hasSetExternalMicrophoneDeviceSetting,
[constants.VOICE_CAPABILITIES_TYPE.CAN_CONSULT]: voiceCapabilitiesResult.canConsult,
[constants.VOICE_CAPABILITIES_TYPE.DIAL_PAD]: voiceCapabilitiesResult.isDialPadDisabled,
[constants.VOICE_CAPABILITIES_TYPE.HAS_HID_SUPPORT]: voiceCapabilitiesResult.isHidSupported,
[constants.VOICE_CAPABILITIES_TYPE.PHONEBOOK_DISABLE]: voiceCapabilitiesResult.isPhoneBookDisabled
},
callInProgress: activeCalls.length > 0 ? activeCalls[0] : null
}
Expand Down Expand Up @@ -281,7 +285,7 @@ async function channelMessageHandler(message) {
case constants.VOICE_MESSAGE_TYPE.MUTE:
try {
const telephonyConnector = await vendorConnector.getTelephonyConnector();
const payload = await telephonyConnector.mute();
const payload = await telephonyConnector.mute(message.data.call);
publishEvent({eventType: constants.VOICE_EVENT_TYPE.MUTE_TOGGLE, payload});
} catch (e) {
if (e instanceof CustomError) {
Expand All @@ -294,7 +298,7 @@ async function channelMessageHandler(message) {
case constants.VOICE_MESSAGE_TYPE.UNMUTE:
try {
const telephonyConnector = await vendorConnector.getTelephonyConnector();
const payload = await telephonyConnector.unmute();
const payload = await telephonyConnector.unmute(message.data.call);
publishEvent({eventType: constants.VOICE_EVENT_TYPE.MUTE_TOGGLE, payload});
} catch (e) {
if (e instanceof CustomError) {
Expand Down Expand Up @@ -623,6 +627,7 @@ async function channelMessageHandler(message) {
case constants.CALL_STATE.TRANSFERRING:
dispatchEvent(constants.VOICE_EVENT_TYPE.PARTICIPANT_ADDED, {
phoneNumber: call.contact.phoneNumber,
contact:call.contact,
callInfo: call.callInfo,
initialCallHasEnded: call.callAttributes.initialCallHasEnded,
callId: call.callId
Expand All @@ -631,6 +636,7 @@ async function channelMessageHandler(message) {
case constants.CALL_STATE.TRANSFERRED:
dispatchEvent(constants.VOICE_EVENT_TYPE.PARTICIPANT_CONNECTED, {
phoneNumber: call.contact.phoneNumber,
contact:call.contact,
callInfo: call.callInfo,
initialCallHasEnded: call.callAttributes.initialCallHasEnded,
callId: call.callId
Expand All @@ -648,7 +654,10 @@ async function channelMessageHandler(message) {
try {
const telephonyConnector = await vendorConnector.getTelephonyConnector();
const result = await telephonyConnector.setAgentConfig(message.data.config);
Validator.validateClassObject(result, GenericResult);
Validator.validateClassObjects(result, GenericResult, SetAgentConfigResult);
if (result instanceof SetAgentConfigResult) {
result.setIsSystemEvent(!!message.data.config.isSystemEvent);
}
dispatchEvent(constants.VOICE_EVENT_TYPE.AGENT_CONFIG_UPDATED, result);
} catch (e) {
if (e instanceof CustomError) {
Expand Down Expand Up @@ -933,6 +942,9 @@ export function publishError({ eventType, error }) {
dispatchError(constants.SHARED_ERROR_TYPE.GENERIC_ERROR, error, constants.VOICE_EVENT_TYPE.SOFTPHONE_ERROR);
}
break;
case constants.VOICE_EVENT_TYPE.CALL_UPDATED:
dispatchError(constants.VOICE_ERROR_TYPE.CAN_NOT_UPDATE_CALL, error, constants.VOICE_EVENT_TYPE.CALL_UPDATED);
break;
default:
console.error('Unhandled error scenario with arguments ', arguments);
}
Expand All @@ -958,6 +970,7 @@ export function publishError({ eventType, error }) {
* MUTE_TOGGLE - MuteToggleResult
* HOLD_TOGGLE - HoldToggleResult
* RECORDING_TOGGLE - RecordingToggleResult
* AUDIO_STATS - AudioStats
*/
export async function publishEvent({ eventType, payload, registerLog = true }) {
switch(eventType) {
Expand Down Expand Up @@ -1023,12 +1036,13 @@ export async function publishEvent({ eventType, payload, registerLog = true }) {
}
case constants.VOICE_EVENT_TYPE.PARTICIPANT_CONNECTED: {
if (validatePayload(payload, ParticipantResult, constants.VOICE_ERROR_TYPE.CAN_NOT_CONNECT_PARTICIPANT, constants.VOICE_EVENT_TYPE.PARTICIPANT_CONNECTED)) {
const { initialCallHasEnded, callInfo, phoneNumber, callId } = payload;
const { initialCallHasEnded, callInfo, phoneNumber, callId, contact } = payload;
dispatchEvent(constants.VOICE_EVENT_TYPE.PARTICIPANT_CONNECTED, {
initialCallHasEnded,
callInfo,
phoneNumber,
callId
callId,
contact
}, true /* ignoring registerLog for critical event*/);
}
break;
Expand All @@ -1055,7 +1069,7 @@ export async function publishEvent({ eventType, payload, registerLog = true }) {
}, true /* ignoring registerLog for critical event*/)
} else {
dispatchEvent(constants.VOICE_EVENT_TYPE.PARTICIPANT_REMOVED, {
reason: call? call.reason : null
callId: call? call.callId : null, reason: call? call.reason : null
}, true /* ignoring registerLog for critical event*/);
}
}
Expand Down Expand Up @@ -1131,10 +1145,25 @@ export async function publishEvent({ eventType, payload, registerLog = true }) {
}
break;
}

case constants.VOICE_EVENT_TYPE.CALL_UPDATED: {
if (validatePayload(payload, CallResult, constants.VOICE_ERROR_TYPE.CAN_NOT_UPDATE_CALL, constants.VOICE_EVENT_TYPE.CALL_UPDATED)) {
dispatchEvent(constants.VOICE_EVENT_TYPE.CALL_UPDATED, payload, registerLog);
}
break;
}

case constants.VOICE_EVENT_TYPE.UPDATE_AUDIO_STATS: {
if (validatePayload(payload, AudioStats)) {
if (payload.stats) {
updateAudioStats(payload.stats);
let audioStats;
if (payload.callId) {
audioStats = {stats: payload.stats, callId: payload.callId};
} else {
audioStats = {stats: payload.stats}
}
dispatchEvent(constants.VOICE_EVENT_TYPE.AUDIO_STATS, {audioStats}, registerLog);
}
if (payload.isAudioStatsCompleted && payload.callId) {
const callId = payload.callId;
Expand Down
13 changes: 10 additions & 3 deletions src/main/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export default {
HANGUP: 'HANGUP',
SOFTPHONE_ERROR: 'SOFTPHONE_ERROR',
SHOW_TRANSFER_VIEW: 'SHOW_TRANSFER_VIEW',
GET_AUDIO_DEVICES: 'GET_AUDIO_DEVICES'
GET_AUDIO_DEVICES: 'GET_AUDIO_DEVICES',
AUDIO_STATS: 'AUDIO_STATS',
CALL_UPDATED: 'CALL_UPDATED' //sent during a call to update call controls
},
INFO_TYPE: {
CAN_NOT_ACCEPT_THE_CALL: 'CAN_NOT_ACCEPT_THE_CALL'
Expand Down Expand Up @@ -149,7 +151,8 @@ export default {
AGENT_ERROR: 'AGENT_ERROR',
MICROPHONE_NOT_SHARED: 'MICROPHONE_NOT_SHARED',
UNSUPPORTED_BROWSER: 'UNSUPPORTED_BROWSER',
CAN_NOT_GET_AUDIO_DEVICES: 'CAN_NOT_GET_AUDIO_DEVICES'
CAN_NOT_GET_AUDIO_DEVICES: 'CAN_NOT_GET_AUDIO_DEVICES',
CAN_NOT_UPDATE_CALL: 'CAN_NOT_UPDATE_CALL'
},
AGENT_STATUS: {
ONLINE: 'Online',
Expand Down Expand Up @@ -215,7 +218,11 @@ export default {
HAS_GET_EXTERNAL_SPEAKER: 'HAS_GET_EXTERNAL_SPEAKER',
HAS_SET_EXTERNAL_SPEAKER: 'HAS_SET_EXTERNAL_SPEAKER',
HAS_GET_EXTERNAL_MICROPHONE: 'HAS_GET_EXTERNAL_MICROPHONE',
HAS_SET_EXTERNAL_MICROPHONE: 'HAS_SET_EXTERNAL_MICROPHONE'
HAS_SET_EXTERNAL_MICROPHONE: 'HAS_SET_EXTERNAL_MICROPHONE',
CAN_CONSULT: 'CAN_CONSULT',
DIAL_PAD: 'DIAL_PAD',
HAS_HID_SUPPORT: 'HAS_HID_SUPPORT',
PHONEBOOK_DISABLE: 'PHONEBOOK_DISABLE'
},
CALL_STATE: {
RINGING: 'ringing',
Expand Down
3 changes: 2 additions & 1 deletion src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ export {
DialOptions,
ContactsFilter,
AudioDevicesResult,
ACWInfo
ACWInfo,
SetAgentConfigResult
} from './types.js';
Loading