112:f4a4878c99a3
Anton Shestakov <av6@dwimlabs.net>, Thu, 07 Apr 2016 22:56:16 +0800
index: check if roster has the item before removing it Sometimes we get events from contacts that are not in user's roster, trying to remove such contacts used to fail before this patch.

next change 142:d702edce24b7
previous change 58:7326ef07b362

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.tagName = 'div';
CallView.prototype.className = 'video-block';
CallView.prototype.template = $('#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.$el.html(this.template);
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);
return this.listenTo(this.model, 'change:remote/audio/muted', this.muteAudio);
};
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() {
this.listenTo(this.collection, 'add', this.onAdd);
return this.listenTo(this.collection, 'remove', this.onRemove);
};
CallsApp.prototype.onAdd = function(model) {
model.view = new Tram.CallView({
model: model
});
return this.$el.append(model.view.render().el);
};
CallsApp.prototype.onRemove = function(model) {
return model.view.remove();
};
return CallsApp;
})(Backbone.View);
}).call(this);
//# sourceMappingURL=calls.js.map