Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions lib/NameAddrHeader.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {Parameters, URI} from './URI'
import {Grammar} from './Grammar'

export class NameAddrHeader {
get display_name(): string;
set display_name(value: string);
Expand All @@ -23,5 +21,5 @@ export class NameAddrHeader {

toString(): string;

static parse(uri: string): Grammar | undefined;
static parse(uri: string): string | undefined;
}
16 changes: 3 additions & 13 deletions lib/NameAddrHeader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const URI = require('./URI');
const Grammar = require('./Grammar');
const Utils = require('./Utils');

module.exports = class NameAddrHeader
{
Expand All @@ -9,22 +8,13 @@ module.exports = class NameAddrHeader
*/
static parse(name_addr_header)
{
name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header');

if (name_addr_header !== -1)
{
return name_addr_header;
}
else
{
return undefined;
}
return Utils.parseNameAddrHeader(name_addr_header);
}

constructor(uri, display_name, parameters)
{
// Checks.
if (!uri || !(uri instanceof URI))
if (!Utils.isValidURI(uri))
{
throw new TypeError('missing or invalid "uri" parameter');
}
Expand Down
4 changes: 1 addition & 3 deletions lib/URI.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {Grammar} from './Grammar'

export type URIScheme = 'sip' | string;

export type Parameters = Record<string, string | null>;
Expand Down Expand Up @@ -40,5 +38,5 @@ export class URI {

toAor(): string;

static parse(uri: string): Grammar | undefined;
static parse(uri: string): string | undefined;
}
12 changes: 1 addition & 11 deletions lib/URI.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const JsSIP_C = require('./Constants');
const Utils = require('./Utils');
const Grammar = require('./Grammar');

/**
* -param {String} [scheme]
Expand All @@ -19,16 +18,7 @@ module.exports = class URI
*/
static parse(uri)
{
uri = Grammar.parse(uri, 'SIP_URI');

if (uri !== -1)
{
return uri;
}
else
{
return undefined;
}
return Utils.parseUri(uri)
}

constructor(scheme, user, host, port, parameters = {}, headers = {})
Expand Down
4 changes: 4 additions & 0 deletions lib/Utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ export function closeMediaStream(stream?: MediaStream): void;
export function cloneArray<T = unknown>(arr: T[]): T[];

export function cloneObject<T>(obj: T, fallback?: T): T;

export function parseUri(uri: string): string | undefined;

export function parseNameAddrHeader(nameAddrHeader: string): string | undefined;
40 changes: 39 additions & 1 deletion lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ exports.normalizeTarget = (target, domain) =>
// Finally parse the resulting URI.
let uri;

if ((uri = URI.parse(target)))
if ((uri = parseUri(target)))
{
return uri;
}
Expand Down Expand Up @@ -550,3 +550,41 @@ exports.cloneObject = (obj, fallback = {}) =>
{
return (obj && Object.assign({}, obj)) || fallback;
};

/**
* Parse the given string and returns a JsSIP.URI instance or undefined if
* it is an invalid URI.
*/
const parseUri = (uri) =>
{
uri = Grammar.parse(uri, 'SIP_URI');

if (uri !== -1)
{
return uri;
}
else
{
return undefined;
}
}
exports.parseUri = parseUri

exports.parseNameAddrHeader = (name_addr_header) =>
{
name_addr_header = Grammar.parse(name_addr_header, 'Name_Addr_Header');

if (name_addr_header !== -1)
{
return name_addr_header;
}
else
{
return undefined;
}
}

exports.isValidURI = (instance) =>
{
return instance && (instance instanceof URI)
}