Cleanup: fixes to style, typos and documentation.

This commit is contained in:
Boris Grozev 2015-07-22 13:34:44 -05:00
parent b8548757b4
commit be6d7af377
5 changed files with 88 additions and 90 deletions

4
app.js
View File

@ -33,8 +33,8 @@ function init() {
$(document).ready(function () { $(document).ready(function () {
var URLPRocessor = require("./modules/URLProcessor/URLProcessor"); var URLProcessor = require("./modules/URLProcessor/URLProcessor");
URLPRocessor.setConfigParametersFromUrl(); URLProcessor.setConfigParametersFromUrl();
APP.init(); APP.init();
APP.translation.init(); APP.translation.init();

View File

@ -27,13 +27,15 @@ var JitsiMeetExternalAPI = (function()
*/ */
function JitsiMeetExternalAPI(domain, room_name, width, height, parent_node) function JitsiMeetExternalAPI(domain, room_name, width, height, parent_node)
{ {
if(!width || width < MIN_WIDTH)
width = MIN_WIDTH;
if(!height || height < MIN_HEIGHT)
height = MIN_HEIGHT;
this.parentNode = null; this.parentNode = null;
if(parent_node) if(parent_node) {
{
this.parentNode = parent_node; this.parentNode = parent_node;
} } else {
else
{
var scriptTag = document.scripts[document.scripts.length - 1]; var scriptTag = document.scripts[document.scripts.length - 1];
this.parentNode = scriptTag.parentNode; this.parentNode = scriptTag.parentNode;
} }
@ -41,10 +43,6 @@ var JitsiMeetExternalAPI = (function()
this.iframeHolder = this.iframeHolder =
this.parentNode.appendChild(document.createElement("div")); this.parentNode.appendChild(document.createElement("div"));
this.iframeHolder.id = "jitsiConference" + JitsiMeetExternalAPI.id; this.iframeHolder.id = "jitsiConference" + JitsiMeetExternalAPI.id;
if(width < MIN_WIDTH)
width = MIN_WIDTH;
if(height < MIN_HEIGHT)
height = MIN_HEIGHT;
this.iframeHolder.style.width = width + "px"; this.iframeHolder.style.width = width + "px";
this.iframeHolder.style.height = height + "px"; this.iframeHolder.style.height = height + "px";
this.frameName = "jitsiConferenceFrame" + JitsiMeetExternalAPI.id; this.frameName = "jitsiConferenceFrame" + JitsiMeetExternalAPI.id;

View File

@ -93,12 +93,9 @@ LocalStream.prototype.setMute = function (mute)
LocalStream.prototype.isMuted = function () { LocalStream.prototype.isMuted = function () {
var tracks = []; var tracks = [];
if(this.type == "audio") if (this.isAudioStream()) {
{
tracks = this.stream.getAudioTracks(); tracks = this.stream.getAudioTracks();
} } else {
else
{
if (this.stream.ended) if (this.stream.ended)
return true; return true;
tracks = this.stream.getVideoTracks(); tracks = this.stream.getVideoTracks();
@ -108,7 +105,7 @@ LocalStream.prototype.isMuted = function () {
return false; return false;
} }
return true; return true;
} };
LocalStream.prototype.getId = function () { LocalStream.prototype.getId = function () {
return this.stream.getTracks()[0].id; return this.stream.getTracks()[0].id;

View File

@ -4,15 +4,15 @@ var XMPPEvents = require("../../service/xmpp/XMPPEvents");
function TraceablePeerConnection(ice_config, constraints, session) { function TraceablePeerConnection(ice_config, constraints, session) {
var self = this; var self = this;
var RTCPeerconnectionType = null; var RTCPeerConnectionType = null;
if (RTCBrowserType.isFirefox()) { if (RTCBrowserType.isFirefox()) {
RTCPeerconnectionType = mozRTCPeerConnection; RTCPeerConnectionType = mozRTCPeerConnection;
} else if (RTCBrowserType.isTemasysPluginUsed()) { } else if (RTCBrowserType.isTemasysPluginUsed()) {
RTCPeerconnectionType = RTCPeerConnection; RTCPeerConnectionType = RTCPeerConnection;
} else { } else {
RTCPeerconnectionType = webkitRTCPeerConnection; RTCPeerConnectionType = webkitRTCPeerConnection;
} }
this.peerconnection = new RTCPeerconnectionType(ice_config, constraints); this.peerconnection = new RTCPeerConnectionType(ice_config, constraints);
this.updateLog = []; this.updateLog = [];
this.stats = {}; this.stats = {};
this.statsinterval = null; this.statsinterval = null;
@ -95,9 +95,8 @@ function TraceablePeerConnection(ice_config, constraints, session) {
this.statsinterval = window.setInterval(function() { this.statsinterval = window.setInterval(function() {
self.peerconnection.getStats(function(stats) { self.peerconnection.getStats(function(stats) {
var results = stats.result(); var results = stats.result();
for (var i = 0; i < results.length; ++i) {
//console.log(results[i].type, results[i].id, results[i].names())
var now = new Date(); var now = new Date();
for (var i = 0; i < results.length; ++i) {
results[i].names().forEach(function (name) { results[i].names().forEach(function (name) {
var id = results[i].id + '-' + name; var id = results[i].id + '-' + name;
if (!self.stats[id]) { if (!self.stats[id]) {
@ -121,9 +120,12 @@ function TraceablePeerConnection(ice_config, constraints, session) {
}, 1000); }, 1000);
} }
}; }
dumpSDP = function(description) { /**
* Returns a string representation of a SessionDescription object.
*/
var dumpSDP = function(description) {
if (typeof description === 'undefined' || description == null) { if (typeof description === 'undefined' || description == null) {
return ''; return '';
} }
@ -135,7 +137,7 @@ dumpSDP = function(description) {
* Takes a SessionDescription object and returns a "normalized" version. * Takes a SessionDescription object and returns a "normalized" version.
* Currently it only takes care of ordering the a=ssrc lines. * Currently it only takes care of ordering the a=ssrc lines.
*/ */
normalizePlanB = function(desc) { var normalizePlanB = function(desc) {
if (typeof desc !== 'object' || desc === null || if (typeof desc !== 'object' || desc === null ||
typeof desc.sdp !== 'string') { typeof desc.sdp !== 'string') {
console.warn('An empty description was passed as an argument.'); console.warn('An empty description was passed as an argument.');
@ -199,9 +201,15 @@ normalizePlanB = function(desc) {
}; };
if (TraceablePeerConnection.prototype.__defineGetter__ !== undefined) { if (TraceablePeerConnection.prototype.__defineGetter__ !== undefined) {
TraceablePeerConnection.prototype.__defineGetter__('signalingState', function() { return this.peerconnection.signalingState; }); TraceablePeerConnection.prototype.__defineGetter__(
TraceablePeerConnection.prototype.__defineGetter__('iceConnectionState', function() { return this.peerconnection.iceConnectionState; }); 'signalingState',
TraceablePeerConnection.prototype.__defineGetter__('localDescription', function() { function() { return this.peerconnection.signalingState; });
TraceablePeerConnection.prototype.__defineGetter__(
'iceConnectionState',
function() { return this.peerconnection.iceConnectionState; });
TraceablePeerConnection.prototype.__defineGetter__(
'localDescription',
function() {
var desc = this.peerconnection.localDescription; var desc = this.peerconnection.localDescription;
this.trace('getLocalDescription::preTransform', dumpSDP(desc)); this.trace('getLocalDescription::preTransform', dumpSDP(desc));
@ -212,7 +220,9 @@ if (TraceablePeerConnection.prototype.__defineGetter__ !== undefined) {
} }
return desc; return desc;
}); });
TraceablePeerConnection.prototype.__defineGetter__('remoteDescription', function() { TraceablePeerConnection.prototype.__defineGetter__(
'remoteDescription',
function() {
var desc = this.peerconnection.remoteDescription; var desc = this.peerconnection.remoteDescription;
this.trace('getRemoteDescription::preTransform', dumpSDP(desc)); this.trace('getRemoteDescription::preTransform', dumpSDP(desc));
@ -234,7 +244,6 @@ TraceablePeerConnection.prototype.addStream = function (stream) {
catch (e) catch (e)
{ {
console.error(e); console.error(e);
return;
} }
}; };
@ -272,7 +281,8 @@ TraceablePeerConnection.prototype.createDataChannel = function (label, opts) {
return this.peerconnection.createDataChannel(label, opts); return this.peerconnection.createDataChannel(label, opts);
}; };
TraceablePeerConnection.prototype.setLocalDescription = function (description, successCallback, failureCallback) { TraceablePeerConnection.prototype.setLocalDescription
= function (description, successCallback, failureCallback) {
this.trace('setLocalDescription::preTransform', dumpSDP(description)); this.trace('setLocalDescription::preTransform', dumpSDP(description));
// if we're running on FF, transform to Plan A first. // if we're running on FF, transform to Plan A first.
if (RTCBrowserType.usesUnifiedPlan()) { if (RTCBrowserType.usesUnifiedPlan()) {
@ -298,7 +308,8 @@ TraceablePeerConnection.prototype.setLocalDescription = function (description, s
*/ */
}; };
TraceablePeerConnection.prototype.setRemoteDescription = function (description, successCallback, failureCallback) { TraceablePeerConnection.prototype.setRemoteDescription
= function (description, successCallback, failureCallback) {
this.trace('setRemoteDescription::preTransform', dumpSDP(description)); this.trace('setRemoteDescription::preTransform', dumpSDP(description));
// TODO the focus should squeze or explode the remote simulcast // TODO the focus should squeze or explode the remote simulcast
description = this.simulcast.mungeRemoteDescription(description); description = this.simulcast.mungeRemoteDescription(description);
@ -341,7 +352,8 @@ TraceablePeerConnection.prototype.close = function () {
this.peerconnection.close(); this.peerconnection.close();
}; };
TraceablePeerConnection.prototype.createOffer = function (successCallback, failureCallback, constraints) { TraceablePeerConnection.prototype.createOffer
= function (successCallback, failureCallback, constraints) {
var self = this; var self = this;
this.trace('createOffer', JSON.stringify(constraints, null, ' ')); this.trace('createOffer', JSON.stringify(constraints, null, ' '));
this.peerconnection.createOffer( this.peerconnection.createOffer(
@ -369,20 +381,21 @@ TraceablePeerConnection.prototype.createOffer = function (successCallback, failu
); );
}; };
TraceablePeerConnection.prototype.createAnswer = function (successCallback, failureCallback, constraints) { TraceablePeerConnection.prototype.createAnswer
= function (successCallback, failureCallback, constraints) {
var self = this; var self = this;
this.trace('createAnswer', JSON.stringify(constraints, null, ' ')); this.trace('createAnswer', JSON.stringify(constraints, null, ' '));
this.peerconnection.createAnswer( this.peerconnection.createAnswer(
function (answer) { function (answer) {
self.trace('createAnswerOnSuccess::preTransfom', dumpSDP(answer)); self.trace('createAnswerOnSuccess::preTransform', dumpSDP(answer));
// if we're running on FF, transform to Plan A first. // if we're running on FF, transform to Plan A first.
if (RTCBrowserType.usesUnifiedPlan()) { if (RTCBrowserType.usesUnifiedPlan()) {
answer = self.interop.toPlanB(answer); answer = self.interop.toPlanB(answer);
self.trace('createAnswerOnSuccess::postTransfom (Plan B)', dumpSDP(answer)); self.trace('createAnswerOnSuccess::postTransform (Plan B)', dumpSDP(answer));
} }
if (config.enableSimulcast && self.simulcast.isSupported()) { if (config.enableSimulcast && self.simulcast.isSupported()) {
answer = self.simulcast.mungeLocalDescription(answer); answer = self.simulcast.mungeLocalDescription(answer);
self.trace('createAnswerOnSuccess::postTransfom (simulcast)', dumpSDP(answer)); self.trace('createAnswerOnSuccess::postTransform (simulcast)', dumpSDP(answer));
} }
successCallback(answer); successCallback(answer);
}, },
@ -394,8 +407,9 @@ TraceablePeerConnection.prototype.createAnswer = function (successCallback, fail
); );
}; };
TraceablePeerConnection.prototype.addIceCandidate = function (candidate, successCallback, failureCallback) { TraceablePeerConnection.prototype.addIceCandidate
var self = this; = function (candidate, successCallback, failureCallback) {
//var self = this;
this.trace('addIceCandidate', JSON.stringify(candidate, null, ' ')); this.trace('addIceCandidate', JSON.stringify(candidate, null, ' '));
this.peerconnection.addIceCandidate(candidate); this.peerconnection.addIceCandidate(candidate);
/* maybe later /* maybe later

View File

@ -26,9 +26,6 @@ function connect(jid, password) {
connection = XMPP.createConnection(); connection = XMPP.createConnection();
Moderator.setConnection(connection); Moderator.setConnection(connection);
if (connection.disco) {
// for chrome, add multistream cap
}
connection.jingle.pc_constraints = APP.RTC.getPCConstraints(); connection.jingle.pc_constraints = APP.RTC.getPCConstraints();
if (config.useIPv6) { if (config.useIPv6) {
// https://code.google.com/p/webrtc/issues/detail?id=2828 // https://code.google.com/p/webrtc/issues/detail?id=2828
@ -131,8 +128,8 @@ function connect(jid, password) {
// if we get disconnected from the XMPP server permanently. // if we get disconnected from the XMPP server permanently.
// If the connection failed, retry. // If the connection failed, retry.
if (connectionFailed if (connectionFailed &&
&& faultTolerantConnect.retry("connection-failed")) { faultTolerantConnect.retry("connection-failed")) {
return; return;
} }
@ -151,11 +148,10 @@ function connect(jid, password) {
} }
function maybeDoJoin() { function maybeDoJoin() {
if (connection && connection.connected && if (connection && connection.connected &&
Strophe.getResourceFromJid(connection.jid) Strophe.getResourceFromJid(connection.jid) &&
&& (APP.RTC.localAudio || APP.RTC.localVideo)) { (APP.RTC.localAudio || APP.RTC.localVideo)) {
// .connected is true while connecting? // .connected is true while connecting?
doJoin(); doJoin();
} }
@ -198,7 +194,8 @@ var unload = (function () {
async: false, async: false,
cache: false, cache: false,
contentType: 'application/xml', contentType: 'application/xml',
data: "<body rid='" + (connection.rid || connection._proto.rid) + data: "<body rid='" +
(connection.rid || connection._proto.rid) +
"' xmlns='http://jabber.org/protocol/httpbind' sid='" + "' xmlns='http://jabber.org/protocol/httpbind' sid='" +
(connection.sid || connection._proto.sid) + (connection.sid || connection._proto.sid) +
"' type='terminate'>" + "' type='terminate'>" +
@ -224,7 +221,7 @@ function setupEvents() {
// (change URL). If this participant doesn't unload properly, then it // (change URL). If this participant doesn't unload properly, then it
// becomes a ghost for the rest of the participants that stay in the // becomes a ghost for the rest of the participants that stay in the
// conference. Thankfully handling the 'unload' event in addition to the // conference. Thankfully handling the 'unload' event in addition to the
// 'beforeunload' event seems to garante the execution of the 'unload' // 'beforeunload' event seems to guarantee the execution of the 'unload'
// method at least once. // method at least once.
// //
// The 'unload' method can safely be run multiple times, it will actually do // The 'unload' method can safely be run multiple times, it will actually do
@ -274,10 +271,8 @@ var XMPP = {
promptLogin: function () { promptLogin: function () {
eventEmitter.emit(XMPPEvents.PROMPT_FOR_LOGIN); eventEmitter.emit(XMPPEvents.PROMPT_FOR_LOGIN);
}, },
joinRoom: function(roomName, useNicks, nick) joinRoom: function(roomName, useNicks, nick) {
{ var roomjid = roomName;
var roomjid;
roomjid = roomName;
if (useNicks) { if (useNicks) {
if (nick) { if (nick) {
@ -286,7 +281,6 @@ var XMPP = {
roomjid += '/' + Strophe.getNodeFromJid(connection.jid); roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
} }
} else { } else {
var tmpJid = Strophe.getNodeFromJid(connection.jid); var tmpJid = Strophe.getNodeFromJid(connection.jid);
if(!authenticatedUser) if(!authenticatedUser)
@ -323,14 +317,12 @@ var XMPP = {
} }
eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE, onUnload); eventEmitter.emit(XMPPEvents.DISPOSE_CONFERENCE, onUnload);
connection.jingle.activecall = null; connection.jingle.activecall = null;
if(!onUnload) if (!onUnload) {
{
this.sessionTerminated = true; this.sessionTerminated = true;
connection.emuc.doLeave(); connection.emuc.doLeave();
} }
}, },
addListener: function(type, listener) addListener: function(type, listener) {
{
eventEmitter.on(type, listener); eventEmitter.on(type, listener);
}, },
removeListener: function (type, listener) { removeListener: function (type, listener) {
@ -398,7 +390,6 @@ var XMPP = {
return false; return false;
} }
if (this.forceMuted && !mute) { if (this.forceMuted && !mute) {
console.info("Asking focus for unmute"); console.info("Asking focus for unmute");
connection.moderate.setMute(connection.emuc.myroomjid, mute); connection.moderate.setMute(connection.emuc.myroomjid, mute);
@ -411,11 +402,7 @@ var XMPP = {
return true; return true;
} }
// It is not clear what is the right way to handle multiple tracks.
// So at least make sure that they are all muted or all unmuted and
// that we send presence just once.
APP.RTC.localAudio.setMute(mute); APP.RTC.localAudio.setMute(mute);
// isMuted is the opposite of audioEnabled
this.sendAudioInfoPresence(mute, callback); this.sendAudioInfoPresence(mute, callback);
return true; return true;
}, },
@ -439,9 +426,11 @@ var XMPP = {
var sdp = new SDP(answer.sdp); var sdp = new SDP(answer.sdp);
if (sdp.media.length > 1) { if (sdp.media.length > 1) {
if (unmute) if (unmute)
sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv'); sdp.media[1] = sdp.media[1].replace(
'a=recvonly', 'a=sendrecv');
else else
sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly'); sdp.media[1] = sdp.media[1].replace(
'a=sendrecv', 'a=recvonly');
sdp.raw = sdp.session + sdp.media.join(''); sdp.raw = sdp.session + sdp.media.join('');
answer.sdp = sdp.raw; answer.sdp = sdp.raw;
} }
@ -451,7 +440,8 @@ var XMPP = {
}, },
function (error) { function (error) {
console.log('mute SLD error'); console.log('mute SLD error');
eventEmitter.emit(XMPPEvents.SET_LOCAL_DESCRIPTION_ERROR); eventEmitter.emit(
XMPPEvents.SET_LOCAL_DESCRIPTION_ERROR);
} }
); );
}, },
@ -473,8 +463,7 @@ var XMPP = {
startingCallback, startedCallback, connection); startingCallback, startedCallback, connection);
}, },
addToPresence: function (name, value, dontSend) { addToPresence: function (name, value, dontSend) {
switch (name) switch (name) {
{
case "displayName": case "displayName":
connection.emuc.addDisplayNameToPresence(value); connection.emuc.addDisplayNameToPresence(value);
break; break;