From 5ccdc6361b0fadc5902315a72dfb93ae61d1f359 Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Tue, 15 Oct 2013 23:00:56 -0700 Subject: [PATCH] Got things mostly almost working --- clientapp/helpers/xmppEventHandlers.js | 13 ++++++---- clientapp/pages/chat.js | 33 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/clientapp/helpers/xmppEventHandlers.js b/clientapp/helpers/xmppEventHandlers.js index 63cfbff..cd94f61 100644 --- a/clientapp/helpers/xmppEventHandlers.js +++ b/clientapp/helpers/xmppEventHandlers.js @@ -9,6 +9,7 @@ var uuid = require('node-uuid'); var Contact = require('../models/contact'); var Resource = require('../models/resource'); var Message = require('../models/message'); +var Call = require('../models/call'); var discoCapsQueue = async.queue(function (pres, cb) { @@ -337,31 +338,37 @@ module.exports = function (client, app) { client.on('jingle:incoming', function (session) { var contact = me.getContact(session.peer); - me.calls.add({ + var call = new Call({ contact: contact, state: 'incoming', jingleSession: session }); + contact.jingleCall = call; + me.calls.add(call); }); client.on('jingle:outgoing', function (session) { var contact = me.getContact(session.peer); - me.calls.add({ + var call = new Call({ contact: contact, state: 'outgoing', jingleSession: session }); + contact.jingleCall = call; + me.calls.add(call); }); client.on('jingle:terminated', function (session) { var contact = me.getContact(session.peer); contact.callState = ''; contact.jingleCall = null; + contact.onCall = false; }); client.on('jingle:accepted', function (session) { var contact = me.getContact(session.peer); contact.callState = 'activeCall'; + contact.onCall = true; }); client.on('jingle:localstream:added', function (stream) { @@ -375,13 +382,11 @@ module.exports = function (client, app) { client.on('jingle:remotestream:added', function (session) { var contact = me.getContact(session.peer); contact.stream = session.stream; - contact.trigger('change:stream'); }); client.on('jingle:remotestream:removed', function (session) { var contact = me.getContact(session.peer); contact.stream = null; - contact.trigger('change:stream'); }); client.on('jingle:ringing', function (session) { diff --git a/clientapp/pages/chat.js b/clientapp/pages/chat.js index 86142a4..9c3127a 100644 --- a/clientapp/pages/chat.js +++ b/clientapp/pages/chat.js @@ -23,6 +23,7 @@ module.exports = BasePage.extend(chatHelpers).extend({ this.listenTo(this.model.messages, 'change:edited', this.refreshModel); this.listenTo(this.model.messages, 'change:pending', this.refreshModel); + this.listenTo(this.model, 'change:onCall', this.handleCall); this.listenTo(this.model, 'change:stream', this.handleStream); this.render(); @@ -30,7 +31,9 @@ module.exports = BasePage.extend(chatHelpers).extend({ events: { 'keydown textarea': 'handleKeyDown', 'keyup textarea': 'handleKeyUp', - 'click .call': 'handleCallClick' + 'click .call': 'handleCallClick', + 'click .end': 'handleEndClick', + 'click .mute': 'handleMuteClick' }, srcBindings: { avatar: 'header .avatar' @@ -198,12 +201,6 @@ module.exports = BasePage.extend(chatHelpers).extend({ var resources = val || this.model.jingleResources; this.$('button.call').prop('disabled', !resources.length); }, - handleStream: function () { - this.attach = attachMediaStream; - if (!!this.model.stream) { - attachMediaStream(this.model.stream, this.$('.remoteVideo')[0]); - } - }, appendModel: function (model, preload) { var self = this; var isGrouped = model.shouldGroupWith(this.lastModel); @@ -221,5 +218,27 @@ module.exports = BasePage.extend(chatHelpers).extend({ this.lastModel = model; this.scrollIfPinned(); + }, + handleCall: function () { + if (this.model.onCall) { + attachMediaStream(me.stream, this.$('video.local')[0], { + mirror: true, + muted: true + }); + } + }, + handleStream: function (model, stream) { + console.log(arguments); + attachMediaStream(stream, this.$('video.remote')[0]); + }, + handleEndClick: function (e) { + e.preventDefault(); + this.model.jingleCall.end({ + condition: 'success' + }); + return false; + }, + handleMuteClick: function (e) { + return false; } });