Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

caller and callee info capturing #72

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 64 additions & 8 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,22 +223,53 @@ 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would you remove recordingSessionId property? That breaks the requirement that all changes be backwards compatible

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code


}
}
catch (err) {
Expand Down