Browse Source

Fixed jshint latedef and strict errors.

pull/247/head
Simon Eisenmann 10 years ago
parent
commit
a6ded93b2f
  1. 3
      src/hooks/pre-commit.hook
  2. 1
      static/js/base.js
  3. 18
      static/js/directives/buddylist.js
  4. 27
      static/js/directives/buddypicturecapture.js
  5. 24
      static/js/directives/buddypictureupload.js
  6. 22
      static/js/directives/youtubevideo.js
  7. 3
      static/js/mediastream/peerscreenshare.js
  8. 3
      static/js/mediastream/peerxfer.js
  9. 4
      static/js/mediastream/tokens.js
  10. 1
      static/js/mediastream/utils.js
  11. 16
      static/js/services/animationframe.js
  12. 2
      static/js/services/desktopnotify.js
  13. 13
      static/js/services/filedownload.js
  14. 5
      static/js/services/mediastream.js
  15. 20
      static/js/services/rooms.js

3
src/hooks/pre-commit.hook

@ -27,7 +27,6 @@ echo "==========================================================================
fi fi
done done
for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.js$"` ; do for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.js$"` ; do
case "$file" in case "$file" in
*/libs/*) */libs/*)
@ -39,7 +38,7 @@ for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "
*) *)
echo "Checking ${file}" echo "Checking ${file}"
nf=`git checkout-index --temp ${file} | cut -f 1` nf=`git checkout-index --temp ${file} | cut -f 1`
jshint --config .jshint "${nf}" PATH="node_modules/.bin:${PATH}" jshint --config .jshint "${nf}"
r=$? r=$?
rm "${nf}" rm "${nf}"
if [ $r != 0 ] ; then if [ $r != 0 ] ; then

1
static/js/base.js

@ -19,6 +19,7 @@
* *
*/ */
"use strict";
define([ // Helper module to put non dependency base libraries together. define([ // Helper module to put non dependency base libraries together.
'modernizr', 'modernizr',
'moment', 'moment',

18
static/js/directives/buddylist.js

@ -29,10 +29,19 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) { var controller = ['$scope', '$element', '$attrs', function($scope, $element, $attrs) {
var buddylist = $scope.buddylist = buddyList.buddylist($element, $scope, {});
var onJoined = _.bind(buddylist.onJoined, buddylist);
var onLeft = _.bind(buddylist.onLeft, buddylist);
var onStatus = _.bind(buddylist.onStatus, buddylist);
var onContactAdded = _.bind(buddylist.onContactAdded, buddylist);
var onContactRemoved = _.bind(buddylist.onContactRemoved, buddylist);
var onContactUpdated = _.bind(buddylist.onContactUpdated, buddylist);
var inRoom = false;
$scope.layout.buddylist = false; $scope.layout.buddylist = false;
$scope.layout.buddylistAutoHide = true; $scope.layout.buddylistAutoHide = true;
var inRoom = false;
var updateBuddyListVisibility = function() { var updateBuddyListVisibility = function() {
if (inRoom && !$scope.peer) { if (inRoom && !$scope.peer) {
$scope.layout.buddylist = true; $scope.layout.buddylist = true;
@ -87,13 +96,6 @@ define(['underscore', 'text!partials/buddylist.html'], function(_, template) {
}; };
var buddylist = $scope.buddylist = buddyList.buddylist($element, $scope, {});
var onJoined = _.bind(buddylist.onJoined, buddylist);
var onLeft = _.bind(buddylist.onLeft, buddylist);
var onStatus = _.bind(buddylist.onStatus, buddylist);
var onContactAdded = _.bind(buddylist.onContactAdded, buddylist);
var onContactRemoved = _.bind(buddylist.onContactRemoved, buddylist);
var onContactUpdated = _.bind(buddylist.onContactUpdated, buddylist);
api.e.on("received.userleftorjoined", function(event, dataType, data) { api.e.on("received.userleftorjoined", function(event, dataType, data) {
if (dataType === "Left") { if (dataType === "Left") {
onLeft(data); onLeft(data);

27
static/js/directives/buddypicturecapture.js

@ -27,6 +27,17 @@ define(['jquery', 'underscore', 'text!partials/buddypicturecapture.html'], funct
var controller = ['$scope', 'safeApply', '$timeout', '$q', "mediaDevices", "userMedia", function($scope, safeApply, $timeout, $q, mediaDevices, userMedia) { var controller = ['$scope', 'safeApply', '$timeout', '$q', "mediaDevices", "userMedia", function($scope, safeApply, $timeout, $q, mediaDevices, userMedia) {
var localStream = null;
var delayToTakePicture = 3000;
var countDownFrom = 3;
var takePictureCountDown;
var writeVideoToCanvas;
var writePreviewPic;
var makePicture;
var videoStop;
var videoStart;
// Buddy picutre capture size. // Buddy picutre capture size.
$scope.captureSize = { $scope.captureSize = {
width: 128, width: 128,
@ -41,12 +52,8 @@ define(['jquery', 'underscore', 'text!partials/buddypicturecapture.html'], funct
$scope.canvasPic = null; $scope.canvasPic = null;
$scope.canvasPrev = null; $scope.canvasPrev = null;
var localStream = null;
var delayToTakePicture = 3000;
var countDownFrom = 3;
// Counts down from start to 1 // Counts down from start to 1
var takePictureCountDown = function(start, delayTotal) { takePictureCountDown = function(start, delayTotal) {
$scope.countingDown = true; $scope.countingDown = true;
$scope.countdown = {}; $scope.countdown = {};
$scope.countdown.num = start; $scope.countdown.num = start;
@ -63,7 +70,7 @@ define(['jquery', 'underscore', 'text!partials/buddypicturecapture.html'], funct
} }
}; };
var writeVideoToCanvas = function(canvas) { writeVideoToCanvas = function(canvas) {
var videoWidth = $scope.video.videoWidth; var videoWidth = $scope.video.videoWidth;
var videoHeight = $scope.video.videoHeight; var videoHeight = $scope.video.videoHeight;
@ -89,12 +96,12 @@ define(['jquery', 'underscore', 'text!partials/buddypicturecapture.html'], funct
}; };
var writePreviewPic = function() { writePreviewPic = function() {
writeVideoToCanvas($scope.canvasPrev); writeVideoToCanvas($scope.canvasPrev);
$scope.preview = $scope.canvasPrev.toDataURL("image/jpeg"); $scope.preview = $scope.canvasPrev.toDataURL("image/jpeg");
}; };
var makePicture = function(stream, cntFrom, delayTotal) { makePicture = function(stream, cntFrom, delayTotal) {
takePictureCountDown(cntFrom, delayTotal); takePictureCountDown(cntFrom, delayTotal);
$timeout(function() { $timeout(function() {
$scope.flash.addClass("flash"); $scope.flash.addClass("flash");
@ -107,7 +114,7 @@ define(['jquery', 'underscore', 'text!partials/buddypicturecapture.html'], funct
}, delayTotal); }, delayTotal);
}; };
var videoStop = function(stream, video) { videoStop = function(stream, video) {
if (stream) { if (stream) {
video.pause(); video.pause();
userMedia.stopUserMediaStream(stream); userMedia.stopUserMediaStream(stream);
@ -115,7 +122,7 @@ define(['jquery', 'underscore', 'text!partials/buddypicturecapture.html'], funct
} }
}; };
var videoStart = function() { videoStart = function() {
$scope.waitingForPermission = true; $scope.waitingForPermission = true;
var videoConstraints = true; var videoConstraints = true;
var videoAllowed = $q.defer(); var videoAllowed = $q.defer();

24
static/js/directives/buddypictureupload.js

@ -39,8 +39,16 @@ define(['jquery', 'underscore', 'text!partials/buddypictureupload.html'], functi
var previewWidth = 205; var previewWidth = 205;
var previewHeight = 205; var previewHeight = 205;
$scope.maxUploadMb = 8; var maxUploadBytes = 8388608; // 8MB
var maxUploadBytes = $scope.maxUploadMb * 1024 * 1024;
var completedUpload;
var setUploadImageDimension;
var getAutoFitDimensions;
var getScaledDimensions;
var writePictureToCanvas;
var clearPicture;
$scope.maxUploadMb = maxUploadBytes / 1024 / 1024;
$scope.showUploadPicture = false; $scope.showUploadPicture = false;
$scope.previewUpload = false; $scope.previewUpload = false;
$scope.imgData = null; $scope.imgData = null;
@ -54,11 +62,11 @@ define(['jquery', 'underscore', 'text!partials/buddypictureupload.html'], functi
}; };
$scope.aspectRatio = 1; $scope.aspectRatio = 1;
var completedUpload = function() { completedUpload = function() {
$scope.upload.status = 100; $scope.upload.status = 100;
}; };
var setUploadImageDimension = function(data) { setUploadImageDimension = function(data) {
$scope.prevImage.onload = function() { $scope.prevImage.onload = function() {
// clear old dimensions // clear old dimensions
this.style.cssText = null; this.style.cssText = null;
@ -76,7 +84,7 @@ define(['jquery', 'underscore', 'text!partials/buddypictureupload.html'], functi
}; };
// Auto fit by smallest dimension // Auto fit by smallest dimension
var getAutoFitDimensions = function(from, to) { getAutoFitDimensions = function(from, to) {
if (!from.width && !from.height && !to.width && !to.height) { if (!from.width && !from.height && !to.width && !to.height) {
return null; return null;
} }
@ -94,7 +102,7 @@ define(['jquery', 'underscore', 'text!partials/buddypictureupload.html'], functi
}; };
// (image, canvas) -> object // (image, canvas) -> object
var getScaledDimensions = function(from, to) { getScaledDimensions = function(from, to) {
if (!from.style.width && !from.style.height && !to.width && !to.height) { if (!from.style.width && !from.style.height && !to.width && !to.height) {
return null; return null;
} }
@ -120,7 +128,7 @@ define(['jquery', 'underscore', 'text!partials/buddypictureupload.html'], functi
return {width: width, height: height, x: x, y: y}; return {width: width, height: height, x: x, y: y};
}; };
var writePictureToCanvas = function(canvas) { writePictureToCanvas = function(canvas) {
var img = $scope.prevImage; var img = $scope.prevImage;
var dim = getScaledDimensions(img, canvas); var dim = getScaledDimensions(img, canvas);
var context = canvas.getContext("2d"); var context = canvas.getContext("2d");
@ -129,7 +137,7 @@ define(['jquery', 'underscore', 'text!partials/buddypictureupload.html'], functi
//console.log('writeUploadToCanvas', dim); //console.log('writeUploadToCanvas', dim);
}; };
var clearPicture = function() { clearPicture = function() {
$(".file-input-name").empty(); $(".file-input-name").empty();
$scope.imgData = null; $scope.imgData = null;
$scope.prevImage.src = ""; $scope.prevImage.src = "";

22
static/js/directives/youtubevideo.js

@ -106,6 +106,16 @@ define(['require', 'jquery', 'underscore', 'moment', 'text!partials/youtubevideo
var initialState = null; var initialState = null;
var sandboxApi = null; var sandboxApi = null;
var peers = {};
var youtubevideos = [];
var youtubevideoCount = 0;
var currentToken = null;
var tokenHandler = null;
var mediaStreamSendYouTubeVideo;
var connector;
var updater;
var createSandboxApi = function(force, template) { var createSandboxApi = function(force, template) {
if (sandboxApi && force) { if (sandboxApi && force) {
sandboxApi.destroy(); sandboxApi.destroy();
@ -475,13 +485,7 @@ define(['require', 'jquery', 'underscore', 'moment', 'text!partials/youtubevideo
} }
}); });
var peers = {}; mediaStreamSendYouTubeVideo = function(peercall, token, params) {
var youtubevideos = [];
var youtubevideoCount = 0;
var currentToken = null;
var tokenHandler = null;
var mediaStreamSendYouTubeVideo = function(peercall, token, params) {
mediaStream.api.apply("sendYouTubeVideo", { mediaStream.api.apply("sendYouTubeVideo", {
send: function(type, data) { send: function(type, data) {
if (!peercall.peerconnection.datachannelReady) { if (!peercall.peerconnection.datachannelReady) {
@ -495,7 +499,7 @@ define(['require', 'jquery', 'underscore', 'moment', 'text!partials/youtubevideo
})(peercall.id, token, params); })(peercall.id, token, params);
}; };
var connector = function(token, peercall) { connector = function(token, peercall) {
if (peers.hasOwnProperty(peercall.id)) { if (peers.hasOwnProperty(peercall.id)) {
// Already got a connection. // Already got a connection.
return; return;
@ -522,7 +526,7 @@ define(['require', 'jquery', 'underscore', 'moment', 'text!partials/youtubevideo
}; };
// Updater function to bring in new calls. // Updater function to bring in new calls.
var updater = function(event, state, currentcall) { updater = function(event, state, currentcall) {
switch (state) { switch (state) {
case "completed": case "completed":
case "connected": case "connected":

3
static/js/mediastream/peerscreenshare.js

@ -23,6 +23,7 @@
define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens'], function($, _, PeerCall, tokens) { define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens'], function($, _, PeerCall, tokens) {
var screenshareIds = 0; var screenshareIds = 0;
var PeerScreenshare;
// Register ourselves for tokens. // Register ourselves for tokens.
tokens.registerHandler("screenshare", function(webrtc, id, token, from) { tokens.registerHandler("screenshare", function(webrtc, id, token, from) {
@ -32,7 +33,7 @@ define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens'], f
}); });
// PeerScreenshare inherits from PeerCall. // PeerScreenshare inherits from PeerCall.
var PeerScreenshare = function(webrtc, id, token, to) { PeerScreenshare = function(webrtc, id, token, to) {
if (id === null) { if (id === null) {
id = screenshareIds++; id = screenshareIds++;

3
static/js/mediastream/peerxfer.js

@ -23,6 +23,7 @@
define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens', 'webrtc.adapter'], function($, _, PeerCall, tokens) { define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens', 'webrtc.adapter'], function($, _, PeerCall, tokens) {
var xfersIds = 0; var xfersIds = 0;
var PeerXfer;
// Register ourselves for tokens. // Register ourselves for tokens.
tokens.registerHandler("xfer", function(webrtc, id, token, from) { tokens.registerHandler("xfer", function(webrtc, id, token, from) {
@ -32,7 +33,7 @@ define(['jquery', 'underscore', 'mediastream/peercall', 'mediastream/tokens', 'w
}); });
// PeerXfer inherits from PeerCall. // PeerXfer inherits from PeerCall.
var PeerXfer = function(webrtc, id, token, to) { PeerXfer = function(webrtc, id, token, to) {
if (id === null) { if (id === null) {
id = xfersIds++; id = xfersIds++;

4
static/js/mediastream/tokens.js

@ -22,6 +22,8 @@
"use strict"; "use strict";
define(['jquery', 'underscore'], function($, _) { define(['jquery', 'underscore'], function($, _) {
var tokens;
var Token = function(handlerKey) { var Token = function(handlerKey) {
this.e = $({}); this.e = $({});
this.count = 0; this.count = 0;
@ -179,7 +181,7 @@ define(['jquery', 'underscore'], function($, _) {
}; };
var tokens = new Tokens(); tokens = new Tokens();
return tokens; return tokens;
}); });

1
static/js/mediastream/utils.js

@ -41,6 +41,7 @@
"use strict"; "use strict";
define([], function() { define([], function() {
/*jshint strict: true, latedef: false */
function trace(text) { function trace(text) {
// noop // noop

16
static/js/services/animationframe.js

@ -28,20 +28,26 @@ define(["underscore", "rAF"], function(_) {
var requestAnimationFrame = $window.requestAnimationFrame; var requestAnimationFrame = $window.requestAnimationFrame;
var registry = []; var registry = [];
var caller = function(f) { var caller;
var runner;
var timer;
var worker;
var animationFrame;
caller = function(f) {
f(); f();
}; };
var runner = function(c) { runner = function(c) {
registry.forEach(caller); registry.forEach(caller);
requestAnimationFrame(worker) requestAnimationFrame(worker)
} }
var timer = $window.setTimeout; timer = $window.setTimeout;
var worker = function() { worker = function() {
timer(runner, 100); timer(runner, 100);
}; };
// Public api. // Public api.
var animationFrame = { animationFrame = {
register: function(f) { register: function(f) {
registry.push(f); registry.push(f);
} }

2
static/js/services/desktopnotify.js

@ -74,7 +74,7 @@ define(['jquery', 'underscore', 'desktop-notify', 'webrtc.adapter'], function($,
// on Android, where Notifications raise an exception. // on Android, where Notifications raise an exception.
// See https://code.google.com/p/chromium/issues/detail?id=481856 // See https://code.google.com/p/chromium/issues/detail?id=481856
try { try {
/*jshint nonew: false */ /*jshint strict: true, nonew: false */
new $window.Notification(''); new $window.Notification('');
} catch(e) { } catch(e) {
if (e.name == 'TypeError') { if (e.name == 'TypeError') {

13
static/js/services/filedownload.js

@ -26,8 +26,9 @@ define(["jquery", "underscore"], function($, _) {
var downloads = 0; var downloads = 0;
var Session = function(id, token, scope) { var Session = function(fileDownload, id, token, scope) {
this.fileDownload = fileDownload;
this.id = id; this.id = id;
this.token = token; this.token = token;
this.scope = scope; this.scope = scope;
@ -175,7 +176,7 @@ define(["jquery", "underscore"], function($, _) {
session.done(this); session.done(this);
return; return;
} }
fileDownload.sendRequest(xfer, this.chunk++); this.fileDownload.sendRequest(xfer, this.chunk++);
}, job); }, job);
//console.log("Starting new job", job, this.fragments, xfer.id); //console.log("Starting new job", job, this.fragments, xfer.id);
xfer.e.on("sessionData", _.bind(this.handleData, this, job)); xfer.e.on("sessionData", _.bind(this.handleData, this, job));
@ -287,7 +288,7 @@ define(["jquery", "underscore"], function($, _) {
FileDownload.prototype.createSession = function(scope, token) { FileDownload.prototype.createSession = function(scope, token) {
var id = Session.makeId(token, this.downloads++); var id = Session.makeId(token, this.downloads++);
var session = this.sessions[id] = new Session(id, token, scope); var session = this.sessions[id] = new Session(this, id, token, scope);
//console.log("Created new file download session", id, session); //console.log("Created new file download session", id, session);
return session; return session;
}; };
@ -330,11 +331,7 @@ define(["jquery", "underscore"], function($, _) {
}; };
return new FileDownload();
// Create signleton.
var fileDownload = new FileDownload();
return fileDownload;
}]; }];

5
static/js/services/mediastream.js

@ -252,8 +252,9 @@ define([
}, 1000); }, 1000);
if (context.Cfg.Tokens) { if (context.Cfg.Tokens) {
var prompt, check;
var storedCode = localStorage.getItem("mediastream-access-code"); var storedCode = localStorage.getItem("mediastream-access-code");
var prompt = function() { prompt = function() {
alertify.dialog.prompt(translation._("Access code required"), function(code) { alertify.dialog.prompt(translation._("Access code required"), function(code) {
if (!code) { if (!code) {
prompt(); prompt();
@ -264,7 +265,7 @@ define([
}, prompt); }, prompt);
}; };
var url = restURL.api("tokens"); var url = restURL.api("tokens");
var check = function(code) { check = function(code) {
$http({ $http({
method: "POST", method: "POST",
url: url, url: url,

20
static/js/services/rooms.js

@ -37,7 +37,14 @@ define([
var canJoinRooms = !mediaStream.config.AuthorizeRoomJoin; var canJoinRooms = !mediaStream.config.AuthorizeRoomJoin;
var canCreateRooms = canJoinRooms ? !mediaStream.config.AuthorizeRoomCreation : false; var canCreateRooms = canJoinRooms ? !mediaStream.config.AuthorizeRoomCreation : false;
var joinFailed = function(error) { var rooms;
var joinFailed;
var joinRequestedRoom;
var setCurrentRoom;
var updateRoom;
var applyRoomUpdate;
joinFailed = function(error) {
setCurrentRoom(null); setCurrentRoom(null);
switch(error.Code) { switch(error.Code) {
@ -70,7 +77,7 @@ define([
} }
}; };
var joinRequestedRoom = function() { joinRequestedRoom = function() {
if (!connector.connected || appData.authorizing()) { if (!connector.connected || appData.authorizing()) {
// Do nothing while not connected or authorizing. // Do nothing while not connected or authorizing.
return; return;
@ -95,7 +102,7 @@ define([
} }
}; };
var setCurrentRoom = function(room) { setCurrentRoom = function(room) {
if (room === currentRoom) { if (room === currentRoom) {
return; return;
} }
@ -112,13 +119,13 @@ define([
} }
}; };
var updateRoom = function(room) { updateRoom = function(room) {
var response = $q.defer(); var response = $q.defer();
api.requestRoomUpdate(room, response.resolve, response.reject); api.requestRoomUpdate(room, response.resolve, response.reject);
return response.promise.then(applyRoomUpdate); return response.promise.then(applyRoomUpdate);
}; };
var applyRoomUpdate = function(room) { applyRoomUpdate = function(room) {
if (room.Credentials) { if (room.Credentials) {
roompin.update(currentRoom.Name, room.Credentials.PIN); roompin.update(currentRoom.Name, room.Credentials.PIN);
delete room.Credentials; delete room.Credentials;
@ -169,7 +176,8 @@ define([
} }
}); });
var rooms = { // Public API.
rooms = {
inDefaultRoom: function() { inDefaultRoom: function() {
return (currentRoom !== null ? currentRoom.Name : requestedRoomName) === ""; return (currentRoom !== null ? currentRoom.Name : requestedRoomName) === "";
}, },

Loading…
Cancel
Save