Skip to content

Registering to a proxy

juzna edited this page Jun 21, 2011 · 3 revisions

Registering to a SIP proxy

To use a SIP phone, it does not need to be registered to a proxy and you can make calls by entering other's side IP address (and port). This is not very user friendly and also this doesn't work always, and so there is possibility to register to a proxy. Proxy server can provide you a "normal" phone number like you have on old analog phones; or you can get a name similar to email address which identifies you uniquely. Thus, it will be much easier for others to contact you.

Simplest way to register to a proxy is by definig server, username and password parameters. Registration will be done automatically when plugin is started.

For manual registration, first add a proxy server by calling: phone.addProxy('sip:sip.my-provider.com', 'sip:571123456@sip.my-provider.com') where you should provide address of proxy server and your full username.

After that, Linphone-JS will try to register with this proxy, which will probably need a password to authenticate you. Password request from SIP server will cause firing event authInfoRequested, where you can display a dialog asking for a password. After user enters his password, you should attach authentication info to the plugin: phone.addAuthInfo("571123456", "my-realm", "my-dummy-pass");

This should be enough for the authentication. If given credentials are wrong, authInfoRequested will be fired again. It's your responsibility to add logic in JavaScript, which will show an "Invalid password" error message when this event has been fired for the second time.

Example

// Add a proxy
phone.addProxy('sip:sip.my-provider.com', 'sip:571123456@sip.my-provider.com');

// Wait for event
var numPasswordAsked = 0;
phone.addEventListener('authInfoRequested', function(user, realm) {
  if(++numPasswordAsked > 1) alert('Password was invalid, please retry');
  
  console.log('Auth info requested for', user, realm);
    var pass = prompt('Gimme password for ' + user);

    // Set password
    phone.addAuthInfo(user, realm, pass);
});

Known credentials

If you know all user credentials in advance, you can add authentication info before adding a proxy. Event asking for password will NOT be thrown in this case, when provided password is valid. Also, it's not always required to provide realm - just leave it null.

Example:

phone.addAuthInfo('sip:571123456@sip.my-provider.com', null, 'my-pass');
phone.addProxy('sip:sip.my-provider.com', 'sip:571123456@sip.my-provider.com');