Skip to content

Commit

Permalink
incorporate changes from pull request 72 (drachtio#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
hajothelen committed Jun 18, 2024
1 parent 5960a96 commit f12070a
Showing 1 changed file with 85 additions and 9 deletions.
94 changes: 85 additions & 9 deletions lib/payload-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,20 @@ module.exports = function parseSiprecPayload(opts) {
const arr = /^(.*:)recording/.exec(key) ;
const prefix = !arr ? '' : (arr[1]) ;
const obj = opts.recordingData[`${prefix}recording`];

const headers = {};
// 1. collect participant data
const participants = {} ;
obj[`${prefix}participant`].forEach((p) => {
const partDetails = {} ;
participants[p.$.participant_id] = partDetails;
// fix for acme packet xml participants
if (p.$.id) {
participants[p.$.id] = partDetails;
}
else {
participants[p.$.participant_id] = partDetails;
}
// end of fix

if ((`${prefix}nameID` in p) && Array.isArray(p[`${prefix}nameID`])) {
partDetails.aor = p[`${prefix}nameID`][0].$.aor;
if ('name' in p[`${prefix}nameID`][0] && Array.isArray(p[`${prefix}nameID`][0].name)) {
Expand All @@ -90,7 +98,24 @@ module.exports = function parseSiprecPayload(opts) {
else if (typeof name === 'object') partDetails.name = name._ ;
}
}


//Extract headers from extensiondata, as received from ACME/Avaya
if ((`${prefix}extensiondata` in p) && Array.isArray(p[`${prefix}extensiondata`])) {
const extdata = p[`${prefix}extensiondata`][0];
debug(`participant extensiondata: ${JSON.stringify(extdata)}`);
if (('apkt:header' in extdata) && Array.isArray(extdata['apkt:header'])) {
extdata['apkt:header'].forEach((h) => {
const name = h.$.label;
if (('value' in h) && Array.isArray(h['value']) && h['value'].length > 0) {
headers[name] = h['value'].slice(-1)[0];
}
});
}
}
});
// add headers in opts
opts.sipheaders = headers;

// 2. find the associated streams for each participant
if (`${prefix}participantstreamassoc` in obj) {
Expand Down Expand Up @@ -198,29 +223,80 @@ module.exports = function parseSiprecPayload(opts) {
}

if (opts.caller.aor) {

let user;
let host;
const uri = parseUri(opts.caller.aor);
if (uri) opts.caller.number = uri.user;
if (uri) user = uri.user;
else {
const arr = /sip:(.*)@/.exec(opts.callee.aor);
opts.caller.number = arr[1];
const arr = /sip:(.*)@/.exec(opts.caller.aor);
if (arr) {
user = arr[1];
}
}
if (uri) host = uri.host;
else {
const arr = /sip:.*@(.*)/.exec(opts.caller.aor);
if (arr) {
host = arr[1];
}
}
debug(`parsed user ${user} from caller aor ${opts.caller.aor}`);
debug(`parsed host ${host} from caller aor ${opts.caller.aor}`);
opts.caller.number = user;
opts.caller.host = host;
}
if (opts.callee.aor) {
let user;
let host;
const uri = parseUri(opts.callee.aor);
if (uri) opts.callee.number = uri.user;
if (uri) user = uri.user;
else {
const arr = /sip:(.*)@/.exec(opts.callee.aor);
opts.callee.number = arr[1];
if (arr) {
user = arr[1];
}
}
if (uri) host = uri.host;
else {
const arr = /sip:.*@(.*)/.exec(opts.callee.aor);
if (arr) {
host = arr[1];
}
}
debug(`parsed user ${user} from callee aor ${opts.callee.aor}`);
debug(`parsed host ${host} from callee aor ${opts.callee.aor}`);
opts.callee.number = user;
opts.callee.host = host;
}
opts.recordingSessionId = opts.recordingData[`${prefix}recording`][`${prefix}session`][0].$.session_id;
obj[`${prefix}session`].forEach((s) => {
/*
Get UCID for User-To-User header, but also check if it exists. We know it
exists within Avaya, but this might not always be the case.
Avaya: recording.session.extensiondata.apkt:ucid
*/
if ((`${prefix}extensiondata` in s) && Array.isArray(s[`${prefix}extensiondata`])) {
opts.ucid = s[`${prefix}extensiondata`][0][`${prefix}apkt:ucid`][0];
} else if (Array.isArray(s[`${prefix}ac:AvayaUCID`])) {
opts.ucid = s[`${prefix}ac:AvayaUCID`][0]._;
} else {
opts.ucid = 'Not available';
}
/*
* Get the Recording session ID
* Sometimes as session_id, sometimes as id
*/
opts.recordingSessionId = s.$.session_id ? s.$.session_id : s.$.id;
});

}
}
catch (err) {
debug(`Error parsing ${err}`);
reject(err);
}
debug(opts, 'payload parser results');
resolve(opts) ;
}) ;
}) ;
};
};

0 comments on commit f12070a

Please sign in to comment.