fix errors reported by jshint

This commit is contained in:
Philipp Hancke 2014-04-13 14:30:47 +02:00
parent 84593b2bcb
commit 78c8f43c3d
6 changed files with 509 additions and 502 deletions

130
app.js
View File

@ -40,9 +40,11 @@ function init() {
if (RTC === null) {
window.location.href = 'webrtcrequired.html';
return;
/*
} else if (RTC.browser !== 'chrome') {
window.location.href = 'chromeonly.html';
return;
*/
}
connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
@ -196,7 +198,9 @@ function change_local_video(stream, flipX) {
var localVideoSelector = $('#' + localVideo.id);
// Add click handler
localVideoSelector.click(function () { handleVideoThumbClicked(localVideo.src); } );
localVideoSelector.click(function () {
handleVideoThumbClicked(localVideo.src);
});
// Add stream ended handler
stream.onended = function () {
localVideoContainer.removeChild(localVideo);
@ -330,13 +334,16 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
};
// Add click handler
sel.click(function () { handleVideoThumbClicked(vid.src); });
sel.click(function () {
handleVideoThumbClicked(vid.src);
});
// an attempt to work around https://github.com/jitsi/jitmeet/issues/32
if (isVideo
&& data.peerjid && sess.peerjid === data.peerjid &&
if (isVideo &&
data.peerjid && sess.peerjid === data.peerjid &&
data.stream.getVideoTracks().length === 0 &&
connection.jingle.localVideo.getVideoTracks().length > 0) {
//
window.setTimeout(function () {
sendKeyframe(sess.peerconnection);
}, 3000);
@ -396,8 +403,10 @@ function sendKeyframe(pc) {
function () {
pc.createAnswer(
function (modifiedAnswer) {
pc.setLocalDescription(modifiedAnswer,
pc.setLocalDescription(
modifiedAnswer,
function () {
// noop
},
function (error) {
console.log('triggerKeyframe setLocalDescription failed', error);
@ -497,11 +506,11 @@ $(document).bind('setLocalDescription.jingle', function (event, sid) {
newssrcs[type] = ssrc;
directions[type] = (
SDPUtil.find_line(media, 'a=sendrecv')
|| SDPUtil.find_line(media, 'a=recvonly')
|| SDPUtil.find_line('a=sendonly')
|| SDPUtil.find_line('a=inactive')
|| 'a=sendrecv' ).substr(2);
SDPUtil.find_line(media, 'a=sendrecv') ||
SDPUtil.find_line(media, 'a=recvonly') ||
SDPUtil.find_line('a=sendonly') ||
SDPUtil.find_line('a=inactive') ||
'a=sendrecv').substr(2);
}
});
console.log('new ssrcs', newssrcs);
@ -650,8 +659,7 @@ $(document).bind('passwordrequired.muc', function (event, jid) {
console.log('on password required', jid);
$.prompt('<h2>Password required</h2>' +
'<input id="lockKey" type="text" placeholder="shared key" autofocus>',
{
'<input id="lockKey" type="text" placeholder="shared key" autofocus>', {
persistent: true,
buttons: { "Ok": true, "Cancel": false},
defaultButton: 1,
@ -659,12 +667,10 @@ $(document).bind('passwordrequired.muc', function (event, jid) {
document.getElementById('lockKey').focus();
},
submit: function (e, v, m, f) {
if(v)
{
if (v) {
var lockKey = document.getElementById('lockKey');
if (lockKey.value !== null)
{
if (lockKey.value !== null) {
setSharedKey(lockKey.value);
connection.emuc.doJoin(jid, lockKey.value);
}
@ -801,7 +807,7 @@ function toggleVideo() {
);
}
var sess = focus || activecall;
sess = focus || activecall;
if (!sess) {
return;
}
@ -875,9 +881,9 @@ function getCameraVideoPosition( videoWidth,
// Parent height isn't completely calculated when we position the video in
// full screen mode and this is why we use the screen height in this case.
// Need to think it further at some point and implement it properly.
var isFullScreen = document.fullScreen
|| document.mozFullScreen
|| document.webkitIsFullScreen;
var isFullScreen = document.fullScreen ||
document.mozFullScreen ||
document.webkitIsFullScreen;
if (isFullScreen)
videoSpaceHeight = window.innerHeight;
@ -948,8 +954,7 @@ function getCameraVideoSize(videoWidth,
function getDesktopVideoSize(videoWidth,
videoHeight,
videoSpaceWidth,
videoSpaceHeight )
{
videoSpaceHeight) {
if (!videoWidth)
videoWidth = currentVideoWidth;
if (!videoHeight)
@ -1056,8 +1061,7 @@ $(document).ready(function () {
// Set default desktop sharing method
setDesktopSharing(config.desktopSharing);
// Initialize Chrome extension inline installs
if(config.chromeExtensionId)
{
if (config.chromeExtensionId) {
initInlineInstalls();
}
@ -1141,8 +1145,8 @@ function dump(elem, filename){
data["jingle_" + session.sid] = {
updateLog: session.peerconnection.updateLog,
stats: session.peerconnection.stats,
url: window.location.href}
;
url: window.location.href
};
}
});
}
@ -1176,16 +1180,17 @@ function openLockDialog() {
{
title: "Secrect key",
persistent: false
});
}
);
else
$.prompt("This conversation isn't currently protected by a secret key. Only the owner of the conference could set a shared key.",
{
title: "Secrect key",
persistent: false
});
}
else {
if (sharedKey)
);
} else {
if (sharedKey) {
$.prompt("Are you sure you would like to remove your secret key?",
{
title: "Remove secrect key",
@ -1193,14 +1198,14 @@ function openLockDialog() {
buttons: { "Remove": true, "Cancel": false},
defaultButton: 1,
submit: function (e, v, m, f) {
if(v)
{
if (v) {
setSharedKey('');
lockRoom(false);
}
}
});
else
}
);
} else {
$.prompt('<h2>Set a secrect key to lock your room</h2>' +
'<input id="lockKey" type="text" placeholder="your shared key" autofocus>',
{
@ -1211,18 +1216,18 @@ function openLockDialog() {
document.getElementById('lockKey').focus();
},
submit: function (e, v, m, f) {
if(v)
{
if (v) {
var lockKey = document.getElementById('lockKey');
if (lockKey.value)
{
if (lockKey.value) {
setSharedKey(Util.escapeHtml(lockKey.value));
lockRoom(true);
}
}
}
});
}
);
}
}
}
@ -1230,8 +1235,8 @@ function openLockDialog() {
* Opens the invite link dialog.
*/
function openLinkDialog() {
$.prompt('<input id="inviteLinkRef" type="text" value="'
+ encodeURI(roomUrl) + '" onclick="this.select();" readonly>',
$.prompt('<input id="inviteLinkRef" type="text" value="' +
encodeURI(roomUrl) + '" onclick="this.select();" readonly>',
{
title: "Share this link with everyone you want to invite",
persistent: false,
@ -1239,7 +1244,8 @@ function openLinkDialog() {
loaded: function (event) {
document.getElementById('inviteLinkRef').select();
}
});
}
);
}
/**
@ -1258,15 +1264,12 @@ function openSettingsDialog() {
document.getElementById('lockKey').focus();
},
submit: function (e, v, m, f) {
if(v)
{
if ($('#initMuted').is(":checked"))
{
if (v) {
if ($('#initMuted').is(":checked")) {
// it is checked
}
if ($('#requireNicknames').is(":checked"))
{
if ($('#requireNicknames').is(":checked")) {
// it is checked
}
/*
@ -1280,7 +1283,8 @@ function openSettingsDialog() {
*/
}
}
});
}
);
}
/**
@ -1439,7 +1443,6 @@ function showFocusIndicator() {
* @param peerJid peer Jid to check.
*/
function ensurePeerContainerExists(peerJid) {
var peerResource = Strophe.getResourceFromJid(peerJid);
var videoSpanId = 'participant_' + peerResource;
@ -1483,7 +1486,6 @@ function toggleFullScreen() {
var fsElement = document.documentElement;
if (!document.mozFullScreen && !document.webkitIsFullScreen) {
//Enter Full Screen
if (fsElement.mozRequestFullScreen) {
fsElement.mozRequestFullScreen();
@ -1511,13 +1513,13 @@ function showDisplayName(videoSpanId, displayName) {
if (nameSpan.length > 0) {
var nameSpanElement = nameSpan.get(0);
if (nameSpanElement.id === 'localDisplayName'
&& $('#localDisplayName').text() !== displayName)
if (nameSpanElement.id === 'localDisplayName' &&
$('#localDisplayName').text() !== displayName) {
$('#localDisplayName').text(displayName);
else
} else {
$('#' + videoSpanId + '_name').text(displayName);
}
else {
} else {
var editButton = null;
if (videoSpanId === 'localVideoContainer') {
@ -1532,8 +1534,7 @@ function showDisplayName(videoSpanId, displayName) {
if (!editButton) {
nameSpan.id = videoSpanId + '_name';
}
else {
} else {
nameSpan.id = 'localDisplayName';
$('#' + videoSpanId)[0].appendChild(editButton);
@ -1541,9 +1542,9 @@ function showDisplayName(videoSpanId, displayName) {
editableText.className = 'displayname';
editableText.id = 'editDisplayName';
if (displayName.length)
editableText.value
= displayName.substring(0, displayName.indexOf(' (me)'));
if (displayName.length) {
editableText.value = displayName.substring(0, displayName.indexOf(' (me)'));
}
editableText.setAttribute('style', 'display:none;');
editableText.setAttribute('placeholder', 'ex. Jane Pink');
@ -1664,9 +1665,9 @@ $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
function () {
resizeLargeVideoContainer();
positionLarge();
isFullScreen = document.fullScreen
|| document.mozFullScreen
|| document.webkitIsFullScreen;
isFullScreen = document.fullScreen ||
document.mozFullScreen ||
document.webkitIsFullScreen;
if (isFullScreen) {
setView("fullscreen");
@ -1674,7 +1675,8 @@ $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
else {
setView("default");
}
});
}
);
/**
* Sets the current view.

23
chat.js
View File

@ -1,3 +1,4 @@
/* global $, Util, connection, nickname:true, getVideoSize, getVideoPosition, showToolbar, processReplacements */
/**
* Chat related user interface.
*/
@ -82,9 +83,9 @@ var Chat = (function (my) {
var escDisplayName = Util.escapeHtml(displayName);
message = processReplacements(escMessage);
$('#chatconversation').append('<div class="' + divClassName + '"><b>'
+ escDisplayName + ': </b>'
+ message + '</div>');
$('#chatconversation').append('<div class="' + divClassName + '"><b>' +
escDisplayName + ': </b>' +
message + '</div>');
$('#chatconversation').animate(
{ scrollTop: $('#chatconversation')[0].scrollHeight}, 1000);
};
@ -183,7 +184,7 @@ var Chat = (function (my) {
*/
my.setChatConversationMode = function (isConversationMode) {
if (isConversationMode) {
$('#nickname').css({visibility:"hidden"});
$('#nickname').css({visibility: 'hidden'});
$('#chatconversation').css({visibility: 'visible'});
$('#usermsg').css({visibility: 'visible'});
$('#usermsg').focus();
@ -228,7 +229,7 @@ var Chat = (function (my) {
$('#chatconversation').width($('#chatspace').width() - 10);
$('#chatconversation')
.height(window.innerHeight - 10 - parseInt(usermsgHeight));
};
}
/**
* Shows/hides a visual notification, indicating that a message has arrived.
@ -245,15 +246,15 @@ var Chat = (function (my) {
var chatButtonElement
= document.getElementById('chatButton').parentNode;
var leftIndent = (Util.getTextWidth(chatButtonElement)
- Util.getTextWidth(unreadMsgElement))/2;
var topIndent = (Util.getTextHeight(chatButtonElement)
- Util.getTextHeight(unreadMsgElement))/2 - 3;
var leftIndent = (Util.getTextWidth(chatButtonElement) -
Util.getTextWidth(unreadMsgElement)) / 2;
var topIndent = (Util.getTextHeight(chatButtonElement) -
Util.getTextHeight(unreadMsgElement)) / 2 - 3;
unreadMsgElement.setAttribute(
'style',
'top:' + topIndent
+ '; left:' + leftIndent +';');
'top:' + topIndent +
'; left:' + leftIndent + ';');
if (!glower.hasClass('icon-chat-simple')) {
glower.removeClass('icon-chat');

View File

@ -1,3 +1,4 @@
/* global $, config, connection, chrome, alert, getUserMediaWithConstraints, change_local_video, getConferenceHandler */
/**
* Indicates that desktop stream is currently in use(for toggle purpose).
* @type {boolean}
@ -22,6 +23,155 @@ var obtainDesktopStream = null;
*/
var _desktopSharingEnabled = null;
/**
* Method obtains desktop stream from WebRTC 'screen' source.
* Flag 'chrome://flags/#enable-usermedia-screen-capture' must be enabled.
*/
function obtainWebRTCScreen(streamCallback, failCallback) {
getUserMediaWithConstraints(
['screen'],
streamCallback,
failCallback
);
}
/**
* Constructs inline install URL for Chrome desktop streaming extension.
* The 'chromeExtensionId' must be defined in config.js.
* @returns {string}
*/
function getWebStoreInstallUrl()
{
return "https://chrome.google.com/webstore/detail/" + config.chromeExtensionId;
}
/**
* Checks whether extension update is required.
* @param minVersion minimal required version
* @param extVersion current extension version
* @returns {boolean}
*/
function isUpdateRequired(minVersion, extVersion)
{
try
{
var s1 = minVersion.split('.');
var s2 = extVersion.split('.');
var len = Math.max(s1.length, s2.length);
for (var i = 0; i < len; i++)
{
var n1 = 0,
n2 = 0;
if (i < s1.length)
n1 = parseInt(s1[i]);
if (i < s2.length)
n2 = parseInt(s2[i]);
if (isNaN(n1) || isNaN(n2))
{
return true;
}
else if (n1 !== n2)
{
return n1 > n2;
}
}
// will happen if boths version has identical numbers in
// their components (even if one of them is longer, has more components)
return false;
}
catch (e)
{
console.error("Failed to parse extension version", e);
return true;
}
}
function checkExtInstalled(isInstalledCallback) {
if (!chrome.runtime) {
// No API, so no extension for sure
isInstalledCallback(false);
}
chrome.runtime.sendMessage(
config.chromeExtensionId,
{ getVersion: true },
function (response) {
if (!response || !response.version) {
// Communication failure - assume that no endpoint exists
console.warn("Extension not installed?: " + chrome.runtime.lastError);
isInstalledCallback(false);
} else {
// Check installed extension version
var extVersion = response.version;
console.log('Extension version is: ' + extVersion);
var updateRequired = isUpdateRequired(config.minChromeExtVersion, extVersion);
if (updateRequired) {
alert(
'Jitsi Desktop Streamer requires update. ' +
'Changes will take effect after next Chrome restart.');
}
isInstalledCallback(!updateRequired);
}
}
);
}
function doGetStreamFromExtension(streamCallback, failCallback) {
// Sends 'getStream' msg to the extension. Extension id must be defined in the config.
chrome.runtime.sendMessage(
config.chromeExtensionId,
{ getStream: true},
function (response) {
if (!response) {
failCallback(chrome.runtime.lastError);
return;
}
console.log("Response from extension: " + response);
if (response.streamId) {
getUserMediaWithConstraints(
['desktop'],
function (stream) {
streamCallback(stream);
},
failCallback,
null, null, null,
response.streamId);
} else {
failCallback("Extension failed to get the stream");
}
}
);
}
/**
* Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop' stream for returned stream token.
*/
function obtainScreenFromExtension(streamCallback, failCallback) {
checkExtInstalled(
function (isInstalled) {
if (isInstalled) {
doGetStreamFromExtension(streamCallback, failCallback);
} else {
chrome.webstore.install(
getWebStoreInstallUrl(),
function (arg) {
console.log("Extension installed successfully", arg);
// We need to reload the page in order to get the access to chrome.runtime
window.location.reload(false);
},
function (arg) {
console.log("Failed to install the extension", arg);
failCallback(arg);
}
);
}
}
);
}
/**
* @returns {boolean} <tt>true</tt> if desktop sharing feature is available and enabled.
*/
@ -41,6 +191,14 @@ function isDesktopSharingEnabled() {
return _desktopSharingEnabled;
}
function showDesktopSharingButton() {
if (isDesktopSharingEnabled()) {
$('#desktopsharing').css({display: "inline"});
} else {
$('#desktopsharing').css({display: "none"});
}
}
/**
* Call this method to toggle desktop sharing feature.
* @param method pass "ext" to use chrome extension for desktop capture(chrome extension required),
@ -66,14 +224,6 @@ function setDesktopSharing(method) {
showDesktopSharingButton();
}
function showDesktopSharingButton() {
if(isDesktopSharingEnabled()) {
$('#desktopsharing').css( {display:"inline"} );
} else {
$('#desktopsharing').css( {display:"none"} );
}
}
/**
* Initializes <link rel=chrome-webstore-item /> with extension id set in config.js to support inline installs.
* Host site must be selected as main website of published extension.
@ -83,14 +233,34 @@ function initInlineInstalls()
$("link[rel=chrome-webstore-item]").attr("href", getWebStoreInstallUrl());
}
/**
* Constructs inline install URL for Chrome desktop streaming extension.
* The 'chromeExtensionId' must be defined in config.js.
* @returns {string}
*/
function getWebStoreInstallUrl()
{
return "https://chrome.google.com/webstore/detail/" + config.chromeExtensionId;
function getSwitchStreamFailed(error) {
console.error("Failed to obtain the stream to switch to", error);
switchInProgress = false;
}
function streamSwitchDone() {
//window.setTimeout(
// function () {
switchInProgress = false;
// }, 100
//);
}
function newStreamCreated(stream) {
var oldStream = connection.jingle.localVideo;
change_local_video(stream, !isUsingScreenStream);
var conferenceHandler = getConferenceHandler();
if (conferenceHandler) {
// FIXME: will block switchInProgress on true value in case of exception
conferenceHandler.switchStreams(stream, oldStream, streamSwitchDone);
} else {
// We are done immediately
console.error("No conference handler");
streamSwitchDone();
}
}
/*
@ -135,170 +305,3 @@ function toggleScreenSharing() {
}
}
function getSwitchStreamFailed(error) {
console.error("Failed to obtain the stream to switch to", error);
switchInProgress = false;
}
function newStreamCreated(stream) {
var oldStream = connection.jingle.localVideo;
change_local_video(stream, !isUsingScreenStream);
var conferenceHandler = getConferenceHandler();
if(conferenceHandler) {
// FIXME: will block switchInProgress on true value in case of exception
conferenceHandler.switchStreams(stream, oldStream, streamSwitchDone);
} else {
// We are done immediately
console.error("No conference handler");
streamSwitchDone();
}
}
function streamSwitchDone() {
//window.setTimeout(
// function() {
switchInProgress = false;
// }, 100
//);
}
/**
* Method obtains desktop stream from WebRTC 'screen' source.
* Flag 'chrome://flags/#enable-usermedia-screen-capture' must be enabled.
*/
function obtainWebRTCScreen(streamCallback, failCallback) {
getUserMediaWithConstraints(
['screen'],
streamCallback,
failCallback
);
}
/**
* Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop' stream for returned stream token.
*/
function obtainScreenFromExtension(streamCallback, failCallback) {
checkExtInstalled(
function(isInstalled) {
if(isInstalled) {
doGetStreamFromExtension(streamCallback, failCallback);
} else {
chrome.webstore.install(
getWebStoreInstallUrl(),
function(arg) {
console.log("Extension installed successfully", arg);
// We need to reload the page in order to get the access to chrome.runtime
window.location.reload(false);
},
function(arg) {
console.log("Failed to install the extension", arg);
failCallback(arg);
}
);
}
}
);
}
function checkExtInstalled(isInstalledCallback) {
if(!chrome.runtime) {
// No API, so no extension for sure
isInstalledCallback(false);
}
chrome.runtime.sendMessage(
config.chromeExtensionId,
{ getVersion: true },
function(response){
if(!response || !response.version) {
// Communication failure - assume that no endpoint exists
console.warn("Extension not installed?: "+chrome.runtime.lastError);
isInstalledCallback(false);
} else {
// Check installed extension version
var extVersion = response.version;
console.log('Extension version is: '+extVersion);
var updateRequired = isUpdateRequired(config.minChromeExtVersion, extVersion);
if(updateRequired) {
alert(
'Jitsi Desktop Streamer requires update. ' +
'Changes will take effect after next Chrome restart.' );
}
isInstalledCallback(!updateRequired);
}
}
);
}
/**
* Checks whether extension update is required.
* @param minVersion minimal required version
* @param extVersion current extension version
* @returns {boolean}
*/
function isUpdateRequired(minVersion, extVersion)
{
try
{
var s1 = minVersion.split('.');
var s2 = extVersion.split('.');
var len = Math.max(s1.length, s2.length);
for(var i = 0; i < len; i++)
{
var n1=0,n2=0;
if(i < s1.length)
n1 = parseInt(s1[i]);
if(i < s2.length)
n2 = parseInt(s2[i]);
if(isNaN(n1) || isNaN(n2))
{
return true;
}
else if(n1 !== n2)
{
return n1 > n2;
}
}
// will happen if boths version has identical numbers in
// their components (even if one of them is longer, has more components)
return false;
}
catch(e)
{
console.error("Failed to parse extension version", e);
return true;
}
}
function doGetStreamFromExtension(streamCallback, failCallback) {
// Sends 'getStream' msg to the extension. Extension id must be defined in the config.
chrome.runtime.sendMessage(
config.chromeExtensionId,
{ getStream: true},
function(response) {
if(!response) {
failCallback(chrome.runtime.lastError);
return;
}
console.log("Response from extension: "+response);
if(response.streamId) {
getUserMediaWithConstraints(
['desktop'],
function(stream) {
streamCallback(stream);
},
failCallback,
null, null, null,
response.streamId);
} else {
failCallback("Extension failed to get the stream");
}
}
);
}

View File

@ -1,3 +1,4 @@
/* global Strophe */
Strophe.addConnectionPlugin('logger', {
// logs raw stanzas and makes them available for download as JSON
connection: null,

View File

@ -1,3 +1,4 @@
/* global $, config, Prezi, Util, connection, setLargeVideoVisible, dockToolbar */
var Etherpad = (function (my) {
var etherpadName = null;
var etherpadIFrame = null;
@ -15,8 +16,8 @@ var Etherpad = (function (my) {
if (!name) {
// In case we're the focus we generate the name.
etherpadName = Math.random().toString(36).substring(7)
+ '_' + (new Date().getTime()).toString();
etherpadName = Math.random().toString(36).substring(7) +
'_' + (new Date().getTime()).toString();
shareEtherpad();
}
else
@ -41,9 +42,9 @@ var Etherpad = (function (my) {
if ($('#etherpad>iframe').css('visibility') === 'hidden') {
largeVideo.fadeOut(300, function () {
if (Prezi.isPresentationVisible())
if (Prezi.isPresentationVisible()) {
largeVideo.css({opacity: '0'});
else {
} else {
setLargeVideoVisible(false);
dockToolbar(true);
}

View File

@ -1,3 +1,4 @@
/* global $ */
/**
* Utility functions.
*/
@ -50,9 +51,7 @@ var Util = (function (my) {
* Returns the available video width.
*/
my.getAvailableVideoWidth = function () {
var chatspaceWidth = $('#chatspace').is(":visible")
? $('#chatspace').width()
: 0;
var chatspaceWidth = $('#chatspace').is(":visible") ? $('#chatspace').width() : 0;
return window.innerWidth - chatspaceWidth;
};