Skip to content

Commit

Permalink
Add "answer" button
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlogic committed Aug 25, 2015
1 parent a47d3d3 commit 257e5f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion client-quickstart.rb
Expand Up @@ -17,7 +17,6 @@
post '/voice' do
response = Twilio::TwiML::Response.new do |r|
r.Dial :callerId => '+15124002030' do |d|
d.Number '+16143021744'
d.Client 'example'
end
end
Expand Down
17 changes: 14 additions & 3 deletions views/index.erb
Expand Up @@ -11,7 +11,9 @@
type="text/css" rel="stylesheet" />
<script type="text/javascript">

Twilio.Device.setup("<%= token %>", {debug: true});
var connection;

Twilio.Device.setup("<%= token %>", {debug: true});

Twilio.Device.ready(function (device) {
$("#log").text("Ready");
Expand All @@ -31,17 +33,22 @@

/* Listen for incoming connections */
Twilio.Device.incoming(function (conn) {
connection = 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 answer() {
connection.accept();
$("#log").text("Connected with " + connection.parameters.From);
}

function hangup() {
Twilio.Device.disconnectAll();
connection = null;
}
</script>
</head>
Expand All @@ -50,6 +57,10 @@
Call
</button>

<button class="call" onclick="answer();">
Answer
</button>

<button class="hangup" onclick="hangup();">
Hangup
</button>
Expand Down

0 comments on commit 257e5f2

Please sign in to comment.