Anton Shestakov <av6@dwimlabs.net>, Thu, 14 Apr 2016 02:05:24 +0800
index: remove offline contacts only when they change to being offline
Since new contacts are currently added while they still have the default
presence of 'unavailable', add event sees them as offline and throws them away
immediately, before their presence could change to something else.
js/webrtc.js
Permissions: -rw-r--r--
// Generated by CoffeeScript 1.10.0 var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; Tram.WebRTCInterface = (function() { WebRTCInterface.prototype.lstream = null; WebRTCInterface.prototype.rstream = null; function WebRTCInterface(contact) { this.fail = bind(this.fail, this); this.connect = bind(this.connect, this); this.peerJid = this.contact.get('jid'); WebRTCInterface.prototype.init = function(initiator, constraints) { this.initiator = initiator; if (constraints.audio || constraints.video) { return navigator.getUserMedia(constraints, this.connect, this.fail); WebRTCInterface.prototype.connect = function(stream) { this.pc = new RTCPeerConnection({ iceServers: Tram.config.iceServers this.pc.addStream(stream); this.call.set('local/stream', stream); this.pc.onicecandidate = (function(_this) { return _this.sendPayload(event.candidate, 'ice'); this.pc.onaddstream = (function(_this) { _this.rstream = event.stream; _this.call.set('remote/stream', event.stream); return _this.contact.set('callstate', 'established'); return this.sendIntent('initiate'); return this.createOffer(); WebRTCInterface.prototype.onPayload = function(stanza) { el = stanza.getElementsByTagNameNS(Tram.NS.WEBRTC, 'payload')[0]; signal = JSON.parse(el.firstChild.nodeValue); if (signal.type === 'offer') { return this.receiveOffer(signal); } else if (signal.type === 'answer') { return this.receiveAnswer(signal); } else if (signal.candidate) { return this.pc.addIceCandidate(new RTCIceCandidate(signal)); WebRTCInterface.prototype.sendPayload = function(data, type) { payload = JSON.stringify(data); return X.conn.send(msg.tree()); WebRTCInterface.prototype.sendIntent = function(intent) { return X.conn.send(msg.tree()); WebRTCInterface.prototype.createOffer = function() { return this.pc.createOffer((function(_this) { return _this.pc.setLocalDescription(offer, function() { return _this.sendPayload(_this.pc.localDescription, 'offer'); WebRTCInterface.prototype.receiveOffer = function(offer) { return this.pc.setRemoteDescription(new RTCSessionDescription(offer), (function(_this) { return _this.pc.createAnswer(function(answer) { return _this.pc.setLocalDescription(answer, function() { return _this.sendPayload(_this.pc.localDescription, 'answer'); WebRTCInterface.prototype.receiveAnswer = function(answer) { return this.pc.setRemoteDescription(new RTCSessionDescription(answer)); WebRTCInterface.prototype.fail = function() { return this.contact.unset('callstate'); WebRTCInterface.prototype.disconnect = function() { this.call.unset('remote/stream'); this.call.unset('local/stream'); if (this.rstream != null) { this.stopStream(this.rstream); if (this.lstream != null) { this.stopStream(this.lstream); WebRTCInterface.prototype.stopStream = function(stream) { var i, j, len, len1, ref, ref1, track; if (stream.getAudioTracks != null) { ref = stream.getAudioTracks(); for (i = 0, len = ref.length; i < len; i++) { if (typeof track.stop === "function") { if (stream.getVideoTracks != null) { ref1 = stream.getVideoTracks(); for (j = 0, len1 = ref1.length; j < len1; j++) { if (typeof track.stop === "function") { return typeof stream.stop === "function" ? stream.stop() : void 0; //# sourceMappingURL=webrtc.js.map