diff --git a/clientapp/app.js b/clientapp/app.js
index 396c5ab..f825f62 100644
--- a/clientapp/app.js
+++ b/clientapp/app.js
@@ -67,10 +67,6 @@ module.exports = {
client.use(pushNotifications);
xmppEventHandlers(self.api, self);
- if (self.api.jingle.capabilities.length > 1) {
- self.api.jingle.startLocalMedia();
- }
-
self.api.once('session:started', function () {
app.state.hasConnected = true;
cb();
diff --git a/clientapp/helpers/xmppEventHandlers.js b/clientapp/helpers/xmppEventHandlers.js
index 3c6be47..a875954 100644
--- a/clientapp/helpers/xmppEventHandlers.js
+++ b/clientapp/helpers/xmppEventHandlers.js
@@ -409,9 +409,10 @@ module.exports = function (client, app) {
state: 'incoming',
jingleSession: session
});
- 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) {
@@ -430,6 +431,10 @@ module.exports = function (client, app) {
contact.callState = '';
contact.jingleCall = null;
contact.onCall = false;
+ if (me.calls.length == 1) { // this is the last call
+ client.jingle.stopLocalMedia();
+ client.jingle.localStream = null;
+ }
});
client.on('jingle:accepted', function (session) {
@@ -449,11 +454,10 @@ module.exports = function (client, app) {
client.on('jingle:remotestream:added', function (session) {
var contact = me.getContact(session.peer);
if (!contact) {
- contact = new Contact({jid: client.JID(session.peer).bare});
contact.resources.add({id: session.peer});
me.contacts.add(contact);
}
- contact.stream = session.stream;
+ contact.stream = session.streams[0];
});
client.on('jingle:remotestream:removed', function (session) {
diff --git a/clientapp/pages/chat.js b/clientapp/pages/chat.js
index a70cb5f..b17cafc 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,11 +227,41 @@ module.exports = BasePage.extend({
embedIt(newEl);
this.lastModel = model;
},
+ handleAcceptClick: function (e) {
+ e.preventDefault();
+ var self = this;
+
+ 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) {
+ self.model.jingleCall.end({
+ condition: 'decline'
+ });
+ } else {
+ client.sendPresence({to: client.JID(self.model.jingleCall.jingleSession.peer) });
+ self.model.jingleCall.jingleSession.accept();
+ }
+ });
+ } else {
+ client.sendPresence({to: client.JID(this.model.jingleCall.jingleSession.peer) });
+ this.model.jingleCall.jingleSession.accept();
+ }
+ }
+ return false;
+ },
handleEndClick: function (e) {
e.preventDefault();
- this.model.jingleCall.end({
- condition: 'success'
- });
+ var condition = 'success';
+ if (this.model.jingleCall) {
+ if (this.model.jingleCall.jingleSession && this.model.jingleCall.jingleSession.state == 'pending') {
+ condition = 'decline';
+ }
+ this.model.jingleCall.end({
+ condition: condition
+ });
+ }
return false;
},
handleMuteClick: function (e) {
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
diff --git a/package.json b/package.json
index 06a0ec4..39f1f4a 100644
--- a/package.json
+++ b/package.json
@@ -25,7 +25,7 @@
"oembed": "0.1.0",
"semi-static": "0.0.4",
"sound-effect-manager": "0.0.5",
- "stanza.io": "3.2.4",
+ "stanza.io": "3.6.x",
"staydown": "1.0.3",
"templatizer": "0.1.2",
"underscore": "1.5.1",