Extracts base class for ColibriFocus and JingleSession.

This commit is contained in:
paweldomas 2014-03-12 19:59:16 +01:00
parent a2633e20e8
commit a5951df0d9
5 changed files with 56 additions and 73 deletions

2
app.js
View File

@ -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');

View File

@ -6,6 +6,7 @@
<script src="libs/strophe/strophe.jingle.bundle.js?v=8"></script>
<script src="libs/strophe/strophe.jingle.js?v=1"></script>
<script src="libs/strophe/strophe.jingle.sdp.js?v=1"></script>
<script src="libs/strophe/strophe.jingle.sessionbase.js?v=1"></script>
<script src="libs/strophe/strophe.jingle.session.js?v=1"></script>
<script src="libs/colibri/colibri.focus.js?v=8"></script><!-- colibri focus implementation -->
<script src="libs/colibri/colibri.session.js?v=1"></script>

View File

@ -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;
});
};

View File

@ -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'})

View File

@ -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;
});
};