Browse Source

fix errors reported by jshint

master
Philipp Hancke 10 years ago
parent
commit
78c8f43c3d
6 changed files with 497 additions and 490 deletions
  1. 247
    245
      app.js
  2. 29
    28
      chat.js
  3. 198
    195
      desktopsharing.js
  4. 1
    0
      estos_log.js
  5. 13
    12
      etherpad.js
  6. 9
    10
      util.js

+ 247
- 245
app.js View File

@@ -24,12 +24,12 @@ var currentVideoWidth = null;
24 24
 var currentVideoHeight = null;
25 25
 /**
26 26
  * Method used to calculate large video size.
27
- * @type {function()}
27
+ * @type {function ()}
28 28
  */
29 29
 var getVideoSize;
30 30
 /**
31 31
  * Method used to get large video position.
32
- * @type {function()}
32
+ * @type {function ()}
33 33
  */
34 34
 var getVideoPosition;
35 35
 
@@ -40,9 +40,11 @@ function init() {
40 40
     if (RTC === null) {
41 41
         window.location.href = 'webrtcrequired.html';
42 42
         return;
43
+        /*
43 44
     } else if (RTC.browser !== 'chrome') {
44 45
         window.location.href = 'chromeonly.html';
45 46
         return;
47
+        */
46 48
     }
47 49
 
48 50
     connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
@@ -69,9 +71,9 @@ function init() {
69 71
             if (config.useStunTurn) {
70 72
                 connection.jingle.getStunAndTurnCredentials();
71 73
             }
72
-            obtainAudioAndVideoPermissions(function(){
73
-                getUserMediaWithConstraints( ['audio'], audioStreamReady,
74
-                    function(error){
74
+            obtainAudioAndVideoPermissions(function () {
75
+                getUserMediaWithConstraints(['audio'], audioStreamReady,
76
+                    function (error) {
75 77
                         console.error('failed to obtain audio stream - stop', error);
76 78
                     });
77 79
             });
@@ -88,20 +90,20 @@ function init() {
88 90
  * We first ask for audio and video combined stream in order to get permissions and not to ask twice.
89 91
  * Then we dispose the stream and continue with separate audio, video streams(required for desktop sharing).
90 92
  */
91
-function obtainAudioAndVideoPermissions(callback){
93
+function obtainAudioAndVideoPermissions(callback) {
92 94
     // This makes sense only on https sites otherwise we'll be asked for permissions every time
93
-    if(location.protocol !== 'https:') {
95
+    if (location.protocol !== 'https:') {
94 96
         callback();
95 97
         return;
96 98
     }
97 99
     // Get AV
98 100
     getUserMediaWithConstraints(
99 101
         ['audio', 'video'],
100
-        function(avStream) {
102
+        function (avStream) {
101 103
             avStream.stop();
102 104
             callback();
103 105
         },
104
-        function(error){
106
+        function (error) {
105 107
             console.error('failed to obtain audio/video stream - stop', error);
106 108
         });
107 109
 }
@@ -110,8 +112,8 @@ function audioStreamReady(stream) {
110 112
 
111 113
     change_local_audio(stream);
112 114
 
113
-    if(RTC.browser !== 'firefox') {
114
-        getUserMediaWithConstraints( ['video'], videoStreamReady, videoStreamFailed, config.resolution || '360' );
115
+    if (RTC.browser !== 'firefox') {
116
+        getUserMediaWithConstraints(['video'], videoStreamReady, videoStreamFailed, config.resolution || '360');
115 117
     } else {
116 118
         doJoin();
117 119
     }
@@ -169,7 +171,7 @@ function doJoin() {
169 171
             roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
170 172
         }
171 173
     } else {
172
-        roomjid += '/' + Strophe.getNodeFromJid(connection.jid).substr(0,8);
174
+        roomjid += '/' + Strophe.getNodeFromJid(connection.jid).substr(0, 8);
173 175
     }
174 176
     connection.emuc.doJoin(roomjid);
175 177
 }
@@ -186,7 +188,7 @@ function change_local_video(stream, flipX) {
186 188
     connection.jingle.localVideo = stream;
187 189
 
188 190
     var localVideo = document.createElement('video');
189
-    localVideo.id = 'localVideo_'+stream.id;
191
+    localVideo.id = 'localVideo_' + stream.id;
190 192
     localVideo.autoplay = true;
191 193
     localVideo.volume = 0; // is it required if audio is separated ?
192 194
     localVideo.oncontextmenu = function () { return false; };
@@ -196,7 +198,9 @@ function change_local_video(stream, flipX) {
196 198
 
197 199
     var localVideoSelector = $('#' + localVideo.id);
198 200
     // Add click handler
199
-    localVideoSelector.click(function () { handleVideoThumbClicked(localVideo.src); } );
201
+    localVideoSelector.click(function () {
202
+        handleVideoThumbClicked(localVideo.src);
203
+    });
200 204
     // Add stream ended handler
201 205
     stream.onended = function () {
202 206
         localVideoContainer.removeChild(localVideo);
@@ -204,7 +208,7 @@ function change_local_video(stream, flipX) {
204 208
     };
205 209
     // Flip video x axis if needed
206 210
     flipXLocalVideo = flipX;
207
-    if(flipX) {
211
+    if (flipX) {
208 212
         localVideoSelector.addClass("flipVideoX");
209 213
     }
210 214
     // Attach WebRTC stream
@@ -216,7 +220,7 @@ function change_local_video(stream, flipX) {
216 220
 
217 221
 $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
218 222
     function waitForRemoteVideo(selector, sid, ssrc) {
219
-        if(selector.removed) {
223
+        if (selector.removed) {
220 224
             console.warn("media removed before had started", selector);
221 225
             return;
222 226
         }
@@ -230,7 +234,7 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
230 234
 
231 235
             // FIXME: add a class that will associate peer Jid, video.src, it's ssrc and video type
232 236
             //        in order to get rid of too many maps
233
-            if(ssrc) {
237
+            if (ssrc) {
234 238
                 videoSrcToSsrc[sel.attr('src')] = ssrc;
235 239
             } else {
236 240
                 console.warn("No ssrc given for video", sel);
@@ -250,7 +254,7 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
250 254
         var ssrclines = SDPUtil.find_lines(sess.peerconnection.remoteDescription.sdp, 'a=ssrc');
251 255
         ssrclines = ssrclines.filter(function (line) {
252 256
             return line.indexOf('mslabel:' + data.stream.label) !== -1;
253
-                                     });
257
+        });
254 258
         if (ssrclines.length) {
255 259
             thessrc = ssrclines[0].substring(7).split(' ')[0];
256 260
             // ok to overwrite the one from focus? might save work in colibri.js
@@ -305,7 +309,7 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
305 309
     sel.hide();
306 310
     RTC.attachMediaStream(sel, data.stream);
307 311
 
308
-    if(isVideo) {
312
+    if (isVideo) {
309 313
         waitForRemoteVideo(sel, sid, thessrc);
310 314
     }
311 315
 
@@ -316,9 +320,9 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
316 320
         sel.removed = true;
317 321
         sel.remove();
318 322
 
319
-        var audioCount = $('#'+container.id+'>audio').length;
320
-        var videoCount = $('#'+container.id+'>video').length;
321
-        if(!audioCount && !videoCount) {
323
+        var audioCount = $('#' + container.id + '>audio').length;
324
+        var videoCount = $('#' + container.id + '>video').length;
325
+        if (!audioCount && !videoCount) {
322 326
             console.log("Remove whole user");
323 327
             // Remove whole container
324 328
             container.remove();
@@ -330,14 +334,17 @@ $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
330 334
     };
331 335
 
332 336
     // Add click handler
333
-    sel.click(function () { handleVideoThumbClicked(vid.src); });
337
+    sel.click(function () {
338
+        handleVideoThumbClicked(vid.src);
339
+    });
334 340
 
335 341
     // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
336
-    if (isVideo
337
-        && data.peerjid && sess.peerjid === data.peerjid &&
338
-           data.stream.getVideoTracks().length === 0 &&
339
-           connection.jingle.localVideo.getVideoTracks().length > 0) {
340
-        window.setTimeout(function() {
342
+    if (isVideo &&
343
+        data.peerjid && sess.peerjid === data.peerjid &&
344
+        data.stream.getVideoTracks().length === 0 &&
345
+        connection.jingle.localVideo.getVideoTracks().length > 0) {
346
+        //
347
+        window.setTimeout(function () {
341 348
             sendKeyframe(sess.peerconnection);
342 349
         }, 3000);
343 350
     }
@@ -361,17 +368,17 @@ function handleVideoThumbClicked(videoSrc) {
361 368
  * Checks if removed video is currently displayed and tries to display another one instead.
362 369
  * @param removedVideoSrc src stream identifier of the video.
363 370
  */
364
-function checkChangeLargeVideo(removedVideoSrc){
371
+function checkChangeLargeVideo(removedVideoSrc) {
365 372
     if (removedVideoSrc === $('#largeVideo').attr('src')) {
366 373
         // this is currently displayed as large
367 374
         // pick the last visible video in the row
368 375
         // if nobody else is left, this picks the local video
369 376
         var pick = $('#remoteVideos>span[id!="mixedstream"]:visible:last>video').get(0);
370 377
 
371
-        if(!pick) {
378
+        if (!pick) {
372 379
             console.info("Last visible video no longer exists");
373 380
             pick = $('#remoteVideos>span[id!="mixedstream"]>video').get(0);
374
-            if(!pick) {
381
+            if (!pick) {
375 382
                 // Try local video
376 383
                 console.info("Fallback to local video...");
377 384
                 pick = $('#remoteVideos>span>span>video').get(0);
@@ -396,8 +403,10 @@ function sendKeyframe(pc) {
396 403
         function () {
397 404
             pc.createAnswer(
398 405
                 function (modifiedAnswer) {
399
-                    pc.setLocalDescription(modifiedAnswer,
406
+                    pc.setLocalDescription(
407
+                        modifiedAnswer,
400 408
                         function () {
409
+                            // noop
401 410
                         },
402 411
                         function (error) {
403 412
                             console.log('triggerKeyframe setLocalDescription failed', error);
@@ -436,7 +445,7 @@ function muteVideo(pc, unmute) {
436 445
                         function () {
437 446
                             console.log('mute SLD ok');
438 447
                         },
439
-                        function(error) {
448
+                        function (error) {
440 449
                             console.log('mute SLD error');
441 450
                         }
442 451
                     );
@@ -497,11 +506,11 @@ $(document).bind('setLocalDescription.jingle', function (event, sid) {
497 506
             newssrcs[type] = ssrc;
498 507
 
499 508
             directions[type] = (
500
-                SDPUtil.find_line(media, 'a=sendrecv')
501
-                || SDPUtil.find_line(media, 'a=recvonly')
502
-                || SDPUtil.find_line('a=sendonly')
503
-                || SDPUtil.find_line('a=inactive')
504
-                || 'a=sendrecv' ).substr(2);
509
+                SDPUtil.find_line(media, 'a=sendrecv') ||
510
+                SDPUtil.find_line(media, 'a=recvonly') ||
511
+                SDPUtil.find_line('a=sendonly') ||
512
+                SDPUtil.find_line('a=inactive') ||
513
+                'a=sendrecv').substr(2);
505 514
         }
506 515
     });
507 516
     console.log('new ssrcs', newssrcs);
@@ -513,7 +522,7 @@ $(document).bind('setLocalDescription.jingle', function (event, sid) {
513 522
         i++;
514 523
         var type = mtype;
515 524
         // Change video type to screen
516
-        if(mtype === 'video' && isUsingScreenStream) {
525
+        if (mtype === 'video' && isUsingScreenStream) {
517 526
             type = 'screen';
518 527
         }
519 528
         connection.emuc.addMediaToPresence(i, type, newssrcs[mtype], directions[mtype]);
@@ -603,13 +612,13 @@ $(document).bind('left.muc', function (event, jid) {
603 612
 $(document).bind('presence.muc', function (event, jid, info, pres) {
604 613
 
605 614
     // Remove old ssrcs coming from the jid
606
-    Object.keys(ssrc2jid).forEach(function(ssrc){
607
-       if(ssrc2jid[ssrc] == jid){
608
-           delete ssrc2jid[ssrc];
609
-       }
610
-       if(ssrc2videoType == jid){
611
-           delete  ssrc2videoType[ssrc];
612
-       }
615
+    Object.keys(ssrc2jid).forEach(function (ssrc) {
616
+        if (ssrc2jid[ssrc] == jid) {
617
+            delete ssrc2jid[ssrc];
618
+        }
619
+        if (ssrc2videoType == jid) {
620
+            delete ssrc2videoType[ssrc];
621
+        }
613 622
     });
614 623
 
615 624
     $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
@@ -623,7 +632,7 @@ $(document).bind('presence.muc', function (event, jid, info, pres) {
623 632
         // might need to update the direction if participant just went from sendrecv to recvonly
624 633
         if (type === 'video' || type === 'screen') {
625 634
             var el = $('#participant_'  + Strophe.getResourceFromJid(jid) + '>video');
626
-            switch(ssrc.getAttribute('direction')) {
635
+            switch (ssrc.getAttribute('direction')) {
627 636
             case 'sendrecv':
628 637
                 el.show();
629 638
                 break;
@@ -650,27 +659,24 @@ $(document).bind('passwordrequired.muc', function (event, jid) {
650 659
     console.log('on password required', jid);
651 660
 
652 661
     $.prompt('<h2>Password required</h2>' +
653
-            '<input id="lockKey" type="text" placeholder="shared key" autofocus>',
654
-             {
655
-                persistent: true,
656
-                buttons: { "Ok": true , "Cancel": false},
657
-                defaultButton: 1,
658
-                loaded: function(event) {
659
-                    document.getElementById('lockKey').focus();
660
-                },
661
-                submit: function(e,v,m,f){
662
-                    if(v)
663
-                    {
664
-                        var lockKey = document.getElementById('lockKey');
662
+        '<input id="lockKey" type="text" placeholder="shared key" autofocus>', {
663
+        persistent: true,
664
+        buttons: { "Ok": true, "Cancel": false},
665
+        defaultButton: 1,
666
+        loaded: function (event) {
667
+            document.getElementById('lockKey').focus();
668
+        },
669
+        submit: function (e, v, m, f) {
670
+            if (v) {
671
+                var lockKey = document.getElementById('lockKey');
665 672
 
666
-                        if (lockKey.value !== null)
667
-                        {
668
-                            setSharedKey(lockKey.value);
669
-                            connection.emuc.doJoin(jid, lockKey.value);
670
-                        }
671
-                    }
673
+                if (lockKey.value !== null) {
674
+                    setSharedKey(lockKey.value);
675
+                    connection.emuc.doJoin(jid, lockKey.value);
672 676
                 }
673
-            });
677
+            }
678
+        }
679
+    });
674 680
 });
675 681
 
676 682
 $(document).bind('audiomuted.muc', function (event, jid, isMuted) {
@@ -739,19 +745,19 @@ function updateLargeVideo(newSrc, vol) {
739 745
  * @param videoSrc eg. blob:https%3A//pawel.jitsi.net/9a46e0bd-131e-4d18-9c14-a9264e8db395
740 746
  * @returns {boolean}
741 747
  */
742
-function isVideoSrcDesktop(videoSrc){
748
+function isVideoSrcDesktop(videoSrc) {
743 749
     // FIXME: fix this mapping mess...
744 750
     // figure out if large video is desktop stream or just a camera
745 751
     var isDesktop = false;
746
-    if(localVideoSrc === videoSrc) {
752
+    if (localVideoSrc === videoSrc) {
747 753
         // local video
748 754
         isDesktop = isUsingScreenStream;
749 755
     } else {
750 756
         // Do we have associations...
751 757
         var videoSsrc = videoSrcToSsrc[videoSrc];
752
-        if(videoSsrc) {
758
+        if (videoSsrc) {
753 759
             var videoType = ssrc2videoType[videoSsrc];
754
-            if(videoType) {
760
+            if (videoType) {
755 761
                 // Finally there...
756 762
                 isDesktop = videoType === 'screen';
757 763
             } else {
@@ -769,12 +775,12 @@ function isVideoSrcDesktop(videoSrc){
769 775
  */
770 776
 function setLargeVideoVisible(isVisible) {
771 777
     if (isVisible) {
772
-        $('#largeVideo').css({visibility:'visible'});
773
-        $('.watermark').css({visibility:'visible'});
778
+        $('#largeVideo').css({visibility: 'visible'});
779
+        $('.watermark').css({visibility: 'visible'});
774 780
     }
775 781
     else {
776
-        $('#largeVideo').css({visibility:'hidden'});
777
-        $('.watermark').css({visibility:'hidden'});
782
+        $('#largeVideo').css({visibility: 'hidden'});
783
+        $('.watermark').css({visibility: 'hidden'});
778 784
     }
779 785
 }
780 786
 
@@ -789,8 +795,8 @@ function toggleVideo() {
789 795
     var sess = getConferenceHandler();
790 796
     if (sess) {
791 797
         sess.toggleVideoMute(
792
-            function(isMuted){
793
-                if(isMuted) {
798
+            function (isMuted) {
799
+                if (isMuted) {
794 800
                     $('#video').removeClass("icon-camera");
795 801
                     $('#video').addClass("icon-camera icon-camera-disabled");
796 802
                 } else {
@@ -801,7 +807,7 @@ function toggleVideo() {
801 807
         );
802 808
     }
803 809
 
804
-    var sess = focus || activecall;
810
+    sess = focus || activecall;
805 811
     if (!sess) {
806 812
         return;
807 813
     }
@@ -835,30 +841,30 @@ function toggleAudio() {
835 841
  * @param videoWidth the stream video width
836 842
  * @param videoHeight the stream video height
837 843
  */
838
-var positionLarge = function(videoWidth, videoHeight) {
844
+var positionLarge = function (videoWidth, videoHeight) {
839 845
     var videoSpaceWidth = $('#videospace').width();
840 846
     var videoSpaceHeight = window.innerHeight;
841 847
 
842
-    var videoSize = getVideoSize(   videoWidth,
843
-                                    videoHeight,
844
-                                    videoSpaceWidth,
845
-                                    videoSpaceHeight);
848
+    var videoSize = getVideoSize(videoWidth,
849
+                                 videoHeight,
850
+                                 videoSpaceWidth,
851
+                                 videoSpaceHeight);
846 852
 
847 853
     var largeVideoWidth = videoSize[0];
848 854
     var largeVideoHeight = videoSize[1];
849 855
 
850
-    var videoPosition = getVideoPosition(   largeVideoWidth,
851
-                                            largeVideoHeight,
852
-                                            videoSpaceWidth,
853
-                                            videoSpaceHeight);
856
+    var videoPosition = getVideoPosition(largeVideoWidth,
857
+                                         largeVideoHeight,
858
+                                         videoSpaceWidth,
859
+                                         videoSpaceHeight);
854 860
 
855 861
     var horizontalIndent = videoPosition[0];
856 862
     var verticalIndent = videoPosition[1];
857 863
 
858
-    positionVideo(  $('#largeVideo'),
859
-                    largeVideoWidth,
860
-                    largeVideoHeight,
861
-                    horizontalIndent, verticalIndent);
864
+    positionVideo($('#largeVideo'),
865
+                  largeVideoWidth,
866
+                  largeVideoHeight,
867
+                  horizontalIndent, verticalIndent);
862 868
 };
863 869
 
864 870
 /**
@@ -868,21 +874,21 @@ var positionLarge = function(videoWidth, videoHeight) {
868 874
  * @return an array with 2 elements, the horizontal indent and the vertical
869 875
  * indent
870 876
  */
871
-function getCameraVideoPosition(   videoWidth,
872
-                                   videoHeight,
873
-                                   videoSpaceWidth,
874
-                                   videoSpaceHeight) {
877
+function getCameraVideoPosition(videoWidth,
878
+                                videoHeight,
879
+                                videoSpaceWidth,
880
+                                videoSpaceHeight) {
875 881
     // Parent height isn't completely calculated when we position the video in
876 882
     // full screen mode and this is why we use the screen height in this case.
877 883
     // Need to think it further at some point and implement it properly.
878
-    var isFullScreen = document.fullScreen
879
-                        || document.mozFullScreen
880
-                        || document.webkitIsFullScreen; 
884
+    var isFullScreen = document.fullScreen ||
885
+            document.mozFullScreen ||
886
+            document.webkitIsFullScreen;
881 887
     if (isFullScreen)
882 888
         videoSpaceHeight = window.innerHeight;
883 889
 
884
-    var horizontalIndent = (videoSpaceWidth - videoWidth)/2;
885
-    var verticalIndent = (videoSpaceHeight - videoHeight)/2;
890
+    var horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
891
+    var verticalIndent = (videoSpaceHeight - videoHeight) / 2;
886 892
 
887 893
     return [horizontalIndent, verticalIndent];
888 894
 }
@@ -894,12 +900,12 @@ function getCameraVideoPosition(   videoWidth,
894 900
  * @return an array with 2 elements, the horizontal indent and the vertical
895 901
  * indent
896 902
  */
897
-function getDesktopVideoPosition(  videoWidth,
898
-                                   videoHeight,
899
-                                   videoSpaceWidth,
900
-                                   videoSpaceHeight) {
903
+function getDesktopVideoPosition(videoWidth,
904
+                                 videoHeight,
905
+                                 videoSpaceWidth,
906
+                                 videoSpaceHeight) {
901 907
 
902
-    var horizontalIndent = (videoSpaceWidth - videoWidth)/2;
908
+    var horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
903 909
 
904 910
     var verticalIndent = 0;// Top aligned
905 911
 
@@ -928,10 +934,10 @@ function getCameraVideoSize(videoWidth,
928 934
 
929 935
     if (availableWidth / aspectRatio < videoSpaceHeight) {
930 936
         availableHeight = videoSpaceHeight;
931
-        availableWidth = availableHeight*aspectRatio;
937
+        availableWidth = availableHeight * aspectRatio;
932 938
     }
933 939
 
934
-    if (availableHeight*aspectRatio < videoSpaceWidth) {
940
+    if (availableHeight * aspectRatio < videoSpaceWidth) {
935 941
         availableWidth = videoSpaceWidth;
936 942
         availableHeight = availableWidth / aspectRatio;
937 943
     }
@@ -945,11 +951,10 @@ function getCameraVideoSize(videoWidth,
945 951
  *
946 952
  * @return an array with 2 elements, the video width and the video height
947 953
  */
948
-function getDesktopVideoSize( videoWidth,
949
-                              videoHeight,
950
-                              videoSpaceWidth,
951
-                              videoSpaceHeight )
952
-{
954
+function getDesktopVideoSize(videoWidth,
955
+                             videoHeight,
956
+                             videoSpaceWidth,
957
+                             videoSpaceHeight) {
953 958
     if (!videoWidth)
954 959
         videoWidth = currentVideoWidth;
955 960
     if (!videoHeight)
@@ -965,10 +970,10 @@ function getDesktopVideoSize( videoWidth,
965 970
     if (availableWidth / aspectRatio >= videoSpaceHeight)
966 971
     {
967 972
         availableHeight = videoSpaceHeight;
968
-        availableWidth = availableHeight*aspectRatio;
973
+        availableWidth = availableHeight * aspectRatio;
969 974
     }
970 975
 
971
-    if (availableHeight*aspectRatio >= videoSpaceWidth)
976
+    if (availableHeight * aspectRatio >= videoSpaceWidth)
972 977
     {
973 978
         availableWidth = videoSpaceWidth;
974 979
         availableHeight = availableWidth / aspectRatio;
@@ -986,11 +991,11 @@ function getDesktopVideoSize( videoWidth,
986 991
  * @param horizontalIndent the left and right indent
987 992
  * @param verticalIndent the top and bottom indent
988 993
  */
989
-function positionVideo( video,
990
-                        width,
991
-                        height,
992
-                        horizontalIndent,
993
-                        verticalIndent) {
994
+function positionVideo(video,
995
+                       width,
996
+                       height,
997
+                       horizontalIndent,
998
+                       verticalIndent) {
994 999
     video.width(width);
995 1000
     video.height(height);
996 1001
     video.css({  top: verticalIndent + 'px',
@@ -1014,7 +1019,7 @@ var resizeLargeVideoContainer = function () {
1014 1019
     resizeThumbnails();
1015 1020
 };
1016 1021
 
1017
-var calculateThumbnailSize = function() {
1022
+var calculateThumbnailSize = function () {
1018 1023
  // Calculate the available height, which is the inner window height minus
1019 1024
     // 39px for the header minus 2px for the delimiter lines on the top and
1020 1025
     // bottom of the large video, minus the 36px space inside the remoteVideos
@@ -1056,8 +1061,7 @@ $(document).ready(function () {
1056 1061
     // Set default desktop sharing method
1057 1062
     setDesktopSharing(config.desktopSharing);
1058 1063
     // Initialize Chrome extension inline installs
1059
-    if(config.chromeExtensionId)
1060
-    {
1064
+    if (config.chromeExtensionId) {
1061 1065
         initInlineInstalls();
1062 1066
     }
1063 1067
 
@@ -1072,7 +1076,7 @@ $(document).ready(function () {
1072 1076
     });
1073 1077
     // Listen for large video size updates
1074 1078
     document.getElementById('largeVideo')
1075
-        .addEventListener('loadedmetadata', function(e){
1079
+        .addEventListener('loadedmetadata', function (e) {
1076 1080
             currentVideoWidth = this.videoWidth;
1077 1081
             currentVideoHeight = this.videoHeight;
1078 1082
             positionLarge(currentVideoWidth, currentVideoHeight);
@@ -1114,12 +1118,12 @@ $(window).bind('beforeunload', function () {
1114 1118
 
1115 1119
 function disposeConference() {
1116 1120
     var handler = getConferenceHandler();
1117
-    if(handler && handler.peerconnection) {
1121
+    if (handler && handler.peerconnection) {
1118 1122
         // FIXME: probably removing streams is not required and close() should be enough
1119
-        if(connection.jingle.localAudio) {
1123
+        if (connection.jingle.localAudio) {
1120 1124
             handler.peerconnection.removeStream(connection.jingle.localAudio);
1121 1125
         }
1122
-        if(connection.jingle.localVideo) {
1126
+        if (connection.jingle.localVideo) {
1123 1127
             handler.peerconnection.removeStream(connection.jingle.localVideo);
1124 1128
         }
1125 1129
         handler.peerconnection.close();
@@ -1128,7 +1132,7 @@ function disposeConference() {
1128 1132
     activecall = null;
1129 1133
 }
1130 1134
 
1131
-function dump(elem, filename){
1135
+function dump(elem, filename) {
1132 1136
     elem = elem.parentNode;
1133 1137
     elem.download = filename || 'meetlog.json';
1134 1138
     elem.href = 'data:application/json;charset=utf-8,\n';
@@ -1141,8 +1145,8 @@ function dump(elem, filename){
1141 1145
                 data["jingle_" + session.sid] = {
1142 1146
                     updateLog: session.peerconnection.updateLog,
1143 1147
                     stats: session.peerconnection.stats,
1144
-                    url: window.location.href}
1145
-                ;
1148
+                    url: window.location.href
1149
+                };
1146 1150
             }
1147 1151
         });
1148 1152
     }
@@ -1173,56 +1177,57 @@ function openLockDialog() {
1173 1177
     if (focus === null) {
1174 1178
         if (sharedKey)
1175 1179
             $.prompt("This conversation is currently protected by a shared secret key.",
1176
-                 {
1177
-                 title: "Secrect key",
1178
-                 persistent: false
1179
-                 });
1180
+                {
1181
+                    title: "Secrect key",
1182
+                    persistent: false
1183
+                }
1184
+            );
1180 1185
         else
1181 1186
             $.prompt("This conversation isn't currently protected by a secret key. Only the owner of the conference could set a shared key.",
1182
-                     {
1183
-                     title: "Secrect key",
1184
-                     persistent: false
1185
-                     });
1186
-    }
1187
-    else {
1188
-        if (sharedKey)
1187
+                {
1188
+                    title: "Secrect key",
1189
+                    persistent: false
1190
+                }
1191
+            );
1192
+    } else {
1193
+        if (sharedKey) {
1189 1194
             $.prompt("Are you sure you would like to remove your secret key?",
1190
-                     {
1191
-                     title: "Remove secrect key",
1192
-                     persistent: false,
1193
-                     buttons: { "Remove": true, "Cancel": false},
1194
-                     defaultButton: 1,
1195
-                     submit: function(e,v,m,f){
1196
-                     if(v)
1197
-                     {
1198
-                        setSharedKey('');
1199
-                        lockRoom(false);
1200
-                     }
1201
-                     }
1202
-                     });
1203
-        else
1195
+                {
1196
+                    title: "Remove secrect key",
1197
+                    persistent: false,
1198
+                    buttons: { "Remove": true, "Cancel": false},
1199
+                    defaultButton: 1,
1200
+                    submit: function (e, v, m, f) {
1201
+                        if (v) {
1202
+                            setSharedKey('');
1203
+                            lockRoom(false);
1204
+                        }
1205
+                    }
1206
+                }
1207
+            );
1208
+        } else {
1204 1209
             $.prompt('<h2>Set a secrect key to lock your room</h2>' +
1205 1210
                      '<input id="lockKey" type="text" placeholder="your shared key" autofocus>',
1206
-                     {
1207
-                     persistent: false,
1208
-                     buttons: { "Save": true , "Cancel": false},
1209
-                     defaultButton: 1,
1210
-                     loaded: function(event) {
1211
-                     document.getElementById('lockKey').focus();
1212
-                     },
1213
-                     submit: function(e,v,m,f){
1214
-                     if(v)
1215
-                     {
1216
-                        var lockKey = document.getElementById('lockKey');
1217
-
1218
-                        if (lockKey.value)
1219
-                        {
1220
-                            setSharedKey(Util.escapeHtml(lockKey.value));
1221
-                            lockRoom(true);
1211
+                {
1212
+                    persistent: false,
1213
+                    buttons: { "Save": true, "Cancel": false},
1214
+                    defaultButton: 1,
1215
+                    loaded: function (event) {
1216
+                        document.getElementById('lockKey').focus();
1217
+                    },
1218
+                    submit: function (e, v, m, f) {
1219
+                        if (v) {
1220
+                            var lockKey = document.getElementById('lockKey');
1221
+
1222
+                            if (lockKey.value) {
1223
+                                setSharedKey(Util.escapeHtml(lockKey.value));
1224
+                                lockRoom(true);
1225
+                            }
1222 1226
                         }
1223
-                     }
1227
+                    }
1224 1228
                 }
1225
-            });
1229
+            );
1230
+        }
1226 1231
     }
1227 1232
 }
1228 1233
 
@@ -1230,16 +1235,17 @@ function openLockDialog() {
1230 1235
  * Opens the invite link dialog.
1231 1236
  */
1232 1237
 function openLinkDialog() {
1233
-    $.prompt('<input id="inviteLinkRef" type="text" value="'
1234
-            + encodeURI(roomUrl) + '" onclick="this.select();" readonly>',
1235
-             {
1236
-             title: "Share this link with everyone you want to invite",
1237
-             persistent: false,
1238
-             buttons: { "Cancel": false},
1239
-             loaded: function(event) {
1240
-             document.getElementById('inviteLinkRef').select();
1241
-             }
1242
-             });
1238
+    $.prompt('<input id="inviteLinkRef" type="text" value="' +
1239
+        encodeURI(roomUrl) + '" onclick="this.select();" readonly>',
1240
+        {
1241
+            title: "Share this link with everyone you want to invite",
1242
+            persistent: false,
1243
+            buttons: { "Cancel": false},
1244
+            loaded: function (event) {
1245
+                document.getElementById('inviteLinkRef').select();
1246
+            }
1247
+        }
1248
+    );
1243 1249
 }
1244 1250
 
1245 1251
 /**
@@ -1247,40 +1253,38 @@ function openLinkDialog() {
1247 1253
  */
1248 1254
 function openSettingsDialog() {
1249 1255
     $.prompt('<h2>Configure your conference</h2>' +
1250
-             '<input type="checkbox" id="initMuted"> Participants join muted<br/>' +
1251
-             '<input type="checkbox" id="requireNicknames"> Require nicknames<br/><br/>' +
1252
-             'Set a secrect key to lock your room: <input id="lockKey" type="text" placeholder="your shared key" autofocus>',
1253
-             {
1254
-                persistent: false,
1255
-                buttons: { "Save": true , "Cancel": false},
1256
-                defaultButton: 1,
1257
-                loaded: function(event) {
1258
-                    document.getElementById('lockKey').focus();
1259
-                },
1260
-                submit: function(e,v,m,f){
1261
-                    if(v)
1262
-                    {
1263
-                        if ($('#initMuted').is(":checked"))
1264
-                        {
1265
-                            // it is checked
1266
-                        }
1256
+        '<input type="checkbox" id="initMuted"> Participants join muted<br/>' +
1257
+        '<input type="checkbox" id="requireNicknames"> Require nicknames<br/><br/>' +
1258
+        'Set a secrect key to lock your room: <input id="lockKey" type="text" placeholder="your shared key" autofocus>',
1259
+        {
1260
+            persistent: false,
1261
+            buttons: { "Save": true, "Cancel": false},
1262
+            defaultButton: 1,
1263
+            loaded: function (event) {
1264
+                document.getElementById('lockKey').focus();
1265
+            },
1266
+            submit: function (e, v, m, f) {
1267
+                if (v) {
1268
+                    if ($('#initMuted').is(":checked")) {
1269
+                        // it is checked
1270
+                    }
1267 1271
 
1268
-                        if ($('#requireNicknames').is(":checked"))
1269
-                        {
1270
-                            // it is checked
1271
-                        }
1272
-             /*
1273
-                        var lockKey = document.getElementById('lockKey');
1272
+                    if ($('#requireNicknames').is(":checked")) {
1273
+                        // it is checked
1274
+                    }
1275
+                    /*
1276
+                    var lockKey = document.getElementById('lockKey');
1274 1277
 
1275
-                        if (lockKey.value)
1276
-                        {
1277
-                            setSharedKey(lockKey.value);
1278
-                            lockRoom(true);
1279
-                        }
1280
-              */
1278
+                    if (lockKey.value)
1279
+                    {
1280
+                        setSharedKey(lockKey.value);
1281
+                        lockRoom(true);
1281 1282
                     }
1283
+                    */
1282 1284
                 }
1283
-             });
1285
+            }
1286
+        }
1287
+    );
1284 1288
 }
1285 1289
 
1286 1290
 /**
@@ -1312,10 +1316,10 @@ function updateLockButton() {
1312 1316
 /**
1313 1317
  * Hides the toolbar.
1314 1318
  */
1315
-var hideToolbar = function() {
1319
+var hideToolbar = function () {
1316 1320
 
1317 1321
     var isToolbarHover = false;
1318
-    $('#header').find('*').each(function(){
1322
+    $('#header').find('*').each(function () {
1319 1323
         var id = $(this).attr('id');
1320 1324
         if ($("#" + id + ":hover").length > 0) {
1321 1325
             isToolbarHover = true;
@@ -1418,7 +1422,7 @@ function showFocusIndicator() {
1418 1422
         var session = connection.jingle.sessions[Object.keys(connection.jingle.sessions)[0]];
1419 1423
         var focusId = 'participant_' + Strophe.getResourceFromJid(session.peerjid);
1420 1424
         var focusContainer = document.getElementById(focusId);
1421
-        if(!focusContainer) {
1425
+        if (!focusContainer) {
1422 1426
             console.error("No focus container!");
1423 1427
             return;
1424 1428
         }
@@ -1438,12 +1442,11 @@ function showFocusIndicator() {
1438 1442
  * Checks if container for participant identified by given peerJid exists in the document and creates it eventually.
1439 1443
  * @param peerJid peer Jid to check.
1440 1444
  */
1441
-function ensurePeerContainerExists(peerJid){
1442
-
1445
+function ensurePeerContainerExists(peerJid) {
1443 1446
     var peerResource = Strophe.getResourceFromJid(peerJid);
1444 1447
     var videoSpanId = 'participant_' + peerResource;
1445 1448
 
1446
-    if($('#'+videoSpanId).length > 0) {
1449
+    if ($('#' + videoSpanId).length > 0) {
1447 1450
         return;
1448 1451
     }
1449 1452
 
@@ -1482,8 +1485,7 @@ function createFocusIndicatorElement(parentElement) {
1482 1485
 function toggleFullScreen() {
1483 1486
     var fsElement = document.documentElement;
1484 1487
 
1485
-    if (!document.mozFullScreen && !document.webkitIsFullScreen){
1486
-
1488
+    if (!document.mozFullScreen && !document.webkitIsFullScreen) {
1487 1489
         //Enter Full Screen
1488 1490
         if (fsElement.mozRequestFullScreen) {
1489 1491
             fsElement.mozRequestFullScreen();
@@ -1511,13 +1513,13 @@ function showDisplayName(videoSpanId, displayName) {
1511 1513
     if (nameSpan.length > 0) {
1512 1514
         var nameSpanElement = nameSpan.get(0);
1513 1515
 
1514
-        if (nameSpanElement.id === 'localDisplayName'
1515
-            && $('#localDisplayName').text() !== displayName)
1516
+        if (nameSpanElement.id === 'localDisplayName' &&
1517
+            $('#localDisplayName').text() !== displayName) {
1516 1518
             $('#localDisplayName').text(displayName);
1517
-        else
1519
+        } else {
1518 1520
             $('#' + videoSpanId + '_name').text(displayName);
1519
-    }
1520
-    else {
1521
+        }
1522
+    } else {
1521 1523
         var editButton = null;
1522 1524
 
1523 1525
         if (videoSpanId === 'localVideoContainer') {
@@ -1532,8 +1534,7 @@ function showDisplayName(videoSpanId, displayName) {
1532 1534
 
1533 1535
         if (!editButton) {
1534 1536
             nameSpan.id = videoSpanId + '_name';
1535
-        }
1536
-        else {
1537
+        } else {
1537 1538
             nameSpan.id = 'localDisplayName';
1538 1539
             $('#' + videoSpanId)[0].appendChild(editButton);
1539 1540
 
@@ -1541,22 +1542,22 @@ function showDisplayName(videoSpanId, displayName) {
1541 1542
             editableText.className = 'displayname';
1542 1543
             editableText.id = 'editDisplayName';
1543 1544
 
1544
-            if (displayName.length)
1545
-                editableText.value
1546
-                    = displayName.substring(0, displayName.indexOf(' (me)'));
1545
+            if (displayName.length) {
1546
+                editableText.value = displayName.substring(0, displayName.indexOf(' (me)'));
1547
+            }
1547 1548
 
1548 1549
             editableText.setAttribute('style', 'display:none;');
1549 1550
             editableText.setAttribute('placeholder', 'ex. Jane Pink');
1550 1551
             $('#' + videoSpanId)[0].appendChild(editableText);
1551 1552
 
1552
-            $('#localVideoContainer .displayname').bind("click", function(e) {
1553
+            $('#localVideoContainer .displayname').bind("click", function (e) {
1553 1554
                 e.preventDefault();
1554 1555
                 $('#localDisplayName').hide();
1555 1556
                 $('#editDisplayName').show();
1556 1557
                 $('#editDisplayName').focus();
1557 1558
                 $('#editDisplayName').select();
1558 1559
 
1559
-                var inputDisplayNameHandler = function(name) {
1560
+                var inputDisplayNameHandler = function (name) {
1560 1561
                     if (nickname !== name) {
1561 1562
                         nickname = name;
1562 1563
                         window.localStorage.displayname = nickname;
@@ -1661,20 +1662,21 @@ function showVideoIndicator(videoSpanId, isMuted) {
1661 1662
  * Resizes and repositions videos in full screen mode.
1662 1663
  */
1663 1664
 $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
1664
-        function() {
1665
-            resizeLargeVideoContainer();
1666
-            positionLarge();
1667
-            isFullScreen = document.fullScreen
1668
-                                || document.mozFullScreen
1669
-                                || document.webkitIsFullScreen;
1670
-
1671
-            if (isFullScreen) {
1672
-                setView("fullscreen");
1673
-            }
1674
-            else {
1675
-                setView("default");
1676
-            }
1677
-});
1665
+    function () {
1666
+        resizeLargeVideoContainer();
1667
+        positionLarge();
1668
+        isFullScreen = document.fullScreen ||
1669
+            document.mozFullScreen ||
1670
+            document.webkitIsFullScreen;
1671
+
1672
+        if (isFullScreen) {
1673
+            setView("fullscreen");
1674
+        }
1675
+        else {
1676
+            setView("default");
1677
+        }
1678
+    }
1679
+);
1678 1680
 
1679 1681
 /**
1680 1682
  * Sets the current view.

+ 29
- 28
chat.js View File

@@ -1,3 +1,4 @@
1
+/* global $, Util, connection, nickname:true, getVideoSize, getVideoPosition, showToolbar, processReplacements */
1 2
 /**
2 3
  * Chat related user interface.
3 4
  */
@@ -16,7 +17,7 @@ var Chat = (function (my) {
16 17
             Chat.setChatConversationMode(true);
17 18
         }
18 19
 
19
-        $('#nickinput').keydown(function(event) {
20
+        $('#nickinput').keydown(function (event) {
20 21
             if (event.keyCode === 13) {
21 22
                 event.preventDefault();
22 23
                 var val = Util.escapeHtml(this.value);
@@ -35,7 +36,7 @@ var Chat = (function (my) {
35 36
             }
36 37
         });
37 38
 
38
-        $('#usermsg').keydown(function(event) {
39
+        $('#usermsg').keydown(function (event) {
39 40
             if (event.keyCode === 13) {
40 41
                 event.preventDefault();
41 42
                 var message = Util.escapeHtml(this.value);
@@ -45,14 +46,14 @@ var Chat = (function (my) {
45 46
             }
46 47
         });
47 48
 
48
-        var onTextAreaResize = function() {
49
+        var onTextAreaResize = function () {
49 50
             resizeChatConversation();
50 51
             scrollChatToBottom();
51 52
         };
52 53
         $('#usermsg').autosize({callback: onTextAreaResize});
53 54
 
54 55
         $("#chatspace").bind("shown",
55
-            function() {
56
+            function () {
56 57
                 unreadMessages = 0;
57 58
                 setVisualNotification(false);
58 59
             });
@@ -82,9 +83,9 @@ var Chat = (function (my) {
82 83
         var escDisplayName = Util.escapeHtml(displayName);
83 84
         message = processReplacements(escMessage);
84 85
 
85
-        $('#chatconversation').append('<div class="' + divClassName + '"><b>'
86
-                                        + escDisplayName + ': </b>'
87
-                                        + message + '</div>');
86
+        $('#chatconversation').append('<div class="' + divClassName + '"><b>' +
87
+                                      escDisplayName + ': </b>' +
88
+                                      message + '</div>');
88 89
         $('#chatconversation').animate(
89 90
                 { scrollTop: $('#chatconversation')[0].scrollHeight}, 1000);
90 91
     };
@@ -103,15 +104,15 @@ var Chat = (function (my) {
103 104
             = getVideoSize(null, null, videospaceWidth, videospaceHeight);
104 105
         var videoWidth = videoSize[0];
105 106
         var videoHeight = videoSize[1];
106
-        var videoPosition = getVideoPosition(   videoWidth,
107
-                                                videoHeight,
108
-                                                videospaceWidth,
109
-                                                videospaceHeight);
107
+        var videoPosition = getVideoPosition(videoWidth,
108
+                                             videoHeight,
109
+                                             videospaceWidth,
110
+                                             videospaceHeight);
110 111
         var horizontalIndent = videoPosition[0];
111 112
         var verticalIndent = videoPosition[1];
112 113
 
113 114
         if (chatspace.is(":visible")) {
114
-            videospace.animate( {right: chatSize[0],
115
+            videospace.animate({right: chatSize[0],
115 116
                                 width: videospaceWidth,
116 117
                                 height: videospaceHeight},
117 118
                                 {queue: false,
@@ -143,7 +144,7 @@ var Chat = (function (my) {
143 144
                                 height: videospaceHeight},
144 145
                                {queue: false,
145 146
                                 duration: 500,
146
-                                complete: function() {
147
+                                complete: function () {
147 148
                                     scrollChatToBottom();
148 149
                                     chatspace.trigger('shown');
149 150
                                 }
@@ -183,9 +184,9 @@ var Chat = (function (my) {
183 184
      */
184 185
     my.setChatConversationMode = function (isConversationMode) {
185 186
         if (isConversationMode) {
186
-            $('#nickname').css({visibility:"hidden"});
187
-            $('#chatconversation').css({visibility:'visible'});
188
-            $('#usermsg').css({visibility:'visible'});
187
+            $('#nickname').css({visibility: 'hidden'});
188
+            $('#chatconversation').css({visibility: 'visible'});
189
+            $('#usermsg').css({visibility: 'visible'});
189 190
             $('#usermsg').focus();
190 191
         }
191 192
     };
@@ -205,13 +206,13 @@ var Chat = (function (my) {
205 206
     /**
206 207
      * Returns the size of the chat.
207 208
      */
208
-    my.getChatSize = function() {
209
+    my.getChatSize = function () {
209 210
         var availableHeight = window.innerHeight;
210 211
         var availableWidth = window.innerWidth;
211 212
 
212 213
         var chatWidth = 200;
213
-        if (availableWidth*0.2 < 200)
214
-            chatWidth = availableWidth*0.2;
214
+        if (availableWidth * 0.2 < 200)
215
+            chatWidth = availableWidth * 0.2;
215 216
 
216 217
         return [chatWidth, availableHeight];
217 218
     };
@@ -228,7 +229,7 @@ var Chat = (function (my) {
228 229
         $('#chatconversation').width($('#chatspace').width() - 10);
229 230
         $('#chatconversation')
230 231
             .height(window.innerHeight - 10 - parseInt(usermsgHeight));
231
-    };
232
+    }
232 233
 
233 234
     /**
234 235
      * Shows/hides a visual notification, indicating that a message has arrived.
@@ -245,15 +246,15 @@ var Chat = (function (my) {
245 246
 
246 247
             var chatButtonElement
247 248
                 = document.getElementById('chatButton').parentNode;
248
-            var leftIndent = (Util.getTextWidth(chatButtonElement)
249
-                                - Util.getTextWidth(unreadMsgElement))/2;
250
-            var topIndent = (Util.getTextHeight(chatButtonElement)
251
-                                - Util.getTextHeight(unreadMsgElement))/2 - 3;
249
+            var leftIndent = (Util.getTextWidth(chatButtonElement) -
250
+                              Util.getTextWidth(unreadMsgElement)) / 2;
251
+            var topIndent = (Util.getTextHeight(chatButtonElement) -
252
+                             Util.getTextHeight(unreadMsgElement)) / 2 - 3;
252 253
 
253 254
             unreadMsgElement.setAttribute(
254 255
                     'style',
255
-                    'top:' + topIndent
256
-                     + '; left:' + leftIndent +';');
256
+                    'top:' + topIndent +
257
+                    '; left:' + leftIndent + ';');
257 258
 
258 259
             if (!glower.hasClass('icon-chat-simple')) {
259 260
                 glower.removeClass('icon-chat');
@@ -267,7 +268,7 @@ var Chat = (function (my) {
267 268
         }
268 269
 
269 270
         if (show && !notificationInterval) {
270
-            notificationInterval = window.setInterval(function() {
271
+            notificationInterval = window.setInterval(function () {
271 272
                 glower.toggleClass('active');
272 273
             }, 800);
273 274
         }
@@ -282,7 +283,7 @@ var Chat = (function (my) {
282 283
      * Scrolls chat to the bottom.
283 284
      */
284 285
     function scrollChatToBottom() {
285
-        setTimeout(function() {
286
+        setTimeout(function () {
286 287
             $('#chatconversation').scrollTop(
287 288
                     $('#chatconversation')[0].scrollHeight);
288 289
         }, 5);

+ 198
- 195
desktopsharing.js View File

@@ -1,3 +1,4 @@
1
+/* global $, config, connection, chrome, alert, getUserMediaWithConstraints, change_local_video, getConferenceHandler */
1 2
 /**
2 3
  * Indicates that desktop stream is currently in use(for toggle purpose).
3 4
  * @type {boolean}
@@ -12,7 +13,7 @@ var switchInProgress = false;
12 13
 /**
13 14
  * Method used to get screen sharing stream.
14 15
  *
15
- * @type {function(stream_callback, failure_callback}
16
+ * @type {function (stream_callback, failure_callback}
16 17
  */
17 18
 var obtainDesktopStream = null;
18 19
 
@@ -22,12 +23,161 @@ var obtainDesktopStream = null;
22 23
  */
23 24
 var _desktopSharingEnabled = null;
24 25
 
26
+/**
27
+ * Method obtains desktop stream from WebRTC 'screen' source.
28
+ * Flag 'chrome://flags/#enable-usermedia-screen-capture' must be enabled.
29
+ */
30
+function obtainWebRTCScreen(streamCallback, failCallback) {
31
+    getUserMediaWithConstraints(
32
+        ['screen'],
33
+        streamCallback,
34
+        failCallback
35
+    );
36
+}
37
+
38
+/**
39
+ * Constructs inline install URL for Chrome desktop streaming extension.
40
+ * The 'chromeExtensionId' must be defined in config.js.
41
+ * @returns {string}
42
+ */
43
+function getWebStoreInstallUrl()
44
+{
45
+    return "https://chrome.google.com/webstore/detail/" + config.chromeExtensionId;
46
+}
47
+
48
+/**
49
+ * Checks whether extension update is required.
50
+ * @param minVersion minimal required version
51
+ * @param extVersion current extension version
52
+ * @returns {boolean}
53
+ */
54
+function isUpdateRequired(minVersion, extVersion)
55
+{
56
+    try
57
+    {
58
+        var s1 = minVersion.split('.');
59
+        var s2 = extVersion.split('.');
60
+
61
+        var len = Math.max(s1.length, s2.length);
62
+        for (var i = 0; i < len; i++)
63
+        {
64
+            var n1 = 0,
65
+                n2 = 0;
66
+
67
+            if (i < s1.length)
68
+                n1 = parseInt(s1[i]);
69
+            if (i < s2.length)
70
+                n2 = parseInt(s2[i]);
71
+
72
+            if (isNaN(n1) || isNaN(n2))
73
+            {
74
+                return true;
75
+            }
76
+            else if (n1 !== n2)
77
+            {
78
+                return n1 > n2;
79
+            }
80
+        }
81
+
82
+        // will happen if boths version has identical numbers in
83
+        // their components (even if one of them is longer, has more components)
84
+        return false;
85
+    }
86
+    catch (e)
87
+    {
88
+        console.error("Failed to parse extension version", e);
89
+        return true;
90
+    }
91
+}
92
+
93
+
94
+function checkExtInstalled(isInstalledCallback) {
95
+    if (!chrome.runtime) {
96
+        // No API, so no extension for sure
97
+        isInstalledCallback(false);
98
+    }
99
+    chrome.runtime.sendMessage(
100
+        config.chromeExtensionId,
101
+        { getVersion: true },
102
+        function (response) {
103
+            if (!response || !response.version) {
104
+                // Communication failure - assume that no endpoint exists
105
+                console.warn("Extension not installed?: " + chrome.runtime.lastError);
106
+                isInstalledCallback(false);
107
+            } else {
108
+                // Check installed extension version
109
+                var extVersion = response.version;
110
+                console.log('Extension version is: ' + extVersion);
111
+                var updateRequired = isUpdateRequired(config.minChromeExtVersion, extVersion);
112
+                if (updateRequired) {
113
+                    alert(
114
+                        'Jitsi Desktop Streamer requires update. ' +
115
+                        'Changes will take effect after next Chrome restart.');
116
+                }
117
+                isInstalledCallback(!updateRequired);
118
+            }
119
+        }
120
+    );
121
+}
122
+
123
+function doGetStreamFromExtension(streamCallback, failCallback) {
124
+    // Sends 'getStream' msg to the extension. Extension id must be defined in the config.
125
+    chrome.runtime.sendMessage(
126
+        config.chromeExtensionId,
127
+        { getStream: true},
128
+        function (response) {
129
+            if (!response) {
130
+                failCallback(chrome.runtime.lastError);
131
+                return;
132
+            }
133
+            console.log("Response from extension: " + response);
134
+            if (response.streamId) {
135
+                getUserMediaWithConstraints(
136
+                    ['desktop'],
137
+                    function (stream) {
138
+                        streamCallback(stream);
139
+                    },
140
+                    failCallback,
141
+                    null, null, null,
142
+                    response.streamId);
143
+            } else {
144
+                failCallback("Extension failed to get the stream");
145
+            }
146
+        }
147
+    );
148
+}
149
+/**
150
+ * Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop' stream for returned stream token.
151
+ */
152
+function obtainScreenFromExtension(streamCallback, failCallback) {
153
+    checkExtInstalled(
154
+        function (isInstalled) {
155
+            if (isInstalled) {
156
+                doGetStreamFromExtension(streamCallback, failCallback);
157
+            } else {
158
+                chrome.webstore.install(
159
+                    getWebStoreInstallUrl(),
160
+                    function (arg) {
161
+                        console.log("Extension installed successfully", arg);
162
+                        // We need to reload the page in order to get the access to chrome.runtime
163
+                        window.location.reload(false);
164
+                    },
165
+                    function (arg) {
166
+                        console.log("Failed to install the extension", arg);
167
+                        failCallback(arg);
168
+                    }
169
+                );
170
+            }
171
+        }
172
+    );
173
+}
174
+
25 175
 /**
26 176
  * @returns {boolean} <tt>true</tt> if desktop sharing feature is available and enabled.
27 177
  */
28 178
 function isDesktopSharingEnabled() {
29
-    if(_desktopSharingEnabled === null){
30
-        if(obtainDesktopStream === obtainScreenFromExtension) {
179
+    if (_desktopSharingEnabled === null) {
180
+        if (obtainDesktopStream === obtainScreenFromExtension) {
31 181
             // Parse chrome version
32 182
             var userAgent = navigator.userAgent.toLowerCase();
33 183
             // We can assume that user agent is chrome, because it's enforced when 'ext' streaming method is set
@@ -41,6 +191,14 @@ function isDesktopSharingEnabled() {
41 191
     return _desktopSharingEnabled;
42 192
 }
43 193
 
194
+function showDesktopSharingButton() {
195
+    if (isDesktopSharingEnabled()) {
196
+        $('#desktopsharing').css({display: "inline"});
197
+    } else {
198
+        $('#desktopsharing').css({display: "none"});
199
+    }
200
+}
201
+
44 202
 /**
45 203
  * Call this method to toggle desktop sharing feature.
46 204
  * @param method pass "ext" to use chrome extension for desktop capture(chrome extension required),
@@ -49,13 +207,13 @@ function isDesktopSharingEnabled() {
49 207
  */
50 208
 function setDesktopSharing(method) {
51 209
     // Check if we are running chrome
52
-    if(!navigator.webkitGetUserMedia){
210
+    if (!navigator.webkitGetUserMedia) {
53 211
         obtainDesktopStream = null;
54 212
         console.info("Desktop sharing disabled");
55
-    } else if(method == "ext") {
213
+    } else if (method == "ext") {
56 214
         obtainDesktopStream = obtainScreenFromExtension;
57 215
         console.info("Using Chrome extension for desktop sharing");
58
-    } else if(method == "webrtc") {
216
+    } else if (method == "webrtc") {
59 217
         obtainDesktopStream = obtainWebRTCScreen;
60 218
         console.info("Using Chrome WebRTC for desktop sharing");
61 219
     }
@@ -66,14 +224,6 @@ function setDesktopSharing(method) {
66 224
     showDesktopSharingButton();
67 225
 }
68 226
 
69
-function showDesktopSharingButton() {
70
-    if(isDesktopSharingEnabled()) {
71
-        $('#desktopsharing').css( {display:"inline"} );
72
-    } else {
73
-        $('#desktopsharing').css( {display:"none"} );
74
-    }
75
-}
76
-
77 227
 /**
78 228
  * Initializes <link rel=chrome-webstore-item /> with extension id set in config.js to support inline installs.
79 229
  * Host site must be selected as main website of published extension.
@@ -83,14 +233,34 @@ function initInlineInstalls()
83 233
     $("link[rel=chrome-webstore-item]").attr("href", getWebStoreInstallUrl());
84 234
 }
85 235
 
86
-/**
87
- * Constructs inline install URL for Chrome desktop streaming extension.
88
- * The 'chromeExtensionId' must be defined in config.js.
89
- * @returns {string}
90
- */
91
-function getWebStoreInstallUrl()
92
-{
93
-    return "https://chrome.google.com/webstore/detail/" + config.chromeExtensionId;
236
+function getSwitchStreamFailed(error) {
237
+    console.error("Failed to obtain the stream to switch to", error);
238
+    switchInProgress = false;
239
+}
240
+
241
+function streamSwitchDone() {
242
+    //window.setTimeout(
243
+    //    function () {
244
+    switchInProgress = false;
245
+    //    }, 100
246
+    //);
247
+}
248
+
249
+function newStreamCreated(stream) {
250
+
251
+    var oldStream = connection.jingle.localVideo;
252
+
253
+    change_local_video(stream, !isUsingScreenStream);
254
+
255
+    var conferenceHandler = getConferenceHandler();
256
+    if (conferenceHandler) {
257
+        // FIXME: will block switchInProgress on true value in case of exception
258
+        conferenceHandler.switchStreams(stream, oldStream, streamSwitchDone);
259
+    } else {
260
+        // We are done immediately
261
+        console.error("No conference handler");
262
+        streamSwitchDone();
263
+    }
94 264
 }
95 265
 
96 266
 /*
@@ -104,28 +274,28 @@ function toggleScreenSharing() {
104 274
     switchInProgress = true;
105 275
 
106 276
     // Only the focus is able to set a shared key.
107
-    if(!isUsingScreenStream)
277
+    if (!isUsingScreenStream)
108 278
     {
109 279
         obtainDesktopStream(
110
-            function(stream) {
280
+            function (stream) {
111 281
                 // We now use screen stream
112 282
                 isUsingScreenStream = true;
113 283
                 // Hook 'ended' event to restore camera when screen stream stops
114 284
                 stream.addEventListener('ended',
115
-                    function(e) {
116
-                        if(!switchInProgress && isUsingScreenStream) {
285
+                    function (e) {
286
+                        if (!switchInProgress && isUsingScreenStream) {
117 287
                             toggleScreenSharing();
118 288
                         }
119 289
                     }
120 290
                 );
121 291
                 newStreamCreated(stream);
122 292
             },
123
-            getSwitchStreamFailed );
293
+            getSwitchStreamFailed);
124 294
     } else {
125 295
         // Disable screen stream
126 296
         getUserMediaWithConstraints(
127 297
             ['video'],
128
-            function(stream) {
298
+            function (stream) {
129 299
                 // We are now using camera stream
130 300
                 isUsingScreenStream = false;
131 301
                 newStreamCreated(stream);
@@ -135,170 +305,3 @@ function toggleScreenSharing() {
135 305
     }
136 306
 }
137 307
 
138
-function getSwitchStreamFailed(error) {
139
-    console.error("Failed to obtain the stream to switch to", error);
140
-    switchInProgress = false;
141
-}
142
-
143
-function newStreamCreated(stream) {
144
-
145
-    var oldStream = connection.jingle.localVideo;
146
-
147
-    change_local_video(stream, !isUsingScreenStream);
148
-
149
-    var conferenceHandler = getConferenceHandler();
150
-    if(conferenceHandler) {
151
-        // FIXME: will block switchInProgress on true value in case of exception
152
-        conferenceHandler.switchStreams(stream, oldStream, streamSwitchDone);
153
-    } else {
154
-        // We are done immediately
155
-        console.error("No conference handler");
156
-        streamSwitchDone();
157
-    }
158
-}
159
-
160
-function streamSwitchDone() {
161
-    //window.setTimeout(
162
-    //    function() {
163
-            switchInProgress = false;
164
-    //    }, 100
165
-    //);
166
-}
167
-
168
-/**
169
- * Method obtains desktop stream from WebRTC 'screen' source.
170
- * Flag 'chrome://flags/#enable-usermedia-screen-capture' must be enabled.
171
- */
172
-function obtainWebRTCScreen(streamCallback, failCallback) {
173
-    getUserMediaWithConstraints(
174
-        ['screen'],
175
-        streamCallback,
176
-        failCallback
177
-    );
178
-}
179
-
180
-/**
181
- * Asks Chrome extension to call chooseDesktopMedia and gets chrome 'desktop' stream for returned stream token.
182
- */
183
-function obtainScreenFromExtension(streamCallback, failCallback) {
184
-    checkExtInstalled(
185
-        function(isInstalled) {
186
-            if(isInstalled) {
187
-                doGetStreamFromExtension(streamCallback, failCallback);
188
-            } else {
189
-                chrome.webstore.install(
190
-                    getWebStoreInstallUrl(),
191
-                    function(arg) {
192
-                        console.log("Extension installed successfully", arg);
193
-                        // We need to reload the page in order to get the access to chrome.runtime
194
-                        window.location.reload(false);
195
-                    },
196
-                    function(arg) {
197
-                        console.log("Failed to install the extension", arg);
198
-                        failCallback(arg);
199
-                    }
200
-                );
201
-            }
202
-        }
203
-    );
204
-}
205
-
206
-function checkExtInstalled(isInstalledCallback) {
207
-    if(!chrome.runtime) {
208
-        // No API, so no extension for sure
209
-        isInstalledCallback(false);
210
-    }
211
-    chrome.runtime.sendMessage(
212
-        config.chromeExtensionId,
213
-        { getVersion: true },
214
-        function(response){
215
-            if(!response || !response.version) {
216
-                // Communication failure - assume that no endpoint exists
217
-                console.warn("Extension not installed?: "+chrome.runtime.lastError);
218
-                isInstalledCallback(false);
219
-            } else {
220
-                // Check installed extension version
221
-                var extVersion = response.version;
222
-                console.log('Extension version is: '+extVersion);
223
-                var updateRequired = isUpdateRequired(config.minChromeExtVersion, extVersion);
224
-                if(updateRequired) {
225
-                    alert(
226
-                        'Jitsi Desktop Streamer requires update. ' +
227
-                        'Changes will take effect after next Chrome restart.' );
228
-                }
229
-                isInstalledCallback(!updateRequired);
230
-            }
231
-        }
232
-    );
233
-}
234
-
235
-/**
236
- * Checks whether extension update is required.
237
- * @param minVersion minimal required version
238
- * @param extVersion current extension version
239
- * @returns {boolean}
240
- */
241
-function isUpdateRequired(minVersion, extVersion)
242
-{
243
-    try
244
-    {
245
-        var s1 = minVersion.split('.');
246
-        var s2 = extVersion.split('.');
247
-
248
-        var len = Math.max(s1.length, s2.length);
249
-        for(var i = 0; i < len; i++)
250
-        {
251
-            var n1=0,n2=0;
252
-
253
-            if(i < s1.length)
254
-                n1 = parseInt(s1[i]);
255
-            if(i < s2.length)
256
-                n2 = parseInt(s2[i]);
257
-
258
-            if(isNaN(n1) || isNaN(n2))
259
-            {
260
-                return true;
261
-            }
262
-            else if(n1 !== n2)
263
-            {
264
-                return n1 > n2;
265
-            }
266
-        }
267
-
268
-        // will happen if boths version has identical numbers in
269
-        // their components (even if one of them is longer, has more components)
270
-        return false;
271
-    }
272
-    catch(e)
273
-    {
274
-        console.error("Failed to parse extension version", e);
275
-        return true;
276
-    }
277
-}
278
-
279
-function doGetStreamFromExtension(streamCallback, failCallback) {
280
-    // Sends 'getStream' msg to the extension. Extension id must be defined in the config.
281
-    chrome.runtime.sendMessage(
282
-        config.chromeExtensionId,
283
-        { getStream: true},
284
-        function(response) {
285
-            if(!response) {
286
-                failCallback(chrome.runtime.lastError);
287
-                return;
288
-            }
289
-            console.log("Response from extension: "+response);
290
-            if(response.streamId) {
291
-                getUserMediaWithConstraints(
292
-                    ['desktop'],
293
-                    function(stream) {
294
-                        streamCallback(stream);
295
-                    },
296
-                    failCallback,
297
-                    null, null, null,
298
-                    response.streamId);
299
-            } else {
300
-                failCallback("Extension failed to get the stream");
301
-            }
302
-        }
303
-    );
304
-}

+ 1
- 0
estos_log.js View File

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

+ 13
- 12
etherpad.js View File

@@ -1,3 +1,4 @@
1
+/* global $, config, Prezi, Util, connection, setLargeVideoVisible, dockToolbar */
1 2
 var Etherpad = (function (my) {
2 3
     var etherpadName = null;
3 4
     var etherpadIFrame = null;
@@ -15,8 +16,8 @@ var Etherpad = (function (my) {
15 16
 
16 17
             if (!name) {
17 18
                 // In case we're the focus we generate the name.
18
-                etherpadName = Math.random().toString(36).substring(7)
19
-                                + '_' + (new Date().getTime()).toString();
19
+                etherpadName = Math.random().toString(36).substring(7) +
20
+                                '_' + (new Date().getTime()).toString();
20 21
                 shareEtherpad();
21 22
             }
22 23
             else
@@ -41,27 +42,27 @@ var Etherpad = (function (my) {
41 42
 
42 43
         if ($('#etherpad>iframe').css('visibility') === 'hidden') {
43 44
             largeVideo.fadeOut(300, function () {
44
-                if (Prezi.isPresentationVisible())
45
-                    largeVideo.css({opacity:'0'});
46
-                else {
45
+                if (Prezi.isPresentationVisible()) {
46
+                    largeVideo.css({opacity: '0'});
47
+                } else {
47 48
                     setLargeVideoVisible(false);
48 49
                     dockToolbar(true);
49 50
                 }
50 51
 
51
-                $('#etherpad>iframe').fadeIn(300, function() {
52
+                $('#etherpad>iframe').fadeIn(300, function () {
52 53
                     document.body.style.background = '#eeeeee';
53
-                    $('#etherpad>iframe').css({visibility:'visible'});
54
-                    $('#etherpad').css({zIndex:2});
54
+                    $('#etherpad>iframe').css({visibility: 'visible'});
55
+                    $('#etherpad').css({zIndex: 2});
55 56
                 });
56 57
             });
57 58
         }
58 59
         else if ($('#etherpad>iframe')) {
59 60
             $('#etherpad>iframe').fadeOut(300, function () {
60
-                $('#etherpad>iframe').css({visibility:'hidden'});
61
-                $('#etherpad').css({zIndex:0});
61
+                $('#etherpad>iframe').css({visibility: 'hidden'});
62
+                $('#etherpad').css({zIndex: 0});
62 63
                 document.body.style.background = 'black';
63 64
                 if (!isPresentation) {
64
-                    $('#largeVideo').fadeIn(300, function() {
65
+                    $('#largeVideo').fadeIn(300, function () {
65 66
                         setLargeVideoVisible(true);
66 67
                         dockToolbar(false);
67 68
                     });
@@ -99,7 +100,7 @@ var Etherpad = (function (my) {
99 100
      */
100 101
     function enableEtherpadButton() {
101 102
         if (!$('#etherpadButton').is(":visible"))
102
-            $('#etherpadButton').css({display:'inline-block'});
103
+            $('#etherpadButton').css({display: 'inline-block'});
103 104
     }
104 105
 
105 106
     /**

+ 9
- 10
util.js View File

@@ -1,3 +1,4 @@
1
+/* global $ */
1 2
 /**
2 3
  * Utility functions.
3 4
  */
@@ -8,7 +9,7 @@ var Util = (function (my) {
8 9
      *
9 10
      * @param el the element
10 11
      */
11
-    my.getTextWidth = function(el) {
12
+    my.getTextWidth = function (el) {
12 13
         return (el.clientWidth + 1);
13 14
     };
14 15
 
@@ -17,7 +18,7 @@ var Util = (function (my) {
17 18
      *
18 19
      * @param el the element
19 20
      */
20
-    my.getTextHeight = function(el) {
21
+    my.getTextHeight = function (el) {
21 22
         return (el.clientHeight + 1);
22 23
     };
23 24
 
@@ -26,7 +27,7 @@ var Util = (function (my) {
26 27
      *
27 28
      * @param number the number to cast
28 29
      */
29
-    my.toInteger = function(number) {
30
+    my.toInteger = function (number) {
30 31
         return Math.round(Number(number));
31 32
     };
32 33
 
@@ -35,27 +36,25 @@ var Util = (function (my) {
35 36
      *
36 37
      * @param id the identifier of the audio element.
37 38
      */
38
-    my.playSoundNotification = function(id) {
39
+    my.playSoundNotification = function (id) {
39 40
         document.getElementById(id).play();
40 41
     };
41 42
 
42 43
     /**
43 44
      * Escapes the given text.
44 45
      */
45
-    my.escapeHtml = function(unsafeText) {
46
+    my.escapeHtml = function (unsafeText) {
46 47
         return $('<div/>').text(unsafeText).html();
47 48
     };
48 49
 
49 50
     /**
50 51
      * Returns the available video width.
51 52
      */
52
-    my.getAvailableVideoWidth = function() {
53
-        var chatspaceWidth = $('#chatspace').is(":visible")
54
-        ? $('#chatspace').width()
55
-        : 0;
53
+    my.getAvailableVideoWidth = function () {
54
+        var chatspaceWidth = $('#chatspace').is(":visible") ? $('#chatspace').width() : 0;
56 55
 
57 56
         return window.innerWidth - chatspaceWidth;
58 57
     };
59 58
 
60 59
     return my;
61
-}(Util || {}));
60
+}(Util || {}));

Loading…
Cancel
Save