/
client.asp
89 lines (70 loc) · 3.08 KB
/
client.asp
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
<%
Option Explicit
Dim client_name, token
client_name = Request.QueryString("client_name")
' For this sample, I've hard coded two Client Tokens since there is no way
' to create them in pure ASP. You need to make sure you specify the client name you
' want to use in the querystring so that Twilio Client can be initialized
if (client_name = "red") then
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJBQzMxMzdkNzY0NTc4MTRhNWVhYmY3ZGU2MmYzNDZkMzlhIiwiZXhwIjoxMzQwMzk1NzE5LCJzY29wZSI6InNjb3BlOmNsaWVudDppbmNvbWluZz9jbGllbnROYW1lPXJlZCJ9.isjukqxKMQbZaddfq3ZHiHtnU_4bcSFB-c59F_1SY5Q"
else
token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJBQzMxMzdkNzY0NTc4MTRhNWVhYmY3ZGU2MmYzNDZkMzlhIiwiZXhwIjoxMzQwMzk1NzE5LCJzY29wZSI6InNjb3BlOmNsaWVudDppbmNvbWluZz9jbGllbnROYW1lPWJsdWUifQ.8tKKdnaPm99oi_ux8u-RFFYjTRQK_4dxzisv9nXccAo"
end if
%>
<!DOCTYPE html>
<html>
<head>
<title>Hello Client Monkey 3</title>
<script type="text/javascript" src="http://static.twilio.com/libs/twiliojs/1.0/twilio.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<link href="http://static0.twilio.com/packages/quickstart/client.css" type="text/css" rel="stylesheet" />
<script type="text/javascript">
Twilio.Device.setup('<%Response.Write(token)%>');
Twilio.Device.ready(function (device) {
$("#log").text("Ready");
});
Twilio.Device.error(function (error) {
$("#log").text("Error: " + error.message);
});
Twilio.Device.connect(function (conn) {
$("#log").text("Successfully established call");
});
Twilio.Device.disconnect(function (conn) {
$("#log").text("Call ended");
});
Twilio.Device.incoming(function (conn) {
$("#log").text("Incoming connection from " + conn.parameters.From);
// accept the incoming connection and start two-way audio
conn.accept();
});
function call() {
Twilio.Device.connect();
}
function hangup() {
Twilio.Device.disconnectAll();
}
function redirect() {
// jQuery ajax request to redirect.asp which will redirect the original call leg
// For this sample I am hard coding the specific client to redirect to, but
// you could use Presence to determine who is currently online and use an
// algorythm to dynamically select the client name
var transferUrl = '/redirect.asp?from_client=<%Response.Write(client_name)%>&to_client=blue';
$.get(transferUrl).success(function(){
$("#log").text('Call transferred to ' + toClient);
});
}
</script>
</head>
<body>
<button class="call" onclick="call();">
Call
</button>
<button class="hangup" onclick="hangup();">
Hangup
</button>
<button class="redirect" onclick="redirect();">
Redirect
</button>
<div id="log">Loading pigeons...</div>
</body>
</html>