-
Notifications
You must be signed in to change notification settings - Fork 2
/
browser-phone.html
122 lines (108 loc) · 4.95 KB
/
browser-phone.html
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
<!DOCTYPE HTML>
<html>
<head>
<title>
Twilio Client Click to Call
</title>
<!-- @start snippet -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script type="text/javascript" src="//static.twilio.com/libs/twiliojs/1.1/twilio.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
Twilio.Device.setup("{{ twilio_token }}");
var connection=null;
$("#call").click(function() {
params = { "tocall" : $('#tocall').val()};
connection = Twilio.Device.connect(params);
});
$("#hangup").click(function() {
Twilio.Device.disconnectAll();
});
Twilio.Device.ready(function (device) {
$('#status').text('Ready to start call');
});
Twilio.Device.incoming(function (conn) {
if (confirm('Accept incoming call from ' + conn.parameters.From + '?')){
connection=conn;
conn.accept();
}
});
Twilio.Device.offline(function (device) {
$('#status').text('Offline');
});
Twilio.Device.error(function (error) {
$('#status').text(error);
});
Twilio.Device.connect(function (conn) {
$('#status').text("Successfully established call");
toggleCallStatus();
});
Twilio.Device.disconnect(function (conn) {
$('#status').text("Call ended");
toggleCallStatus();
});
function toggleCallStatus(){
$('#call').toggle();
$('#hangup').toggle();
$('#dialpad').toggle();
}
$.each(['0','1','2','3','4','5','6','7','8','9','star','pound'], function(index, value) {
$('#button' + value).click(function(){
if(connection) {
if (value=='star')
connection.sendDigits('*')
else if (value=='pound')
connection.sendDigits('#')
else
connection.sendDigits(value)
return false;
}
});
});
});
</script>
<!-- @end snippet -->
</head>
<body>
<div align="center">
<!-- @start snippet -->
<form class="form-inline" role="form" style="padding: 25px 10px;">
<div class="form-group">
<label class="sr-only" for="tocall">Number to dial:</label>
<input type="text" class="form-control input-lg" name="tocaall" id="tocall" placeholder="(512) 555-1212">
</div>
<input type="button" id="call" class="btn btn-primary btn-lg" value="Start Call"/>
<input type="button" id="hangup" class="btn btn-primary btn-lg" value="Hangup Call" style="display:none;"/></form>
<div id="status" class="well" style="width: 20%;">
Offline
</div>
<div id="dialpad" style="display:none;">
<table>
<tr>
<td><input type="button" value="1" id="button1" class="btn btn-default btn-lg"></td>
<td><input type="button" value="2" id="button2" class="btn btn-default btn-lg"></td>
<td><input type="button" value="3" id="button3" class="btn btn-default btn-lg"></td>
</tr>
<tr>
<td><input type="button" value="4" id="button4" class="btn btn-default btn-lg"></td>
<td><input type="button" value="5" id="button5" class="btn btn-default btn-lg"></td>
<td><input type="button" value="6" id="button6" class="btn btn-default btn-lg"></td>
</tr>
<tr>
<td><input type="button" value="7" id="button7" class="btn btn-default btn-lg"></td>
<td><input type="button" value="8" id="button8" class="btn btn-default btn-lg"></td>
<td><input type="button" value="9" id="button9" class="btn btn-default btn-lg"></td>
</tr>
<tr>
<td><input type="button" value="*" id="buttonstar" class="btn btn-default btn-lg"></td>
<td><input type="button" value="0" id="button0" class="btn btn-default btn-lg"></td>
<td><input type="button" value="#" id="buttonpound" class="btn btn-default btn-lg"></td>
</tr>
</table>
</div>
<!-- @end snippet -->
</div>
</body>
</html>