浏览代码

replace resourceIds with ids in AudioLevels

master
isymchych 9 年前
父节点
当前提交
6a3704d826
共有 2 个文件被更改,包括 64 次插入71 次删除
  1. 2
    2
      modules/UI/UI.js
  2. 62
    69
      modules/UI/audio_levels/AudioLevels.js

+ 2
- 2
modules/UI/UI.js 查看文件

603
     VideoLayout.onLastNEndpointsChanged(ids, []);
603
     VideoLayout.onLastNEndpointsChanged(ids, []);
604
 };
604
 };
605
 
605
 
606
-UI.setAudioLevel = function (targetJid, lvl) {
606
+UI.setAudioLevel = function (id, lvl) {
607
     AudioLevels.updateAudioLevel(
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 查看文件

1
-/* global APP, interfaceConfig, $, Strophe */
1
+/* global APP, interfaceConfig, $ */
2
 /* jshint -W101 */
2
 /* jshint -W101 */
3
-var CanvasUtil = require("./CanvasUtils");
3
+import CanvasUtil from './CanvasUtils';
4
 
4
 
5
 var ASDrawContext = null;
5
 var ASDrawContext = null;
6
 
6
 
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
      * didn't exist we create it.
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
         if (!videoSpan) {
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
                 console.error("No video element for local video.");
49
                 console.error("No video element for local video.");
55
-
50
+            }
56
             return;
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
         if (!audioLevelCanvas || audioLevelCanvas.length === 0) {
61
         if (!audioLevelCanvas || audioLevelCanvas.length === 0) {
67
 
62
 
68
             audioLevelCanvas = document.createElement('canvas');
63
             audioLevelCanvas = document.createElement('canvas');
69
             audioLevelCanvas.className = "audiolevel";
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
             videoSpan.appendChild(audioLevelCanvas);
69
             videoSpan.appendChild(audioLevelCanvas);
77
         } else {
70
         } else {
78
             audioLevelCanvas = audioLevelCanvas.get(0);
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
      * @param audioLevel the newAudio level to render
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
             return;
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
         drawContext.drawImage(canvasCache, 0, 0);
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
                 return;
106
                 return;
115
             }
107
             }
116
         }
108
         }
117
 
109
 
118
-        if(resourceJid === largeVideoResourceJid) {
110
+        if(id === largeVideoId) {
119
             window.requestAnimationFrame(function () {
111
             window.requestAnimationFrame(function () {
120
                 AudioLevels.updateActiveSpeakerAudioLevel(audioLevel);
112
                 AudioLevels.updateActiveSpeakerAudioLevel(audioLevel);
121
             });
113
             });
123
     };
115
     };
124
 
116
 
125
     my.updateActiveSpeakerAudioLevel = function(audioLevel) {
117
     my.updateActiveSpeakerAudioLevel = function(audioLevel) {
126
-        if($("#activeSpeaker").css("visibility") == "hidden" || ASDrawContext === null)
118
+        if($("#activeSpeaker").css("visibility") == "hidden" || ASDrawContext === null) {
127
             return;
119
             return;
120
+        }
128
 
121
 
129
         ASDrawContext.clearRect(0, 0, 300, 300);
122
         ASDrawContext.clearRect(0, 0, 300, 300);
130
-        if (!audioLevel)
123
+        if (!audioLevel) {
131
             return;
124
             return;
125
+        }
132
 
126
 
133
         ASDrawContext.shadowBlur = getShadowLevel(audioLevel);
127
         ASDrawContext.shadowBlur = getShadowLevel(audioLevel);
134
 
128
 
150
     /**
144
     /**
151
      * Draws the audio level canvas into the cached canvas object.
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
      * @param audioLevel the newAudio level to render
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
              * FIXME Testing has shown that audioLevelCanvasOrig may not exist.
158
              * FIXME Testing has shown that audioLevelCanvasOrig may not exist.
168
              * been observed to pile into the console, strain the CPU.
161
              * been observed to pile into the console, strain the CPU.
169
              */
162
              */
170
             if (audioLevelCanvasOrig) {
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
             return;
171
             return;
172
+        }
180
 
173
 
181
-        var drawContext = canvas.getContext('2d');
174
+        let drawContext = canvas.getContext('2d');
182
 
175
 
183
         drawContext.clearRect(0, 0, canvas.width, canvas.height);
176
         drawContext.clearRect(0, 0, canvas.width, canvas.height);
184
 
177
 
185
-        var shadowLevel = getShadowLevel(audioLevel);
178
+        let shadowLevel = getShadowLevel(audioLevel);
186
 
179
 
187
         if (shadowLevel > 0) {
180
         if (shadowLevel > 0) {
188
             // drawContext, x, y, w, h, r, shadowColor, shadowLevel
181
             // drawContext, x, y, w, h, r, shadowColor, shadowLevel
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
         var videoSpanId = null;
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
             videoSpanId = 'localVideoContainer';
219
             videoSpanId = 'localVideoContainer';
228
         } else {
220
         } else {
229
-            videoSpanId = 'participant_' + resourceJid;
221
+            videoSpanId = `participant_${id}`;
230
         }
222
         }
231
 
223
 
232
         return videoSpanId;
224
         return videoSpanId;
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
                     width + interfaceConfig.CANVAS_EXTRA;
248
                     width + interfaceConfig.CANVAS_EXTRA;
257
-                audioLevelCanvasCache[resourceJid].height =
249
+                audioLevelCanvasCache[id].height =
258
                     height + interfaceConfig.CANVAS_EXTRA;
250
                     height + interfaceConfig.CANVAS_EXTRA;
259
             });
251
             });
252
+        }
260
     });
253
     });
261
 
254
 
262
     return my;
255
     return my;

正在加载...
取消
保存