-
Notifications
You must be signed in to change notification settings - Fork 48
/
jssip-helper.js
69 lines (60 loc) · 2.85 KB
/
jssip-helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/****************************************************************************
JSCommunicator
http://jscommunicator.org
Copyright (C) 2013-2015 Daniel Pocock http://danielpocock.com
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 2 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
You may distribute non-source (e.g., minimized or compacted) forms of
that code without the full copy of the GNU GPL normally required
provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
****************************************************************************/
// Reads JsCommunicator settings and creates JsSIP configuration object
function getJsSIPSettings(settings) {
// JsSIP currently expects usernames in the turn_servers array
// to be URI encoded (e.g. the @ symbol replaced by %40)
// so we do the encoding here
// Eventually this might change in JsSIP and then this code can
// be removed
var turn_servers = settings.turn_servers;
var encoded_turn_servers = [];
if(Object.prototype.toString.call(turn_servers) === '[object Array]') {
for(var i = 0; i < turn_servers.length; i++) {
encoded_turn_servers[i] = {};
encoded_turn_servers[i].urls = turn_servers[i].server;
encoded_turn_servers[i].username = turn_servers[i].username;
encoded_turn_servers[i].password = turn_servers[i].password;
}
} else {
encoded_turn_servers[0].urls = turn_servers.server;
encoded_turn_servers[0].username = turn_servers.username;
encoded_turn_servers[0].password = turn_servers.password;
}
var jssip_settings = {
uri: settings.user.uri,
password: settings.user.sip_auth_password,
ws_servers: settings.websocket.servers,
sockets: [ new JsSIP.WebSocketInterface(settings.websocket.servers) ],
display_name: settings.user.display_name,
authorization_user: settings.user.sip_auth_user,
register: settings.registration.on_startup,
register_expires: settings.registration.expiry,
registrar_server: settings.registration.server,
no_answer_timeout: settings.dialing.no_answer_timeout,
trace_sip: true,
stun_servers: settings.stun_servers,
turn_servers: encoded_turn_servers,
use_preloaded_route: false,
connection_recovery_min_interval: settings.websocket.connection_recovery_min_interval,
connection_recovery_max_interval: settings.websocket.connection_recovery_max_interval,
hack_via_tcp: false,
hack_ip_in_contact: false,
log: { level: "debug" }
};
return jssip_settings;
};