Class JsSIP.URI
An instance of the JsSIP.URI class represents a SIP URI and provides a set of attributes and methods to retrive and set the different parts of a URI.
It provides a way to represent the URI in its full form (including parameters and headers) and in the AoR form.
The URI permits itself to be clonned so a second URI can be formed from itself.
Instantiation
JsSIP.URI(scheme="sip", user=null, host, port=null, parameters=null, headers=null)
Instantiation of this class will raise an exception if no host value is passed.
scheme- Optional
Stringindicating the uri scheme. Default value is issip user- Optional
Stringindicating the user name. hostStringrepresenting the host. It can be an IP address or a hostname.parameters- Optional
Objectwith property values represented inStringform. For empty parameters, anullvalue must be indicated. headers- Optional
Objectwith property values represented inStringorArrayofStringsform.
Throws
Example
var parameters = {
param_name: 'param_value',
valueless_param: null
}
var headers = {
header_name: 'header_value',
multi_header: ['multi_header_value1','multi_header_value2']
}
var uri = new JsSIP.URI('sip', 'alice', 'atlanta.com', 5060, parameters, headers)
uri.toAor() // Returns "sip:alice@atlanta.com"
uri.toString() // Returns "sip:alice@atlanta.com:5060;param_name=param_value;valueless_param?Header-Name=header_value&Multi-Header=multi_header_value1&Multi-Header=multi_header_value2"
Instance Attributes
scheme
Set or get a String indicating the URI scheme.
Example
uri.scheme = 'sip';
uri.scheme // Returns 'sip'
uri.scheme = 'sIP';
uri.scheme // Returns 'sip'
user
Set or get a String indicating the URI user.
Example
uri.user = 'alice';
uri.user // Returns 'alice'
uri.user = 'Alice';
uri.user // Returns 'Alice'
uri.user = 'j@s0n'
uri.toAor() // Returns 'sip:j%40s0n@atlanta.com'
host
Set or get a String indicating the URI host.
uri.host = 'atlanta.com';
uri.host // Returns 'atlanta.com'
uri.host = 'AtLATta.cOm';
uri.host // Returns 'atlanta.com'
port
Set or get a Number indicating the URI port.
Example
uri.port = 5060;
uri.port // Returns 5060
uri.port = '5060';
uri.port // Returns 5060
Instance Methods
setParam(key, value=null)
Creates or replaces the given URI parameter with given value.
Parameters
keyStringindicating the parameter name.value- Optional
Stringindicating the parameter value.
Example
uri.setParam('param_name', 'param_value');
getParam(key)
Gets the value of the given URI parameter. Returns undefined if the parameter does not exist in the paramter set.
Parameters
keyStringindicating the parameter name.
Example
uri.getParam('param_name'); // Returns 'param_value'
hasParam(key)
Verifies the existence of the given URI parameter. Returns true if the parameter exists, false otherwise.
Parameters
keyStringindicating the parameter name.
Example
uri.hasParam('param_name'); // Returns true
deleteParam(key)
Deletes the given parameter from the URI.
Parameters
keyStringindicating the parameter name.
Example
uri.deleteParam('param_name');
clearParams()
Removes all the URI parameters.
setHeader(key, value)
Creates or replaces the given URI header with given value.
Parameters
keyStringindicating the header name.valueStringorArrayindicating the header value.
Example
uri.setHeader('header_name','header_value');
uri.setHeader('header_name',['header_value1','header_value2']);
getHeader(key)
Gets the value of the given URI header. Returns an Array with the header value/s for the given header name or undefined if the header does not exist in the header set.
Parameters
keyStringindicating the header name.
Example
uri.setHeader('header_name',['header_value1','header_value2']);
uri.getHeader('header_name'); // Returns ['header_value1','header_value2']
uri.setHeader('header_name','header_value');
uri.getHeader('header_name'); // Returns ['header_value']
hasHeader(key)
Verifies the existence of the given URI header. Returns true if the header exists, false otherwise.
Parameters
keyStringindicating the header name.
Example
uri.setHeader('header_name','header_value');
uri.hasHeader('header_name'); // Returns true
deleteHeader(key)
Deletes the given header from the URI.
Parameters
keyStringindicating the header name.
Example
uri.delteHeader('header_name');
clearHeaders()
Removes all URI headers.
Example
uri.clearHeaders();
clone()
Returns a cloned JsSIP.URI instance of the the URI.
cloned_uri = uri.clone();
cloned_uri === uri // Returns false
toAor()
Returns a String representing the AoR of the URI.
Characters that can’t appear unescaped are escaped as stated in the BNF grammar of the RFC 3261.
uri.toAor(); // Returns "sip:alice@atlanta.com"
uri.user = 'j%40s0n'
uri.toAor(): // Returns "sip:j%40s0n@atlanta.com"
toString()
Returns a String representing the URI.
Characters that can’t appear unescaped are escaped as stated in the BNF grammar of the RFC 3261.
uri.toString(); // Returns "sip:alice@atlanta.com:5060?header_name=header_value1&header_name=header_value2"
Module Functions
parse(uri)
Parses the given String against the SIP URI grammar rule. Returns a JsSIP.URI instance if parsing success, undefined otherwise.
Parameters
uriStringrepresenting a SIP URI.
Example
var uri = JsSIP.URI.parse('sip:alice@atlanta.com');