Skip to content

Commit

Permalink
VBLOCKS-1690 Call reconnect() only when pstream is not null. (twilio#203
Browse files Browse the repository at this point in the history
)

* VBLOCKS-1690 Call reconnect() only when pstream is not null.

* VBLOCKS-1690 Add unit tests.

* VIDEO-1690 Add changelog entry.
  • Loading branch information
manjeshbhargav authored Oct 5, 2023
1 parent 884aba3 commit 200b50e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
:warning: **Important**: If you are upgrading to version 2.3.0 or later and have firewall rules or network configuration that blocks any unknown traffic by default, you need to update your configuration to allow connections to the new DNS names and IP addresses. Please refer to this [changelog](#230-january-23-2023) for more details.

2.7.3 (in progress)
===================

Bug Fixes
---------

- Fixed an [issue](https://github.com/twilio/twilio-voice.js/issues/163) where, sometimes a TypeError is raised while handling an incoming call under the following circumstances:
- Network interruptions
- updating the token before accepting the call

2.7.2 (September 21, 2023)
=========================

Expand Down
2 changes: 1 addition & 1 deletion lib/twilio/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ class Call extends EventEmitter {
*/
private _onConnected = (): void => {
this._log.info('Received connected from pstream');
if (this._signalingReconnectToken) {
if (this._signalingReconnectToken && this._mediaHandler.version) {
this._pstream.reconnect(
this._mediaHandler.version.getSDP(),
this.parameters.CallSid,
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,42 @@ describe('Call', function() {
});
});

describe('pstream.connected event', () => {
[true, false].forEach(doesMediaHandlerVersionExist => {
['foo', undefined].forEach(signalingReconnectToken => {
describe(`when mediaHandler.version ${
doesMediaHandlerVersionExist ? 'exists' : 'does not exist'
} and signaling reconnect token ${
signalingReconnectToken ? 'exists' : 'does not exist'
}`, () => {
beforeEach(async () => {
conn = new Call(config, Object.assign(options, { callParameters: { CallSid: 'CA1234' } }));
conn.accept();
await clock.tickAsync(0);
if (!doesMediaHandlerVersionExist) {
mediaHandler.version = null;
}
if (signalingReconnectToken) {
// @ts-ignore
conn._signalingReconnectToken = signalingReconnectToken;
}
pstream.emit('connected');
});

it(`should ${
doesMediaHandlerVersionExist && signalingReconnectToken ? '' : 'not '
}call pstream.reconnect()`, async () => {
if (doesMediaHandlerVersionExist && signalingReconnectToken) {
sinon.assert.calledWith(pstream.reconnect, mediaHandler.version.getSDP(), 'CA1234', signalingReconnectToken);
} else {
sinon.assert.notCalled(pstream.reconnect);
}
});
});
});
});
});

describe('pstream.answer event', () => {
let pStreamAnswerPayload: any;

Expand Down

0 comments on commit 200b50e

Please sign in to comment.