ringcentral-call-control
Version:
[](https://coveralls.io/github/ringcentral/ringcentral-call-control-js?branch=master) [;
exports.ringOutInboundLegCheck = void 0;
var Session_1 = require("./Session");
function ringOutInboundLegCheck(newData, allSessions) {
var _a = newData || {}, _b = _a.parties, parties = _b === void 0 ? [] : _b, _c = _a.origin, origin = _c === void 0 ? { type: 'Call' } : _c;
var party = parties[0];
var checkResult = {
isRingOutInboundLeg: false,
legSessionId: null,
};
if (!party || origin.type === 'Call' && party.direction === Session_1.Direction.outbound) {
return checkResult;
}
if (allSessions.length) {
for (var _i = 0, allSessions_1 = allSessions; _i < allSessions_1.length; _i++) {
var session = allSessions_1[_i];
var sessionIdGap = parseInt(newData.sessionId, 10) - parseInt(session.sessionId, 10);
var existedSessionParty = session.party;
switch (sessionIdGap) {
case 1000:
case 2000:
case 3000:
case 4000: {
if (party.direction === Session_1.Direction.inbound && party.from && party.to &&
existedSessionParty.from && existedSessionParty.to && (party.from.phoneNumber === existedSessionParty.to.phoneNumber) &&
(party.to.phoneNumber === existedSessionParty.from.phoneNumber)) {
checkResult.isRingOutInboundLeg = true;
}
break;
}
case -1000:
case -2000:
case -3000:
case -4000: {
if (party.direction === Session_1.Direction.outbound && party.from && party.to &&
existedSessionParty.from && existedSessionParty.to && (party.from.phoneNumber === existedSessionParty.to.phoneNumber) &&
(party.to.phoneNumber === existedSessionParty.from.phoneNumber)) {
checkResult.isRingOutInboundLeg = false;
checkResult.legSessionId = session.id;
}
break;
}
default:
break;
}
}
}
return checkResult;
}
exports.ringOutInboundLegCheck = ringOutInboundLegCheck;
//# sourceMappingURL=helper.js.map