-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathindex.php
244 lines (212 loc) · 7.45 KB
/
index.php
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
if (isset($_GET["phone_login"])) {
$phone_login = $_GET["phone_login"];
} elseif (isset($_POST["phone_login"])) {
$phone_login = $_POST["phone_login"];
} else {
$phone_login = "";
}
if (isset($_GET["phone_pass"])) {
$phone_pass = $_GET["phone_pass"];
} elseif (isset($_POST["phone_pass"])) {
$phone_pass = $_POST["phone_pass"];
} else {
$phone_pass = "";
}
if (isset($_GET["server_ip"])) {
$server_ip = $_GET["server_ip"];
} elseif (isset($_POST["server_ip"])) {
$server_ip = $_POST["server_ip"];
} else {
$server_ip = "";
}
if (isset($_GET["options"])) {
$options = $_GET["options"];
} elseif (isset($_POST["options"])) {
$options = $_POST["options"];
} else {
$options = "";
}
$phone_pass = base64_decode($phone_pass);
$server_ip = base64_decode($server_ip);
$phone_login = base64_decode($phone_login);
$options = base64_decode($options);
?>
<html>
<head>
<title>WEB PHONE</title>
</head>
<body>
<audio id="bell" src="sounds/incoming.mp3" loop></audio>
<audio id="voice"></audio>
<audio id="dtmf_1" src="sounds/dtmf/1.wav"></audio>
<audio id="dtmf_2" src="sounds/dtmf/2.wav"></audio>
<audio id="dtmf_3" src="sounds/dtmf/3.wav"></audio>
<audio id="dtmf_4" src="sounds/dtmf/4.wav"></audio>
<audio id="dtmf_5" src="sounds/dtmf/5.wav"></audio>
<audio id="dtmf_6" src="sounds/dtmf/6.wav"></audio>
<audio id="dtmf_7" src="sounds/dtmf/7.wav"></audio>
<audio id="dtmf_8" src="sounds/dtmf/8.wav"></audio>
<audio id="dtmf_9" src="sounds/dtmf/9.wav"></audio>
<audio id="dtmf_0" src="sounds/dtmf/0.wav"></audio>
<audio id="dtmf_*" src="sounds/dtmf/s.wav"></audio>
<audio id="dtmf_#" src="sounds/dtmf/h.wav"></audio>
<audio id="dtmfTone" src="sounds/dtmf.wav"> </audio>
<p id="state"></p>
<p id="callState"></p>
<p id="errState"></p>
<div id='divKeyPad' class='span2 well div-keypad' style="left:0px; top:0px; width:250; height:240; visibility:hidden">
<table style="width: 100%; height: 100%">
<tr>
<td><input type="button" style="width: 33%" class="btn" value="1" onclick="sipSendDTMF('1');" /><input type="button" style="width: 33%" class="btn" value="2" onclick="sipSendDTMF('2');" /><input type="button" style="width: 33%" class="btn" value="3" onclick="sipSendDTMF('3');" /></td>
</tr>
<tr>
<td><input type="button" style="width: 33%" class="btn" value="4" onclick="sipSendDTMF('4');" /><input type="button" style="width: 33%" class="btn" value="5" onclick="sipSendDTMF('5');" /><input type="button" style="width: 33%" class="btn" value="6" onclick="sipSendDTMF('6');" /></td>
</tr>
<tr>
<td><input type="button" style="width: 33%" class="btn" value="7" onclick="sipSendDTMF('7');" /><input type="button" style="width: 33%" class="btn" value="8" onclick="sipSendDTMF('8');" /><input type="button" style="width: 33%" class="btn" value="9" onclick="sipSendDTMF('9');" /></td>
</tr>
<tr>
<td><input type="button" style="width: 33%" class="btn" value="*" onclick="sipSendDTMF('*');" /><input type="button" style="width: 33%" class="btn" value="0" onclick="sipSendDTMF('0');" /><input type="button" style="width: 33%" class="btn" value="#" onclick="sipSendDTMF('#');" /></td>
</tr>
<tr>
<td colspan=3><input type="button" style="width: 100%" class="btn btn-medium btn-danger" value="close" onclick="closeKeyPad();" /></td>
</tr>
</table>
</div>
<button id="btn" onclick="mute_unmute()">Mute</button>
<input type="button" class="btn" style="" id="btnKeyPad" value="KeyPad" onclick='openKeyPad();' />
<script type="text/javascript" src="scripts/sip-0.11.6.min.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript">
var bell = document.getElementById('bell');
var state = document.getElementById('state');
var Stream;
var audioCtx;
var activeCall = false;
var ws_url = "";
var Session = null;
var isMuted = false;
var options = <?php echo json_encode($options) ?>;
options = options.split("--");
for (i in options) {
if (options[i].search("WEBSOCKETURL") === 0)
ws_url = options[i].split("WEBSOCKETURL")[1];
}
//--------------------------------------------//
function openKeyPad() {
divKeyPad.style.visibility = 'visible';
divKeyPad.style.left = ((document.body.clientWidth - C.divKeyPadWidth) >> 1) + 'px';
divKeyPad.style.top = '70px';
divGlassPanel.style.visibility = 'visible';
}
function closeKeyPad() {
divKeyPad.style.left = '0px';
divKeyPad.style.top = '0px';
divKeyPad.style.visibility = 'hidden';
divGlassPanel.style.visibility = 'hidden';
}
function sipSendDTMF(c) {
if (Session && c) {
if (Session.dtmf(c) == 0) {
try {
dtmfTone.play();
} catch (e) {}
}
}
}
//--------------------------------------------------//
function extractDomain(url) {
var domain;
//find & remove protocol (http, ftp, etc.) and get domain
if (url.indexOf("://") > -1) {
domain = url.split('/')[2];
} else {
domain = url.split('/')[0];
}
//find & remove port number
domain = domain.split(':')[0];
return domain;
}
function mute() {
if (Session) {
Session.mute();
}
}
function unmute() {
if (Session) {
Session.unmute();
}
}
function mute_unmute() {
if (activeCall) {
if (!isMuted) {
mute();
$('#btn').html("Unmute");
} else {
unmute();
$('#btn').html("Mute");
}
}
}
if (ws_url.length < 5) {
$('#errState').html("Got wrong web socket url. Please check your settings");
} else {
$('#errState').html(null);
}
var phoneLogin = <?php echo json_encode($phone_login) ?>;
if (!phoneLogin) {
$('#errState').html("Phone login is not provided. Please check your settings");
} else {
$('#errState').html(null);
}
// uri: 'sip:' + phoneLogin + '@' + extractDomain(ws_url),
var config = {
password: <?php echo json_encode($phone_pass) ?>,
authorizationUser: phoneLogin,
displayName: phoneLogin,
uri: 'sip:' + phoneLogin + '@' + extractDomain(ws_url),
transportOptions: {
wsServers: [ws_url],
traceSip: false
},
hackWssInTransport: true,
registerExpires: 30,
hackIpInContact: true,
log: {
level: 2
},
sessionDescriptionHandlerFactoryOptions: {
constraints: {
audio: true,
video: false
},
peerConnectionOptions: {
rtcConfiguration: {
"rtcpMuxPolicy": "negotiate"
}
},
iceCheckingTimeout: 10000
}
};
var browserUa = navigator.userAgent.toLowerCase();
var isSafari = false;
var isFirefox = false;
if (browserUa.indexOf('safari') > -1 && browserUa.indexOf('chrome') < 0) {
isSafari = true;
} else if (browserUa.indexOf('firefox') > -1 && browserUa.indexOf('chrome') < 0) {
isFirefox = true;
}
if (isSafari) {
config.sessionDescriptionHandlerFactoryOptions.modifiers = [SIP.Web.Modifiers.stripG722];
}
if (isFirefox) {
config.sessionDescriptionHandlerFactoryOptions.alwaysAcquireMediaFirst = true;
config.sessionDescriptionHandlerFactoryOptions.modifiers = [SIP.Web.Modifiers.addMidLines];
}
</script>
<script type="text/javascript" src="scripts/phone.js?0.11.3e"></script>
</body>
</html>