Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions static/chatWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
left: 186px;
z-index: 2;
}
#callAnswer, #calling {
#callAnswer, #status {
display: none;
position: fixed;
z-index: 4;
Expand Down Expand Up @@ -102,7 +102,7 @@
<video id="localVideo" width="75" height="54" muted></video>
</div>
<div id="callAnswer">Incoming call<br><div id="accept">Accept</div><div id="reject">Reject</div></div>
<div id="calling">Calling…</div>
<div id="status"></div>

<div id="fileDrop"><p>&nbsp;</p><p>Drop a file here!</p></div>
<div id="fullTab">expand</div>
Expand Down
2 changes: 1 addition & 1 deletion static/mobile.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div id="localVideoContainer">
<video id="localVideo" muted></video>
</div>
<button id="closecall" onclick="closeCall();">End Call</button>
<button id="closecall" onclick="closeCall(gChat.who); endCall();">End Call</button>
<audio id="localAudio" muted></audio>
<audio id="remoteAudio"></audio>
</div>
Expand Down
18 changes: 12 additions & 6 deletions static/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,23 @@ function setupEventSource() {
}, false);

source.addEventListener("offer", function(e) {
if (gChat)
var data = JSON.parse(e.data);
// We already are in a call. We reject automatically the incoming
// one.
if (gChat) {
closeCall(data.from, "The callee is busy right now, the call has been rejected.");
return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the audioOnly variable in here, so maybe move that test and early return just after the "var data = " ... line?

}

var data = JSON.parse(e.data);
var audioOnly = JSON.parse(data.request).sdp.indexOf("m=video") == -1;
gChat = {who: data.from, audioOnly: audioOnly};

$("#callAnswer").show();
document.getElementById("callerName").textContent = data.from;
document.getElementById("reject").onclick = function() {closeCall();};
document.getElementById("reject").onclick = function() {
closeCall(gChat.who, "The call has been rejected");
endCall();
};
document.getElementById("accept").onclick = function() {
$("#callAnswer").hide();
$("#call").show();
Expand Down Expand Up @@ -171,12 +178,11 @@ function setupEventSource() {
}, true);
}

function closeCall() {
function closeCall(aUser, aReason) {
if (!gChat)
return;

stopCall(gChat.who);
endCall();
stopCall(aUser, aReason);
}

function endCall() {
Expand Down
4 changes: 2 additions & 2 deletions static/serverConnections.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ function signOutFailure(xhr, status, err) {
alert("Sign out failure: " + err);
}

function stopCall(aUser) {
function stopCall(aUser, aReason) {
$.ajax({
type: 'POST',
url: '/stopcall',
contentType: 'application/json',
data: JSON.stringify({to: aUser})
data: JSON.stringify({to: aUser, reason: aReason})
});
}
37 changes: 27 additions & 10 deletions static/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var gContacts = {};
var gChats = {};
var gUsername = "";
var gFake = false;
var gInChat = false;

function onPersonaLogin(assertion) {
$("#guest").hide();
Expand Down Expand Up @@ -46,12 +47,11 @@ function callPerson(aPerson, aAudioCall) {
}

openChat(aPerson, function(aWin) {
var win = gChats[aPerson].win;
var doc = win.document;
doc.getElementById("calling").style.display = "block";
gChats[aPerson].pc = webrtcMedia.startCall(aPerson, win, aAudioCall,
onConnection, setupFileSharing);
gChats[aPerson].audioOnly = aAudioCall;
var chat = gChats[aPerson];
setStatus(chat, "Calling...");
chat.pc = webrtcMedia.startCall(aPerson, chat.win, aAudioCall,
onConnection, setupFileSharing);
chat.audioOnly = aAudioCall;
});
}

Expand Down Expand Up @@ -316,9 +316,11 @@ function setupEventSource() {

doc.getElementById("callAnswer").style.display = "block";
doc.getElementById("reject").onclick = function() {
stopCall(from, "The call has been rejected");
win.close();
};
doc.getElementById("accept").onclick = function() {
gInChat = true;
doc.getElementById("callAnswer").style.display = "none";
gChats[from].pc = webrtcMedia.handleOffer(data, win, gChats[from].audioOnly,
onConnection, setupFileSharing);
Expand All @@ -340,8 +342,9 @@ function setupEventSource() {
audio.mozSrcObject = video.mozSrcObject;
video.mozSrcObject = null;
}
chat.win.document.getElementById("calling").style.display = "none";
setStatus(chat, "");
pc.setRemoteDescription(answer, function() {
gInChat = true;
// Nothing to do for the audio/video. The interesting things for
// them will happen in onaddstream.
// We need to establish the data connection though.
Expand All @@ -363,8 +366,12 @@ function setupEventSource() {
return;
}
webrtcMedia.endCall(chat.pc, chat.dc, chat.win, chat.audioOnly);
delete gChats[data.from];
chat.win.close();
setStatus(chat, data.reason || "The call has been closed.");
chat.win.document.getElementById("callAnswer").style.display = "none";
setTimeout(function() {
chat.win.close();
delete gChats[data.from];
}, 10000);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timer needs to be cancelled when the user closes the floating window by hand. Otherwise, it may execute if the user starts another call with the same contact; that's what caused the bug I mentioned at #37 (comment)

});

window.addEventListener("beforeunload", function() {
Expand All @@ -373,6 +380,15 @@ function setupEventSource() {
}, true);
}

function setStatus(chat, message) {
var status = chat.win.document.getElementById("status");
if (message) {
status.textContent = message;
status.style.display = "block";
} else
status.style.display = "none";
}

function userIsConnected(userdata) {
$("#userid").text(userdata.userName);
$("#usericon").attr("src", userdata.portrait);
Expand Down Expand Up @@ -426,10 +442,11 @@ function openChat(aTarget, aCallback) {
win.addEventListener("unload", function() {
if (!(aTarget in gChats))
return;
stopCall(aTarget);
stopCall(aTarget, gInChat ? "" : "The call has been canceled.");
var chat = gChats[aTarget];
webrtcMedia.endCall(chat.pc, chat.dc, chat.win, chat.audioOnly);
delete gChats[aTarget];
gInChat = false;
});
if (aCallback) {
aCallback(win);
Expand Down