1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-29 20:52:15 -05:00
kaiwa/clientapp/views/call.js

94 lines
2.5 KiB
JavaScript
Raw Normal View History

2013-10-15 22:48:16 -04:00
/*global $, app*/
"use strict";
var _ = require('underscore');
var HumanView = require('human-view');
var templates = require('../templates');
module.exports = HumanView.extend({
template: templates.includes.call,
classBindings: {
state: ''
},
2013-10-15 22:16:09 -04:00
events: {
'click .answer': 'handleAnswerClick',
'click .ignore': 'handleIgnoreClick',
'click .cancel': 'handleCancelClick',
'click .end': 'handleEndClick',
'click .mute': 'handleMuteClick'
},
render: function () {
this.renderAndBind();
// register bindings for sub model
this.registerBindings(this.model.contact, {
textBindings: {
displayName: '.callerName'
},
srcBindings: {
avatar: '.callerAvatar'
}
});
2013-10-15 22:16:09 -04:00
this.$buttons = this.$('button');
this.listenToAndRun(this.model, 'change:state', this.handleCallStateChange);
return this;
2013-10-15 22:16:09 -04:00
},
handleAnswerClick: function (e) {
2013-10-15 22:48:16 -04:00
e.preventDefault();
var self = this;
self.model.state = 'active';
app.navigate('/chat/' + self.model.contact.jid);
self.model.contact.onCall = true;
self.model.jingleSession.accept();
2013-10-15 22:16:09 -04:00
return false;
},
handleIgnoreClick: function (e) {
2013-10-15 22:48:16 -04:00
e.preventDefault();
this.model.jingleSession.end({
condition: 'decline'
});
2013-10-15 22:16:09 -04:00
return false;
},
handleCancelClick: function (e) {
2013-10-15 22:48:16 -04:00
e.preventDefault();
this.model.jingleSession.end({
condition: 'cancel'
});
2013-10-15 22:16:09 -04:00
return false;
},
handleEndClick: function (e) {
2013-10-15 22:48:16 -04:00
e.preventDefault();
this.model.jingleSession.end({
condition: 'success'
});
2013-10-15 22:16:09 -04:00
return false;
},
handleMuteClick: function (e) {
return false;
},
// we want to make sure we show the appropriate buttons
// when in various stages of the call
handleCallStateChange: function (model, callState) {
var state = callState || this.model.state;
// hide all
this.$buttons.hide();
var map = {
incoming: '.ignore, .answer',
outgoing: '.cancel',
accepted: '.end, .mute',
terminated: '',
ringing: '.cancel',
mute: '.end, .unmute',
unmute: '.end, .mute',
//hold: '',
//resumed: ''
};
console.log('map[state]', map[state]);
this.$(map[state]).show();
}
});