Quellcode durchsuchen

replace resourceIds with ids in AudioLevels

master
isymchych vor 9 Jahren
Ursprung
Commit
6a3704d826
2 geänderte Dateien mit 64 neuen und 71 gelöschten Zeilen
  1. 2
    2
      modules/UI/UI.js
  2. 62
    69
      modules/UI/audio_levels/AudioLevels.js

+ 2
- 2
modules/UI/UI.js Datei anzeigen

@@ -603,9 +603,9 @@ UI.handleLastNEndpoints = function (ids) {
603 603
     VideoLayout.onLastNEndpointsChanged(ids, []);
604 604
 };
605 605
 
606
-UI.setAudioLevel = function (targetJid, lvl) {
606
+UI.setAudioLevel = function (id, lvl) {
607 607
     AudioLevels.updateAudioLevel(
608
-        targetJid, lvl, VideoLayout.getLargeVideoResource()
608
+        id, lvl, VideoLayout.getLargeVideoResource()
609 609
     );
610 610
 };
611 611
 

+ 62
- 69
modules/UI/audio_levels/AudioLevels.js Datei anzeigen

@@ -1,6 +1,6 @@
1
-/* global APP, interfaceConfig, $, Strophe */
1
+/* global APP, interfaceConfig, $ */
2 2
 /* jshint -W101 */
3
-var CanvasUtil = require("./CanvasUtils");
3
+import CanvasUtil from './CanvasUtils';
4 4
 
5 5
 var ASDrawContext = null;
6 6
 
@@ -31,91 +31,83 @@ var AudioLevels = (function(my) {
31 31
     };
32 32
 
33 33
     /**
34
-     * Updates the audio level canvas for the given peerJid. If the canvas
34
+     * Updates the audio level canvas for the given id. If the canvas
35 35
      * didn't exist we create it.
36 36
      */
37
-    my.updateAudioLevelCanvas = function (peerJid, VideoLayout) {
38
-        var resourceJid = null;
39
-        var videoSpanId = null;
40
-        if (!peerJid)
41
-            videoSpanId = 'localVideoContainer';
42
-        else {
43
-            resourceJid = Strophe.getResourceFromJid(peerJid);
44
-
45
-            videoSpanId = 'participant_' + resourceJid;
37
+    my.updateAudioLevelCanvas = function (id, VideoLayout) {
38
+        let videoSpanId = 'localVideoContainer';
39
+        if (id) {
40
+            videoSpanId = `participant_${id}`;
46 41
         }
47 42
 
48
-        var videoSpan = document.getElementById(videoSpanId);
43
+        let videoSpan = document.getElementById(videoSpanId);
49 44
 
50 45
         if (!videoSpan) {
51
-            if (resourceJid)
52
-                console.error("No video element for jid", resourceJid);
53
-            else
46
+            if (id) {
47
+                console.error("No video element for id", id);
48
+            } else {
54 49
                 console.error("No video element for local video.");
55
-
50
+            }
56 51
             return;
57 52
         }
58 53
 
59
-        var audioLevelCanvas = $('#' + videoSpanId + '>canvas');
54
+        let audioLevelCanvas = $(`#${videoSpanId}>canvas`);
60 55
 
61
-        var videoSpaceWidth = $('#remoteVideos').width();
62
-        var thumbnailSize = VideoLayout.calculateThumbnailSize(videoSpaceWidth);
63
-        var thumbnailWidth = thumbnailSize[0];
64
-        var thumbnailHeight = thumbnailSize[1];
56
+        let videoSpaceWidth = $('#remoteVideos').width();
57
+        let thumbnailSize = VideoLayout.calculateThumbnailSize(videoSpaceWidth);
58
+        let thumbnailWidth = thumbnailSize[0];
59
+        let thumbnailHeight = thumbnailSize[1];
65 60
 
66 61
         if (!audioLevelCanvas || audioLevelCanvas.length === 0) {
67 62
 
68 63
             audioLevelCanvas = document.createElement('canvas');
69 64
             audioLevelCanvas.className = "audiolevel";
70
-            audioLevelCanvas.style.bottom = "-" + interfaceConfig.CANVAS_EXTRA/2 + "px";
71
-            audioLevelCanvas.style.left = "-" + interfaceConfig.CANVAS_EXTRA/2 + "px";
72
-            resizeAudioLevelCanvas( audioLevelCanvas,
73
-                    thumbnailWidth,
74
-                    thumbnailHeight);
65
+            audioLevelCanvas.style.bottom = `-${interfaceConfig.CANVAS_EXTRA/2}px`;
66
+            audioLevelCanvas.style.left = `-${interfaceConfig.CANVAS_EXTRA/2}px`;
67
+            resizeAudioLevelCanvas(audioLevelCanvas, thumbnailWidth, thumbnailHeight);
75 68
 
76 69
             videoSpan.appendChild(audioLevelCanvas);
77 70
         } else {
78 71
             audioLevelCanvas = audioLevelCanvas.get(0);
79 72
 
80
-            resizeAudioLevelCanvas( audioLevelCanvas,
81
-                    thumbnailWidth,
82
-                    thumbnailHeight);
73
+            resizeAudioLevelCanvas(audioLevelCanvas, thumbnailWidth, thumbnailHeight);
83 74
         }
84 75
     };
85 76
 
86 77
     /**
87
-     * Updates the audio level UI for the given resourceJid.
78
+     * Updates the audio level UI for the given id.
88 79
      *
89
-     * @param resourceJid the resource jid indicating the video element for
90
-     * which we draw the audio level
80
+     * @param id id of the user for whom we draw the audio level
91 81
      * @param audioLevel the newAudio level to render
92 82
      */
93
-    my.updateAudioLevel = function (resourceJid, audioLevel, largeVideoResourceJid) {
94
-        drawAudioLevelCanvas(resourceJid, audioLevel);
83
+    my.updateAudioLevel = function (id, audioLevel, largeVideoId) {
84
+        drawAudioLevelCanvas(id, audioLevel);
95 85
 
96
-        var videoSpanId = getVideoSpanId(resourceJid);
86
+        let videoSpanId = getVideoSpanId(id);
97 87
 
98
-        var audioLevelCanvas = $('#' + videoSpanId + '>canvas').get(0);
88
+        let audioLevelCanvas = $(`#${videoSpanId}>canvas`).get(0);
99 89
 
100
-        if (!audioLevelCanvas)
90
+        if (!audioLevelCanvas) {
101 91
             return;
92
+        }
102 93
 
103
-        var drawContext = audioLevelCanvas.getContext('2d');
94
+        let drawContext = audioLevelCanvas.getContext('2d');
104 95
 
105
-        var canvasCache = audioLevelCanvasCache[resourceJid];
96
+        let canvasCache = audioLevelCanvasCache[id];
106 97
 
107
-        drawContext.clearRect (0, 0,
108
-                audioLevelCanvas.width, audioLevelCanvas.height);
98
+        drawContext.clearRect(
99
+            0, 0, audioLevelCanvas.width, audioLevelCanvas.height
100
+        );
109 101
         drawContext.drawImage(canvasCache, 0, 0);
110 102
 
111
-        if(resourceJid === AudioLevels.LOCAL_LEVEL) {
112
-            resourceJid = APP.conference.localId;
113
-            if (!resourceJid) {
103
+        if (id === AudioLevels.LOCAL_LEVEL) {
104
+            id = APP.conference.localId;
105
+            if (!id) {
114 106
                 return;
115 107
             }
116 108
         }
117 109
 
118
-        if(resourceJid === largeVideoResourceJid) {
110
+        if(id === largeVideoId) {
119 111
             window.requestAnimationFrame(function () {
120 112
                 AudioLevels.updateActiveSpeakerAudioLevel(audioLevel);
121 113
             });
@@ -123,12 +115,14 @@ var AudioLevels = (function(my) {
123 115
     };
124 116
 
125 117
     my.updateActiveSpeakerAudioLevel = function(audioLevel) {
126
-        if($("#activeSpeaker").css("visibility") == "hidden" || ASDrawContext === null)
118
+        if($("#activeSpeaker").css("visibility") == "hidden" || ASDrawContext === null) {
127 119
             return;
120
+        }
128 121
 
129 122
         ASDrawContext.clearRect(0, 0, 300, 300);
130
-        if (!audioLevel)
123
+        if (!audioLevel) {
131 124
             return;
125
+        }
132 126
 
133 127
         ASDrawContext.shadowBlur = getShadowLevel(audioLevel);
134 128
 
@@ -150,16 +144,15 @@ var AudioLevels = (function(my) {
150 144
     /**
151 145
      * Draws the audio level canvas into the cached canvas object.
152 146
      *
153
-     * @param resourceJid the resource jid indicating the video element for
154
-     * which we draw the audio level
147
+     * @param id of the user for whom we draw the audio level
155 148
      * @param audioLevel the newAudio level to render
156 149
      */
157
-    function drawAudioLevelCanvas(resourceJid, audioLevel) {
158
-        if (!audioLevelCanvasCache[resourceJid]) {
150
+    function drawAudioLevelCanvas(id, audioLevel) {
151
+        if (!audioLevelCanvasCache[id]) {
159 152
 
160
-            var videoSpanId = getVideoSpanId(resourceJid);
153
+            let videoSpanId = getVideoSpanId(id);
161 154
 
162
-            var audioLevelCanvasOrig = $('#' + videoSpanId + '>canvas').get(0);
155
+            let audioLevelCanvasOrig = $(`#${videoSpanId}>canvas`).get(0);
163 156
 
164 157
             /*
165 158
              * FIXME Testing has shown that audioLevelCanvasOrig may not exist.
@@ -168,21 +161,21 @@ var AudioLevels = (function(my) {
168 161
              * been observed to pile into the console, strain the CPU.
169 162
              */
170 163
             if (audioLevelCanvasOrig) {
171
-                audioLevelCanvasCache[resourceJid] =
172
-                    CanvasUtil.cloneCanvas(audioLevelCanvasOrig);
164
+                audioLevelCanvasCache[id] = CanvasUtil.cloneCanvas(audioLevelCanvasOrig);
173 165
             }
174 166
         }
175 167
 
176
-        var canvas = audioLevelCanvasCache[resourceJid];
168
+        let canvas = audioLevelCanvasCache[id];
177 169
 
178
-        if (!canvas)
170
+        if (!canvas) {
179 171
             return;
172
+        }
180 173
 
181
-        var drawContext = canvas.getContext('2d');
174
+        let drawContext = canvas.getContext('2d');
182 175
 
183 176
         drawContext.clearRect(0, 0, canvas.width, canvas.height);
184 177
 
185
-        var shadowLevel = getShadowLevel(audioLevel);
178
+        let shadowLevel = getShadowLevel(audioLevel);
186 179
 
187 180
         if (shadowLevel > 0) {
188 181
             // drawContext, x, y, w, h, r, shadowColor, shadowLevel
@@ -218,15 +211,14 @@ var AudioLevels = (function(my) {
218 211
     }
219 212
 
220 213
     /**
221
-     * Returns the video span id corresponding to the given resourceJid or local
222
-     * user.
214
+     * Returns the video span id corresponding to the given user id
223 215
      */
224
-    function getVideoSpanId(resourceJid) {
216
+    function getVideoSpanId(id) {
225 217
         var videoSpanId = null;
226
-        if (resourceJid === AudioLevels.LOCAL_LEVEL || APP.conference.isLocalId(resourceJid)) {
218
+        if (id === AudioLevels.LOCAL_LEVEL || APP.conference.isLocalId(id)) {
227 219
             videoSpanId = 'localVideoContainer';
228 220
         } else {
229
-            videoSpanId = 'participant_' + resourceJid;
221
+            videoSpanId = `participant_${id}`;
230 222
         }
231 223
 
232 224
         return videoSpanId;
@@ -250,13 +242,14 @@ var AudioLevels = (function(my) {
250 242
             }
251 243
         });
252 244
 
253
-        if (resized)
254
-            Object.keys(audioLevelCanvasCache).forEach(function (resourceJid) {
255
-                audioLevelCanvasCache[resourceJid].width =
245
+        if (resized) {
246
+            Object.keys(audioLevelCanvasCache).forEach(function (id) {
247
+                audioLevelCanvasCache[id].width =
256 248
                     width + interfaceConfig.CANVAS_EXTRA;
257
-                audioLevelCanvasCache[resourceJid].height =
249
+                audioLevelCanvasCache[id].height =
258 250
                     height + interfaceConfig.CANVAS_EXTRA;
259 251
             });
252
+        }
260 253
     });
261 254
 
262 255
     return my;

Laden…
Abbrechen
Speichern