-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrowser-phone.php
128 lines (112 loc) · 3.38 KB
/
browser-phone.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
<?php
// @start snippet
include 'Services/Twilio/Capability.php';
$accountSid = 'ACxxxxxxxxxxxxxxx';
$authToken = 'xxxxxxxxxxxxxxxxx';
$token = new Services_Twilio_Capability($accountSid, $authToken);
$token->allowClientOutgoing('APxxxxxxxxxxxxxxx');
$token->allowClientIncoming("alice");
// @end snippet
?>
<!DOCTYPE HTML>
<html>
<head>
<title>
Twilio Client Click to Call
</title>
<!-- @start snippet -->
<script type="text/javascript" src="//static.twilio.com/libs/twiliojs/1.1/twilio.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
Twilio.Device.setup("<?php echo $token->generateToken();?>");
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 -->
Number to call: <input type="text" id="tocall" value="">
<input type="button" id="call" value="Start Call"/>
<input type="button" id="hangup" value="Hangup Call" style="display:none;"/>
<div id="status">
Offline
</div>
<div id="dialpad" style="display:none;">
<table>
<tr>
<td><input type="button" value="1" id="button1"></td>
<td><input type="button" value="2" id="button2"></td>
<td><input type="button" value="3" id="button3"></td>
</tr>
<tr>
<td><input type="button" value="4" id="button4"></td>
<td><input type="button" value="5" id="button5"></td>
<td><input type="button" value="6" id="button6"></td>
</tr>
<tr>
<td><input type="button" value="7" id="button7"></td>
<td><input type="button" value="8" id="button8"></td>
<td><input type="button" value="9" id="button9"></td>
</tr>
<tr>
<td><input type="button" value="*" id="buttonstar"></td>
<td><input type="button" value="0" id="button0"></td>
<td><input type="button" value="#" id="buttonpound"></td>
</tr>
</table>
</div>
<!-- @end snippet -->
</div>
</body>
</html>