diff --git a/clientapp/helpers/xmppEventHandlers.js b/clientapp/helpers/xmppEventHandlers.js
index 6deed5c..1c1853b 100644
--- a/clientapp/helpers/xmppEventHandlers.js
+++ b/clientapp/helpers/xmppEventHandlers.js
@@ -409,15 +409,10 @@ module.exports = function (client, app) {
state: 'incoming',
jingleSession: session
});
- if (!client.jingle.localStream) {
- client.jingle.startLocalMedia(null, function (err) {
- session.accept();
- });
- } else {
- session.accept();
- }
contact.jingleCall = call;
+ contact.callState = 'incoming';
me.calls.add(call);
+ // FIXME: send directed presence if not on roster
});
client.on('jingle:outgoing', function (session) {
@@ -441,6 +436,7 @@ module.exports = function (client, app) {
client.on('jingle:accepted', function (session) {
var contact = me.getContact(session.peer);
contact.callState = 'activeCall';
+ console.log('jingle accepted...');
contact.onCall = true;
});
diff --git a/clientapp/pages/chat.js b/clientapp/pages/chat.js
index a70cb5f..7be10f3 100644
--- a/clientapp/pages/chat.js
+++ b/clientapp/pages/chat.js
@@ -30,6 +30,7 @@ module.exports = BasePage.extend({
'keydown textarea': 'handleKeyDown',
'keyup textarea': 'handleKeyUp',
'click .call': 'handleCallClick',
+ 'click .accept': 'handleAcceptClick',
'click .end': 'handleEndClick',
'click .mute': 'handleMuteClick'
},
@@ -226,10 +227,38 @@ module.exports = BasePage.extend({
embedIt(newEl);
this.lastModel = model;
},
+ handleAcceptClick: function (e) {
+ e.preventDefault();
+ var self = this;
+
+ //if (!(this.model.jingleCall && this.model.jingleCall.jingleSession)) return;
+ this.$('button.accept').prop('disabled', true);
+ if (this.model.jingleCall.jingleSession.state == 'pending') {
+ if (!client.jingle.localStream) {
+ client.jingle.startLocalMedia(null, function (err) {
+ if (err) {
+ this.model.jingleCall.end({
+ condition: 'decline'
+ });
+ } else {
+ self.model.jingleCall.jingleSession.accept();
+ }
+ });
+ } else {
+ this.model.jingleCall.jingleSession.accept();
+ }
+ }
+ return false;
+ },
handleEndClick: function (e) {
e.preventDefault();
+ var condition = 'success';
+ if (this.model.jingleCall && this.model.jingleCall.jingleSession &&
+ this.model.jingleCall.jingleSession.state == 'pending') {
+ condition = 'decline';
+ }
this.model.jingleCall.end({
- condition: 'success'
+ condition: condition
});
return false;
},
diff --git a/clientapp/templates.js b/clientapp/templates.js
index a1f41da..0b89c44 100644
--- a/clientapp/templates.js
+++ b/clientapp/templates.js
@@ -470,7 +470,7 @@ exports.misc.growlMessage = function anonymous(locals) {
exports.pages.chat = function anonymous(locals) {
var buf = [];
with (locals || {}) {
- buf.push('');
+ buf.push('');
}
return buf.join("");
};
diff --git a/clientapp/templates/pages/chat.jade b/clientapp/templates/pages/chat.jade
index 081516d..76a1cac 100644
--- a/clientapp/templates/pages/chat.jade
+++ b/clientapp/templates/pages/chat.jade
@@ -10,7 +10,8 @@ section.page.chat
video.remote(autoplay)
video.local(autoplay, muted)
aside.button-wrap
- button.end.primary End
+ button.accept.primary Accept
+ button.end.secondary End
.button-group.outlined
button.mute Mute
button.unmute Unmute