320:5d464090cea7
Anton Shestakov <av6@dwimlabs.net>, Sat, 14 Jul 2018 19:36:58 +0800
calls: use rivets more aka the most important shortcut

next change 328:c6851321a39e
previous change 318:4201f7b06df7

js/calls.js

Permissions: -rw-r--r--

Other formats: Feeds:
// Generated by CoffeeScript 1.12.7
(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);
},
'click [data-hang-up]': function() {
return this.model.get('contact').trigger('action/hangup');
}
};
CallView.prototype.initialize = function() {
this.setElement(this.templateEl.clone());
this.$local = this.$('video.local');
this.$remote = this.$('video.remote');
this.$avatarColumn = this.$('.avatar-column');
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.toggleTracks = 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.toggleTracks((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.toggleTracks((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.toggleTracks((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, {
call: this.model,
view: this
});
this.av = new Tram.AvatarView({
model: this.model.get('contact')
});
this.$avatarColumn.append(this.av.render().el);
return this;
};
CallView.prototype.remove = function() {
this.av.remove();
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