drachtio-srf 4.5.28 → 4.5.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/sip-parser/parser.js +33 -0
- package/package.json +1 -1
- package/test/utils.js +8 -0
package/lib/sip-parser/parser.js
CHANGED
|
@@ -243,6 +243,39 @@ function parseUri(s) {
|
|
|
243
243
|
.map(function(s) { return s.split('='); })
|
|
244
244
|
.reduce(function(params, x) { params[x[0]] = x[1]; return params; }, {})
|
|
245
245
|
} ;
|
|
246
|
+
} else {
|
|
247
|
+
// try if this is tel format
|
|
248
|
+
return parseTelUri(s);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function parseTelUri(s) {
|
|
253
|
+
if (typeof s === 'object')
|
|
254
|
+
return s;
|
|
255
|
+
|
|
256
|
+
const re = /^(?:<)?(tel):([+]?[0-9-.()]*)((;[a-zA-Z0-9\-]+=[a-zA-Z0-9\-\.\(\)]+)+)?(?:>)?(?:\s?(.*)|$)/;
|
|
257
|
+
const r = re.exec(s);
|
|
258
|
+
|
|
259
|
+
if (r) {
|
|
260
|
+
let context = null;
|
|
261
|
+
const params = {};
|
|
262
|
+
if (r[3]) {
|
|
263
|
+
const tp = r[3].split(';').filter(Boolean);
|
|
264
|
+
tp.forEach((p) => {
|
|
265
|
+
const [key, value] = p.split('=');
|
|
266
|
+
params[key] = value;
|
|
267
|
+
if (key === 'phone-context') {
|
|
268
|
+
context = value;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return {
|
|
274
|
+
scheme: r[1],
|
|
275
|
+
number: r[2],
|
|
276
|
+
context,
|
|
277
|
+
params
|
|
278
|
+
};
|
|
246
279
|
}
|
|
247
280
|
}
|
|
248
281
|
|
package/package.json
CHANGED
package/test/utils.js
CHANGED
|
@@ -9,6 +9,14 @@ process.on('unhandledRejection', (reason, p) => {
|
|
|
9
9
|
test('utils', (t) => {
|
|
10
10
|
const uri = Srf.parseUri('sip:1234@10.101.10.1;transport=udp');
|
|
11
11
|
t.ok(uri.params.transport === 'udp', 'exposes Srf.parseUri');
|
|
12
|
+
let telUri = Srf.parseUri('<tel:+1-201-555-0123;phone-context=drachtio.org;ext=1>');
|
|
13
|
+
t.ok(telUri.scheme === 'tel', 'Srf.parseUri can parse tel uri');
|
|
14
|
+
t.ok(telUri.number === '+1-201-555-0123', 'Srf.parseUri can parse tel uri');
|
|
15
|
+
t.ok(telUri.context === 'drachtio.org', 'Srf.parseUri can parse tel uri');
|
|
16
|
+
t.ok(telUri.params.ext === '1', 'Srf.parseUri can parse tel uri');
|
|
17
|
+
telUri = Srf.parseUri('<tel:+1-201-555-0123>');
|
|
18
|
+
t.ok(telUri.scheme === 'tel', 'Srf.parseUri can parse tel uri');
|
|
19
|
+
t.ok(telUri.number === '+1-201-555-0123', 'Srf.parseUri can parse tel uri');
|
|
12
20
|
const err = new Srf.SipError(404);
|
|
13
21
|
t.ok(err instanceof Error && err.status === 404, 'exposes Srf.SipError');
|
|
14
22
|
t.throws((() => new Srf('bad,tag')), assert.AssertionError, 'tags may not contain commas');
|