From a5951df0d95bad81e996ed61c7c2ef500ba67e1e Mon Sep 17 00:00:00 2001 From: paweldomas Date: Wed, 12 Mar 2014 19:59:16 +0100 Subject: [PATCH] Extracts base class for ColibriFocus and JingleSession. --- app.js | 2 - index.html | 1 + libs/colibri/colibri.focus.js | 29 +++--------- libs/strophe/strophe.jingle.session.js | 51 ++-------------------- libs/strophe/strophe.jingle.sessionbase.js | 46 +++++++++++++++++++ 5 files changed, 56 insertions(+), 73 deletions(-) create mode 100644 libs/strophe/strophe.jingle.sessionbase.js diff --git a/app.js b/app.js index 2c5a4fc1d8..193d44cb0a 100644 --- a/app.js +++ b/app.js @@ -4,7 +4,6 @@ var connection = null; var focus = null; var activecall = null; var RTC = null; -var RTCPeerConnection = null; var nickname = null; var sharedKey = ''; var roomUrl = null; @@ -23,7 +22,6 @@ function init() { window.location.href = 'chromeonly.html'; return; } - RTCPeerconnection = TraceablePeerConnection; connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind'); diff --git a/index.html b/index.html index fc0733f3ba..f3de5fe2c3 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,7 @@ + diff --git a/libs/colibri/colibri.focus.js b/libs/colibri/colibri.focus.js index 4ba0441c99..84e9473fe8 100644 --- a/libs/colibri/colibri.focus.js +++ b/libs/colibri/colibri.focus.js @@ -34,17 +34,16 @@ THE SOFTWARE. */ /* jshint -W117 */ + +ColibriFocus.prototype = Object.create(SessionBase.prototype); function ColibriFocus(connection, bridgejid) { - this.connection = connection; + + SessionBase.call(this, connection); + this.bridgejid = bridgejid; this.peers = []; this.confid = null; - this.peerconnection - = new TraceablePeerConnection( - this.connection.jingle.ice_config, - this.connection.jingle.pc_constraints); - // media types of the conference this.media = ['audio', 'video']; @@ -623,9 +622,7 @@ ColibriFocus.prototype.sendSSRCUpdate = function (sdp, jid, isadd) { ColibriFocus.prototype.setRemoteDescription = function (session, elem, desctype) { var participant = this.peers.indexOf(session.peerjid); console.log('Colibri.setRemoteDescription from', session.peerjid, participant); - var self = this; var remoteSDP = new SDP(''); - var tmp; var channel; remoteSDP.fromJingle(elem); @@ -800,19 +797,3 @@ ColibriFocus.prototype.terminate = function (session, reason) { delete this.remotessrc[session.peerjid]; this.modifySources(); }; - -ColibriFocus.prototype.modifySources = function () { - var self = this; - this.peerconnection.modifySources(function(){ - $(document).trigger('setLocalDescription.jingle', [self.sid]); - }); -}; - -ColibriFocus.prototype.hardMuteVideo = function (muted) { - - this.peerconnection.hardMuteVideo(muted); - - this.connection.jingle.localVideo.getVideoTracks().forEach(function (track) { - track.enabled = !muted; - }); -}; diff --git a/libs/strophe/strophe.jingle.session.js b/libs/strophe/strophe.jingle.session.js index 69f7b228b1..a6c75978f1 100644 --- a/libs/strophe/strophe.jingle.session.js +++ b/libs/strophe/strophe.jingle.session.js @@ -1,27 +1,17 @@ /* jshint -W117 */ // Jingle stuff +JingleSession.prototype = Object.create(SessionBase.prototype); function JingleSession(me, sid, connection) { + + SessionBase.call(this, connection); + this.me = me; this.sid = sid; - this.connection = connection; this.initiator = null; this.responder = null; this.isInitiator = null; this.peerjid = null; this.state = null; - /** - * Peer connection instance. - * @type {TraceablePeerConnection} - */ - this.peerconnection = null; - //console.log('create PeerConnection ' + JSON.stringify(this.ice_config)); - try { - this.peerconnection = new RTCPeerconnection(this.ice_config, this.pc_constraints); - } catch (e) { - console.error('Failed to create PeerConnection, exception: ', e.message); - console.error(e); - } - this.localSDP = null; this.remoteSDP = null; this.localStreams = []; @@ -633,39 +623,6 @@ JingleSession.prototype.sendTerminate = function (reason, text) { } }; - -JingleSession.prototype.addSource = function (elem) { - - this.peerconnection.addSource(elem); - - this.modifySources(); -}; - -JingleSession.prototype.removeSource = function (elem) { - - this.peerconnection.removeSource(elem); - - this.modifySources(); -}; - -JingleSession.prototype.modifySources = function() { - var self = this; - this.peerconnection.modifySources(function(){ - $(document).trigger('setLocalDescription.jingle', [self.sid]); - }); -}; - -// SDP-based mute by going recvonly/sendrecv -// FIXME: should probably black out the screen as well -JingleSession.prototype.hardMuteVideo = function (muted) { - - this.peerconnection.hardMuteVideo(muted); - - this.connection.jingle.localVideo.getVideoTracks().forEach(function (track) { - track.enabled = !muted; - }); -}; - JingleSession.prototype.sendMute = function (muted, content) { var info = $iq({to: this.peerjid, type: 'set'}) diff --git a/libs/strophe/strophe.jingle.sessionbase.js b/libs/strophe/strophe.jingle.sessionbase.js new file mode 100644 index 0000000000..6388269e52 --- /dev/null +++ b/libs/strophe/strophe.jingle.sessionbase.js @@ -0,0 +1,46 @@ +/** + * Base class for ColibriFocus and JingleSession. + * @param connection Strophe connection object + * @constructor + */ +function SessionBase(connection){ + + this.connection = connection; + this.peerconnection + = new TraceablePeerConnection( + connection.jingle.ice_config, + connection.jingle.pc_constraints); +} + + +SessionBase.prototype.modifySources = function() { + var self = this; + this.peerconnection.modifySources(function(){ + $(document).trigger('setLocalDescription.jingle', [self.sid]); + }); +}; + +SessionBase.prototype.addSource = function (elem) { + + this.peerconnection.addSource(elem); + + this.modifySources(); +}; + +SessionBase.prototype.removeSource = function (elem) { + + this.peerconnection.removeSource(elem); + + this.modifySources(); +}; + +// SDP-based mute by going recvonly/sendrecv +// FIXME: should probably black out the screen as well +SessionBase.prototype.hardMuteVideo = function (muted) { + + this.peerconnection.hardMuteVideo(muted); + + this.connection.jingle.localVideo.getVideoTracks().forEach(function (track) { + track.enabled = !muted; + }); +}; \ No newline at end of file