Skip to content

Commit

Permalink
fix: conference session match issue (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
embbnux authored Oct 19, 2023
1 parent 08904d0 commit 88a823c
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 10 deletions.
24 changes: 18 additions & 6 deletions src/RingCentralCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class RingCentralCall extends EventEmitter {
);
}

_onNewTelephonySession = (telephonySession, fromPreload = false) => {
_getSessionFromTelephonySession(telephonySession) {
let session = this.sessions.find(
(s) => s.telephonySessionId === telephonySession.id
);
Expand All @@ -261,14 +261,26 @@ export class RingCentralCall extends EventEmitter {
const party = telephonySession.party;
if (party && party.direction === directions.OUTBOUND) {
session = this.sessions.find(
(s) => (
!s.telephonySessionId &&
s.to.phoneNumber === party.to.phoneNumber &&
s.direction === directions.OUTBOUND
)
(s) => {
if (s.telephonySessionId) {
return false;
}
if (s.direction !== directions.OUTBOUND) {
return false
}
if (party.to.phoneNumber === 'conference') {
return s.to.phoneNumber && s.to.phoneNumber.indexOf('conf_') === 0;
}
return s.to.phoneNumber === party.to.phoneNumber;
}
);
}
}
return session;
}

_onNewTelephonySession = (telephonySession, fromPreload = false) => {
let session = this._getSessionFromTelephonySession(telephonySession);
if (session) {
session.setTelephonySession(telephonySession);
return session;
Expand Down
107 changes: 103 additions & 4 deletions test/ringcentral-call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,22 +199,121 @@ describe('RingCentral Call ::', () => {
toNumber: '101',
fromNumber: '102',
direction: directions.INBOUND,
})
});
expect(rcCall.sessions.length).toEqual(0);
webphone.userAgent.trigger('invite', webphoneSession);
expect(rcCall.sessions.length).toEqual(1);
expect(rcCall.sessions[0].direction).toEqual(directions.INBOUND);
});

test('should add new session when call control get new event and not existed session', () => {
const telphonySession = new TelephonySession({
const telephonySession = new TelephonySession({
id: '123',
toNumber: '101',
fromNumber: '102',
direction: directions.INBOUND,
})
});
expect(rcCall.sessions.length).toEqual(0);
rcCall.callControl.trigger('new', telphonySession);
rcCall.callControl.trigger('new', telephonySession);
expect(rcCall.sessions.length).toEqual(1);
});

test('should add new session when call control get new event and existed session with same number', () => {
const webphoneSession = new WebPhoneSession({
id: '123',
toNumber: '101',
fromNumber: '102',
direction: directions.OUTBOUND,
});
webphoneSession.request.headers = null; // clear telephony session id in headers
webphone.userAgent.trigger('inviteSent', webphoneSession);
expect(rcCall.sessions.length).toEqual(1);
const telephonySession = new TelephonySession({
id: '123',
toNumber: '101',
fromNumber: '102',
direction: directions.OUTBOUND,
});
rcCall.callControl.trigger('new', telephonySession);
expect(rcCall.sessions.length).toEqual(1);
});

test('should add new session when call control get new event and existed session with different number', () => {
const webphoneSession = new WebPhoneSession({
id: '1234',
toNumber: '103',
fromNumber: '102',
direction: directions.OUTBOUND,
});
webphoneSession.request.headers = null; // clear telephony session id in headers
webphone.userAgent.trigger('inviteSent', webphoneSession);
expect(rcCall.sessions.length).toEqual(1);
const telephonySession = new TelephonySession({
id: '123',
toNumber: '101',
fromNumber: '102',
direction: directions.OUTBOUND,
});
rcCall.callControl.trigger('new', telephonySession);
expect(rcCall.sessions.length).toEqual(2);
});

test('should add new session when call control get new event and existed inbound session', () => {
const webphoneSession = new WebPhoneSession({
id: '1234',
toNumber: '103',
fromNumber: '101',
direction: directions.INBOUND,
});
webphoneSession.request.headers = null; // clear telephony session id in headers
webphone.userAgent.trigger('inviteSent', webphoneSession);
expect(rcCall.sessions.length).toEqual(1);
const telephonySession = new TelephonySession({
id: '123',
toNumber: '101',
fromNumber: '102',
direction: directions.OUTBOUND,
});
rcCall.callControl.trigger('new', telephonySession);
expect(rcCall.sessions.length).toEqual(2);
});

test('should add new session when call control get new event and existed session with telephony session id', () => {
const webphoneSession = new WebPhoneSession({
id: '1234',
toNumber: '103',
fromNumber: '101',
direction: directions.OUTBOUND,
});
webphone.userAgent.trigger('inviteSent', webphoneSession);
expect(rcCall.sessions.length).toEqual(1);
const telephonySession = new TelephonySession({
id: '123',
toNumber: '101',
fromNumber: '102',
direction: directions.OUTBOUND,
});
rcCall.callControl.trigger('new', telephonySession);
expect(rcCall.sessions.length).toEqual(2);
});

test('should add new session when call control get new event and existed conference session', () => {
const webphoneSession = new WebPhoneSession({
id: '123',
toNumber: 'conf_121sss',
fromNumber: '102',
direction: directions.OUTBOUND,
});
webphoneSession.request.headers = null; // clear telephony session id in headers
webphone.userAgent.trigger('inviteSent', webphoneSession);
expect(rcCall.sessions.length).toEqual(1);
const telephonySession = new TelephonySession({
id: '123',
toNumber: 'conference',
fromNumber: '102',
direction: directions.OUTBOUND,
});
rcCall.callControl.trigger('new', telephonySession);
expect(rcCall.sessions.length).toEqual(1);
});

Expand Down

0 comments on commit 88a823c

Please sign in to comment.