Skip to content

Commit

Permalink
chore(2.2.11): updated version to 2.2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
sanyamjain-plivo authored Jun 7, 2024
1 parent c0c3c54 commit c550855
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 115 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable GA release changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## v2.2.11 (released@ 07-06-2024)

**Bug Fixes**
* Enhanced call handling functionality to support multiple executions of the call() method.


## v2.2.10 (released@ 22-05-2024)

**Bug Fixes**
Expand Down
50 changes: 28 additions & 22 deletions lib/managers/incomingCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,21 @@ const onProgress = (incomingCall: CallSession) => (): void => {
4,
callerUri.indexOf('@'),
)}@${DOMAIN}`;
Plivo.log.debug(`${LOGCAT.CALL} | Emitting onIncomingCall`);
cs.emit(
'onIncomingCall',
callerId,
incomingCall.extraHeaders,
incomingCall.getCallInfo("local"),
callerName,
);
cs.noiseSuppresion.setLocalMediaStream();
const emitIncomingCall = () => {
Plivo.log.debug(`${LOGCAT.CALL} | Emitting onIncomingCall`);
cs.emit(
'onIncomingCall',
callerId,
incomingCall.extraHeaders,
incomingCall.getCallInfo("local"),
callerName,
);
};
cs.noiseSuppresion.setLocalMediaStream().then(() => {
emitIncomingCall();
}).catch(() => {
emitIncomingCall();
});
addCloseProtectionListeners.call(cs);
Plivo.log.debug(`${LOGCAT.CALL} | Incoming Call Extra Headers : ${JSON.stringify(incomingCall.extraHeaders)}`);
};
Expand Down Expand Up @@ -542,21 +548,21 @@ export const answerIncomingCall = function (
handleOtherInvites(curIncomingCall, actionOnOtherIncomingCalls);
cs.owaLastDetect.isOneWay = false;
try {
cs._currentSession = curIncomingCall;
cs.incomingInvites.delete(curIncomingCall.callUUID as string);
if (curIncomingCall === cs.lastIncomingCall) {
cs.lastIncomingCall = null;
if (cs.incomingInvites.size) {
cs.lastIncomingCall = cs.incomingInvites.values().next().value;
}
}
cs.loggerUtil.setSipCallID(cs._currentSession.sipCallID ?? "");
cs.callSession = cs._currentSession.session;
cs.callUUID = cs._currentSession.callUUID;
Plivo.log.debug(`${LOGCAT.CALL} | CallUUID is ${cs.callUUID}`);
cs.callDirection = cs._currentSession.direction;
getAnswerOptions().then((options) => {
curIncomingCall.session.answer(options);
cs._currentSession = curIncomingCall;
cs.incomingInvites.delete(curIncomingCall.callUUID as string);
if (curIncomingCall === cs.lastIncomingCall) {
cs.lastIncomingCall = null;
if (cs.incomingInvites.size) {
cs.lastIncomingCall = cs.incomingInvites.values().next().value;
}
}
cs.loggerUtil.setSipCallID(cs._currentSession.sipCallID ?? "");
cs.callSession = cs._currentSession.session;
cs.callUUID = cs._currentSession.callUUID;
Plivo.log.debug(`${LOGCAT.CALL} | CallUUID is ${cs.callUUID}`);
cs.callDirection = cs._currentSession.direction;
});
} catch (err) {
Plivo.log.error(`${LOGCAT.CALL} | error in answering incoming call : `, err.message);
Expand Down
146 changes: 70 additions & 76 deletions lib/managers/outgoingCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,71 +463,67 @@ const getCleanedHeaders = (extraHeaders: ExtraHeaders = {}): string[] => {
* They should start with 'X-PH'
* @returns Outgoing call answer options
*/
const getOptions = function (extraHeaders: ExtraHeaders): Promise<SessionAnswerOptions> {
return new Promise((resolve) => {
const opts: SessionAnswerOptions = {};
opts.sessionTimersExpires = SESSION_TIMERS_EXPIRES;
opts.pcConfig = {
iceServers: [{ urls: STUN_SERVERS }],
};
opts.mediaConstraints = {
audio: cs.options.audioConstraints || true,
video: false,
};
// opts.rtcConstraints = null;
opts.extraHeaders = getCleanedHeaders(extraHeaders);
cs.noiseSuppresion.startNoiseSuppression().then((mediaStream) => {
opts.mediaStream = mediaStream != null ? mediaStream : (window as any).localStream;
// eslint-disable-next-line @typescript-eslint/dot-notation
opts['eventHandlers'] = {
sending: onSending,
sdp: onSDP,
progress: OnProgress,
accepted: onAccepted,
confirmed: onConfirmed,
noCall: onEnded,
newDTMF,
newInfo,
icecandidate: (event: SessionIceCandidateEvent) => cs._currentSession
&& cs._currentSession.onIceCandidate(cs, event),
icetimeout: (sec: number) => cs._currentSession
&& cs._currentSession.onIceTimeout(cs, sec),
failed: onFailed,
ended: onEnded,
getusermediafailed: (err) => cs._currentSession
&& cs._currentSession.onGetUserMediaFailed(cs, err),
'peerconnection:createofferfailed': (err) => cs._currentSession
&& cs._currentSession.handlePeerConnectionFailures(
cs,
'createofferfailed',
cs.callStats ? cs.callStats.webRTCFunctions.createOffer : null,
err,
),
'peerconnection:createanswerfailed': (err) => cs._currentSession
&& cs._currentSession.handlePeerConnectionFailures(
cs,
'createanswerfailed',
cs.callStats ? cs.callStats.webRTCFunctions.createAnswer : null,
err,
),
'peerconnection:setlocaldescriptionfailed': (err) => cs._currentSession
&& cs._currentSession.handlePeerConnectionFailures(
cs,
'setlocaldescriptionfailed',
cs.callStats ? cs.callStats.webRTCFunctions.setLocalDescription : null,
err,
),
'peerconnection:setremotedescriptionfailed': (err) => cs._currentSession
&& cs._currentSession.handlePeerConnectionFailures(
cs,
'setremotedescriptionfailed',
cs.callStats ? cs.callStats.webRTCFunctions.setRemoteDescription : null,
err,
),
};
resolve(opts);
});
});
const getOptions = function (extraHeaders: ExtraHeaders, mediaStream: MediaStream | null): any {
const opts: SessionAnswerOptions = {};
opts.sessionTimersExpires = SESSION_TIMERS_EXPIRES;
opts.pcConfig = {
iceServers: [{ urls: STUN_SERVERS }],
};
opts.mediaConstraints = {
audio: cs.options.audioConstraints || true,
video: false,
};
// opts.rtcConstraints = null;
opts.extraHeaders = getCleanedHeaders(extraHeaders);
opts.mediaStream = mediaStream != null ? mediaStream : (window as any).localStream;
// eslint-disable-next-line @typescript-eslint/dot-notation
opts['eventHandlers'] = {
sending: onSending,
sdp: onSDP,
progress: OnProgress,
accepted: onAccepted,
confirmed: onConfirmed,
noCall: onEnded,
newDTMF,
newInfo,
icecandidate: (event: SessionIceCandidateEvent) => cs._currentSession
&& cs._currentSession.onIceCandidate(cs, event),
icetimeout: (sec: number) => cs._currentSession
&& cs._currentSession.onIceTimeout(cs, sec),
failed: onFailed,
ended: onEnded,
getusermediafailed: (err) => cs._currentSession
&& cs._currentSession.onGetUserMediaFailed(cs, err),
'peerconnection:createofferfailed': (err) => cs._currentSession
&& cs._currentSession.handlePeerConnectionFailures(
cs,
'createofferfailed',
cs.callStats ? cs.callStats.webRTCFunctions.createOffer : null,
err,
),
'peerconnection:createanswerfailed': (err) => cs._currentSession
&& cs._currentSession.handlePeerConnectionFailures(
cs,
'createanswerfailed',
cs.callStats ? cs.callStats.webRTCFunctions.createAnswer : null,
err,
),
'peerconnection:setlocaldescriptionfailed': (err) => cs._currentSession
&& cs._currentSession.handlePeerConnectionFailures(
cs,
'setlocaldescriptionfailed',
cs.callStats ? cs.callStats.webRTCFunctions.setLocalDescription : null,
err,
),
'peerconnection:setremotedescriptionfailed': (err) => cs._currentSession
&& cs._currentSession.handlePeerConnectionFailures(
cs,
'setremotedescriptionfailed',
cs.callStats ? cs.callStats.webRTCFunctions.setRemoteDescription : null,
err,
),
};
return opts;
};

const makingCall = (opts: SessionAnswerOptions, destinationUri: string): void => {
Expand Down Expand Up @@ -581,17 +577,15 @@ export const makeCall = (
if (phoneNumber) {
phoneNumberStr = removeSpaces(String(phoneNumber));
}
if (!validateSession(phoneNumberStr)) return false;
const destinationUri = getValidPhoneNumber(phoneNumberStr);
(() => {
getOptions(extraHeaders)
.then((data) => {
makingCall(data, destinationUri);
})
.catch((error) => {
Plivo.log.error("Error:", error);
});
})();
// eslint-disable-next-line consistent-return
cs.noiseSuppresion.startNoiseSuppression().then((mediaStream) => {
const options = getOptions(extraHeaders, mediaStream);
if (!validateSession(phoneNumberStr)) {
return false;
}
const destinationUri = getValidPhoneNumber(phoneNumberStr);
makingCall(options, destinationUri);
});
return true;
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "plivo-browser-sdk",
"title": "plivo-browser-sdk",
"version": "2.2.10",
"version": "2.2.11",
"description": "This library allows you to connect with plivo's voice enviroment from browser",
"main": "./dist/plivobrowsersdk.js",
"types": "index.d.ts",
Expand Down
27 changes: 27 additions & 0 deletions test/integration/incomingcall.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,33 @@ describe('plivoWebSdk', function () {

// #8
// eslint-disable-next-line no-undef
it('incoming call answered multiple times should be answered', (done) => {
if (bail) {
done(new Error('bailing'));
}
Client2.call(primary_user, {
'X-Ph-Random': true,
});
const answerCall = () => {
const response1 = Client1.answer();
const response2 = Client1.answer();
const response3 = Client1.answer();
const response4 = Client1.answer();
waitUntilIncoming(events.onCallAnswered, () => {
if (response1 && !response2 && !response3 && !response4) {
done();
}
}, 1000);
};
waitUntilIncoming(events.onIncomingCall, answerCall, 500);
bailTimer = setTimeout(() => {
bail = true;
done(new Error('incoming call hangup failed'));
}, TIMEOUT);
});

// #9
// eslint-disable-next-line no-undef
it('inbound call should be ended without answer', (done) => {
// terminate any ongoing calls
Client2.hangup();
Expand Down
Loading

0 comments on commit c550855

Please sign in to comment.