Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit a9ed58c

Browse files
authored
Merge pull request #6 from TwilioDevEd/incoming-call-display-bug
Incoming call display bug
2 parents fc99035 + 156e2d2 commit a9ed58c

File tree

6 files changed

+36
-35
lines changed

6 files changed

+36
-35
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Implementations in other languages:
2020

2121
| .NET | Java | Node | PHP | Ruby |
2222
| :--- | :--- | :----- | :-- | :--- |
23-
| [In progress] | [Done](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-java) | [Done](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-node) | [Done](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-php) | [Done](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-ruby) |
23+
| [Done](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-csharp) | [Done](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-java) | [Done](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-node) | [Done](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-php) | [Done](https://github.com/TwilioDevEd/voice-javascript-sdk-quickstart-ruby) |
2424

2525
## Set Up
2626

app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ def voice():
6666
# Route to the most recently created client based on the identity stored in the session
6767
dial.client(IDENTITY["identity"])
6868
resp.append(dial)
69-
elif request.form.get("phone"):
69+
elif request.form.get("To"):
7070
# Placing an outbound call from the Twilio client
7171
dial = Dial(caller_id=twilio_number)
7272
# wrap the phone number or client name in the appropriate TwiML verb
7373
# by checking if the number given has only digits and format symbols
74-
if phone_pattern.match(request.form["phone"]):
75-
dial.number(request.form["phone"])
74+
if phone_pattern.match(request.form["To"]):
75+
dial.number(request.form["To"])
7676
else:
77-
dial.client(request.form["phone"])
77+
dial.client(request.form["To"])
7878
resp.append(dial)
7979
else:
8080
resp.say("Thanks for calling!")

static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ <h2 class="instructions">Make a Call</h2>
3232
<input id="phone-number" type="text" placeholder="+15552221234" />
3333
<button id="button-call" type="submit">Call</button>
3434
</form>
35-
<button id="button-hangup" class="hide">Hang Up</button>
35+
<button id="button-hangup-outgoing" class="hide">Hang Up</button>
3636
<div id="incoming-call" class="hide">
3737
<h2>Incoming Call Controls</h2>
3838
<p class="instructions">

static/quickstart.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const inputVolumeBar = document.getElementById("input-volume");
66
const volumeIndicators = document.getElementById("volume-indicators");
77
const callButton = document.getElementById("button-call");
8-
const hangupButton = document.getElementById("button-hangup");
8+
const outgoingCallHangupButton = document.getElementById("button-hangup-outgoing");
99
const callControlsDiv = document.getElementById("call-controls");
1010
const audioSelectionDiv = document.getElementById("output-selection");
1111
const getAudioDevicesButton = document.getElementById("get-devices");
@@ -36,8 +36,7 @@
3636
getAudioDevicesButton.onclick = getAudioDevices;
3737
speakerDevices.addEventListener("change", updateOutputDevice);
3838
ringtoneDevices.addEventListener("change", updateRingtoneDevice);
39-
hangupButton.onclick = hangup;
40-
39+
4140
// SETUP STEP 1:
4241
// Browser client should be started after a user gesture
4342
// to avoid errors in the browser console re: AudioContext
@@ -105,48 +104,47 @@
105104
async function makeOutgoingCall() {
106105
var params = {
107106
// get the phone number to call from the DOM
108-
phone: phoneNumberInput.value,
107+
To: phoneNumberInput.value,
109108
};
110109

111110
if (device) {
112-
log(`Attempting to call ${params.phone} ...`);
111+
log(`Attempting to call ${params.To} ...`);
113112

114113
// Twilio.Device.connect() returns a Call object
115114
const call = await device.connect({ params });
116115

117116
// add listeners to the Call
118117
// "accepted" means the call has finished connecting and the state is now "open"
119-
call.addListener("accept", updateUIAcceptedCall);
120-
call.addListener("disconnect", updateUIDisconnectedCall);
118+
call.on("accept", updateUIAcceptedOutgoingCall);
119+
call.on("disconnect", updateUIDisconnectedOutgoingCall);
120+
call.on("cancel", updateUIDisconnectedOutgoingCall);
121+
call.on("reject", updateUIDisconnectedOutgoingCall);
122+
123+
outgoingCallHangupButton.onclick = () => {
124+
log("Hanging up ...");
125+
call.disconnect();
126+
};
127+
121128
} else {
122129
log("Unable to make call.");
123130
}
124131
}
125132

126-
function updateUIAcceptedCall(call) {
133+
function updateUIAcceptedOutgoingCall(call) {
127134
log("Call in progress ...");
128135
callButton.disabled = true;
129-
hangupButton.classList.remove("hide");
136+
outgoingCallHangupButton.classList.remove("hide");
130137
volumeIndicators.classList.remove("hide");
131138
bindVolumeIndicators(call);
132139
}
133140

134-
function updateUIDisconnectedCall() {
141+
function updateUIDisconnectedOutgoingCall() {
135142
log("Call disconnected.");
136143
callButton.disabled = false;
137-
hangupButton.classList.add("hide");
144+
outgoingCallHangupButton.classList.add("hide");
138145
volumeIndicators.classList.add("hide");
139146
}
140147

141-
// HANG UP A CALL
142-
143-
function hangup() {
144-
log("Hanging up ...");
145-
if (device) {
146-
device.disconnectAll();
147-
}
148-
}
149-
150148
// HANDLE INCOMING CALL
151149

152150
function handleIncomingCall(call) {
@@ -170,7 +168,9 @@
170168
};
171169

172170
// add event listener to call object
173-
call.addListener("cancel", handleDisconnectedIncomingCall);
171+
call.on("cancel", handleDisconnectedIncomingCall);
172+
call.on("disconnect", handleDisconnectedIncomingCall);
173+
call.on("reject", handleDisconnectedIncomingCall);
174174
}
175175

176176
// ACCEPT INCOMING CALL
@@ -189,24 +189,21 @@
189189

190190
function rejectIncomingCall(call) {
191191
call.reject();
192-
193192
log("Rejected incoming call");
194193
resetIncomingCallUI();
195194
}
196195

197196
// HANG UP INCOMING CALL
198197

199-
function hangupIncomingCall() {
200-
hangup();
201-
198+
function hangupIncomingCall(call) {
199+
call.disconnect();
200+
log("Hanging up incoming call");
202201
resetIncomingCallUI();
203202
}
204203

205204
// HANDLE CANCELLED INCOMING CALL
206205

207-
function handleDisconnectedIncomingCall(call) {
208-
device.disconnectAll();
209-
console.log("handledisconnected : ", call);
206+
function handleDisconnectedIncomingCall() {
210207
log("Incoming call ended.");
211208
resetIncomingCallUI();
212209
}
@@ -226,6 +223,9 @@
226223

227224
function resetIncomingCallUI() {
228225
incomingPhoneNumberEl.innerHTML = "";
226+
incomingCallAcceptButton.classList.remove("hide");
227+
incomingCallRejectButton.classList.remove("hide");
228+
incomingCallHangupButton.classList.add("hide");
229229
incomingCallDiv.classList.add("hide");
230230
}
231231

static/site.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ main {
5959
}
6060

6161
select {
62-
width: 300px;
62+
width: 250px;
6363
height: 60px;
6464
margin-bottom: 10px;
6565
}

static/twilio.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)