-
Notifications
You must be signed in to change notification settings - Fork 2
PhoneCall
extends Call
Returns the options this call was started with.
none
-
PhoneCallOptions- Options that this call was started with.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let phoneCall = infobipRTC.callPhone('41793026727', PhoneCallOptions.builder()
.setAutoReconnect(true) // Required in order to receive RECONNECTING and RECONNECTED events
.setFrom('33712345678')
.build());
console.log(`Call options: ${JSON.stringify(phoneCall.options())}`);Configures the event handler for phone call events.
-
eventName:CallsApiEvent- Name of the application call event. Allowed values are a subset ofCallsApiEvent. -
eventHandler:CallsEventHandlers- Function that will be called when specified event occurs, with exactly one parameter being passed to the function containing event information. Depending on the event, the passed parameter will contain a set of fields that will describe the event, namely:-
RINGING- No additional data is provided in the event object.event = {}
-
EARLY_MEDIA- AMediaStreamobject representing the media being played is received in the event object.event = { stream: MediaStream }
-
ESTABLISHED- AMediaStreamobject representing the media in the call is received in the event object.event = { stream: MediaStream }
-
HANGUP- A receivedErrorCodeobject provides details about the reason for the call hang-up, along with aTotalMediaStatsobject that offers a comprehensive summary of the call's audio statistics.event = { errorCode: ErrorCode, totalMediaStats: TotalMediaStats }
-
ERROR- A receivedErrorCodeobject provides details about the reason for the error occurrence.event = { errorCode: ErrorCode }
-
NETWORK_QUALITY_CHANGED- An event containing a NetworkQuality and a CurrentMediaStats objects that provides details on the network quality of a local participant and its corresponding media stats.event = { networkQuality: NetworkQuality, currentMediaStats: CurrentMediaStats }
-
CALL_RECORDING_STARTED- An event that is triggered once a call recording starts. It includes RecordingType enum value which corresponds to the type of recording initiated.event = { recordingType: RecordingType }
-
RECONNECTING- No additional data is provided in the event object.event = {}
-
RECONNECTED- No additional data is provided in the event object.event = {}
-
TALKING_WHILE_MUTED- No additional data is provided in the event object.event = {}
-
MACHINE_DETECTION_FINISHED- An event containing the detection result andConfidenceRating.event = { detectionResult: string, confidenceRating: ConfidenceRating }
-
MACHINE_DETECTION_FAILED- An event containing the reason for the failure.event = { reason: string }
-
N/A
Let's assume you have an audio HTML element with the id callAudio.
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let machineDetectionOptions = MachineDetectionOptions.builder().setEnabled(true).build();
let phoneCall = infobipRTC.callPhone('41793026727', PhoneCallOptions.builder()
.setAutoReconnect(true) // Required in order to receive RECONNECTING and RECONNECTED events
.setFrom('33712345678')
.setMachineDetectionOptions(machineDetectionOptions)
.build());
phoneCall.on(CallsApiEvent.RINGING, () => {
console.log('Ringing...');
});
phoneCall.on(CallsApiEvent.EARLY_MEDIA, (event) => {
console.log('Ringtone playing...');
$('#callAudio').srcObject = event.stream;
});
phoneCall.on(CallsApiEvent.ESTABLISHED, (event) => {
$('#callAudio').srcObject = event.stream;
});
phoneCall.on(CallsApiEvent.HANGUP, (event) => {
console.log(`Call finished. Status: ${event.errorCode.name}`);
});
phoneCall.on(CallsApiEvent.ERROR, (event) => {
console.log(`An error has occurred. Error: ${event.errorCode.name}`);
});
phoneCall.on(CallsApiEvent.NETWORK_QUALITY_CHANGED, (event) => {
console.log(`Local network quality is: ${NetworkQuality[event.networkQuality]}`);
});
phoneCall.on(CallsApiEvent.CALL_RECORDING_STARTED, (event) => {
console.log(`Call recording started with type ${event.recordingType}`);
});
phoneCall.on(CallsApiEvent.RECONNECTING, (event) => {
console.log('Call is being reconnected, hang tight!');
});
phoneCall.on(CallsApiEvent.RECONNECTED, (event) => {
console.log('You have successfully reconnected the call!');
});
phoneCall.on(CallsApiEvent.TALKING_WHILE_MUTED, (event) => {
console.log('You are talking while muted. Do you want to unmute?');
});
phoneCall.on(CallsApiEvent.MACHINE_DETECTION_FINISHED, (event) => {
console.log(`Machine detection finished. Result: ${event.detectionResult}`);
console.log(`Confidence ratings: ${JSON.stringify(event.confidenceRating)}`);
});
phoneCall.on(CallsApiEvent.MACHINE_DETECTION_FAILED, (event) => {
console.log(`Machine detection failed. Reason: ${event.reason}`);
});