206:d0bde0e3cc62
Anton Shestakov <av6@dwimlabs.net>, Wed, 01 Jun 2016 21:26:22 +0800
index: expand, but also deduplicate existence checks for previous and contact

next change 247:fcca53a2f523
previous change 191:d2453b933c21

js/calls.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.10.0
(function() {
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
Tram.Call = (function(superClass) {
extend(Call, superClass);
function Call() {
return Call.__super__.constructor.apply(this, arguments);
}
Call.prototype.idAttribute = 'jid';
Call.prototype.initialize = function() {
this.on('change:local/stream', this.updateLocalStreamURL);
return this.on('change:remote/stream', this.updateRemoteStreamURL);
};
Call.prototype.updateStreamURL = function(sattr, uattr) {
var stream;
if (this.has(uattr)) {
URL.revokeObjectURL(this.get(uattr));
}
stream = this.get(sattr);
if (stream) {
return this.set(uattr, URL.createObjectURL(stream));
} else {
return this.unset(uattr);
}
};
Call.prototype.updateLocalStreamURL = function() {
return this.updateStreamURL('local/stream', 'local/stream/url');
};
Call.prototype.updateRemoteStreamURL = function() {
return this.updateStreamURL('remote/stream', 'remote/stream/url');
};
return Call;
})(Backbone.Model);
Tram.Calls = (function(superClass) {
extend(Calls, superClass);
function Calls() {
return Calls.__super__.constructor.apply(this, arguments);
}
Calls.prototype.model = Tram.Call;
return Calls;
})(Backbone.Collection);
Tram.CallView = (function(superClass) {
extend(CallView, superClass);
function CallView() {
return CallView.__super__.constructor.apply(this, arguments);
}
CallView.prototype.templateEl = $($('#video-block-template').html());
CallView.prototype.events = {
'click [data-mute-cam]': function() {
return this.model.set('local/video/muted', true);
},
'click [data-unmute-cam]': function() {
return this.model.set('local/video/muted', false);
},
'click [data-mute-mic]': function() {
return this.model.set('local/audio/muted', true);
},
'click [data-unmute-mic]': function() {
return this.model.set('local/audio/muted', false);
},
'click [data-mute-audio]': function() {
return this.model.set('remote/audio/muted', true);
},
'click [data-unmute-audio]': function() {
return this.model.set('remote/audio/muted', false);
}
};
CallView.prototype.initialize = function() {
this.setElement(this.templateEl.clone());
this.$local = this.$('video.local');
this.$remote = this.$('video.remote');
return this.bind();
};
CallView.prototype.bind = function() {
this.listenTo(this.model, 'change:local/stream/url', this.updateLocal);
this.listenTo(this.model, 'change:remote/stream/url', this.updateRemote);
this.listenTo(this.model, 'change:local/video/muted', this.muteCam);
this.listenTo(this.model, 'change:local/audio/muted', this.muteMic);
this.listenTo(this.model, 'change:remote/audio/muted', this.muteAudio);
return this.listenTo(this.model, 'remove', this.remove);
};
CallView.prototype.updateLocal = function() {
if (this.model.has('local/stream/url')) {
return this.updateVideo(this.$local, this.model.get('local/stream/url'));
} else {
return this.removeVideo(this.$local);
}
};
CallView.prototype.updateRemote = function() {
if (this.model.has('remote/stream/url')) {
return this.updateVideo(this.$remote, this.model.get('remote/stream/url'));
} else {
return this.removeVideo(this.$remote);
}
};
CallView.prototype.updateVideo = function($video, url) {
return $video.each(function() {
this.src = url;
return this.play();
});
};
CallView.prototype.removeVideo = function($video) {
return $video.each(function() {
this.pause();
return this.removeAttribute('src');
});
};
CallView.prototype.enableTracks = function(tracks, state) {
var i, len, results, track;
if (tracks != null) {
results = [];
for (i = 0, len = tracks.length; i < len; i++) {
track = tracks[i];
results.push(track.enabled = state);
}
return results;
}
};
CallView.prototype.muteCam = function() {
var muted, ref;
muted = this.model.get('local/video/muted');
return this.enableTracks((ref = this.model.get('local/stream')) != null ? typeof ref.getVideoTracks === "function" ? ref.getVideoTracks() : void 0 : void 0, !muted);
};
CallView.prototype.muteMic = function() {
var muted, ref;
muted = this.model.get('local/audio/muted');
return this.enableTracks((ref = this.model.get('local/stream')) != null ? typeof ref.getAudioTracks === "function" ? ref.getAudioTracks() : void 0 : void 0, !muted);
};
CallView.prototype.muteAudio = function() {
var muted, ref;
muted = this.model.get('remote/audio/muted');
return this.enableTracks((ref = this.model.get('remote/stream')) != null ? typeof ref.getAudioTracks === "function" ? ref.getAudioTracks() : void 0 : void 0, !muted);
};
CallView.prototype.render = function() {
this.rivet = rivets.bind(this.el, {
model: this.model,
view: this
});
return this;
};
CallView.prototype.remove = function() {
this.rivet.unbind();
return CallView.__super__.remove.apply(this, arguments);
};
return CallView;
})(Backbone.View);
Tram.CallsApp = (function(superClass) {
extend(CallsApp, superClass);
function CallsApp() {
return CallsApp.__super__.constructor.apply(this, arguments);
}
CallsApp.prototype.initialize = function() {
return this.listenTo(this.collection, 'add', this.onAdd);
};
CallsApp.prototype.onAdd = function(model) {
model.view = new Tram.CallView({
model: model
});
return this.$el.append(model.view.render().el);
};
return CallsApp;
})(Backbone.View);
}).call(this);
//# sourceMappingURL=calls.js.map