ソースを参照

feat(external_api): make height / width calculation more resilient

master
Saúl Ibarra Corretgé 8年前
コミット
7b1639569e
1個のファイルの変更28行の追加4行の削除
  1. 28
    4
      modules/API/external/external_api.js

+ 28
- 4
modules/API/external/external_api.js ファイルの表示

@@ -182,8 +182,7 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
182 182
             noSSL,
183 183
             roomName
184 184
         });
185
-        this._createIFrame(Math.max(height, MIN_HEIGHT),
186
-            Math.max(width, MIN_WIDTH));
185
+        this._createIFrame(height, width);
187 186
         this._transport = new Transport({
188 187
             backend: new PostMessageTransportBackend({
189 188
                 postisOptions: {
@@ -207,11 +206,36 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
207 206
      * @private
208 207
      */
209 208
     _createIFrame(height, width) {
209
+        // Compute valid values for height and width. If a number is specified
210
+        // it's treated as pixel units and our minimum constraints are applied.
211
+        // If the value is expressed in em, pt or percentage, it's used as is.
212
+        // Also protect ourselves from undefined, because
213
+        // Math.max(undefined, 100) === NaN, obviously.
214
+        //
215
+        // This regex parses values of the form 100em, 100pt or 100%. Values
216
+        // like 100 or 100px are handled outside of the regex, and invalid
217
+        // values will be ignored and the minimum will be used.
218
+        const re = /([0-9]*\.?[0-9]+)(em|pt|%)$/;
219
+
220
+        /* eslint-disable no-param-reassign */
221
+
222
+        if (String(height).match(re) === null) {
223
+            height = parseInt(height, 10) || MIN_HEIGHT;
224
+            height = `${Math.max(height, MIN_HEIGHT)}px`;
225
+        }
226
+
227
+        if (String(width).match(re) === null) {
228
+            width = parseInt(width, 10) || MIN_WIDTH;
229
+            width = `${Math.max(width, MIN_WIDTH)}px`;
230
+        }
231
+
232
+        /* eslint-enable no-param-reassign */
233
+
210 234
         this.iframeHolder
211 235
             = this.parentNode.appendChild(document.createElement('div'));
212 236
         this.iframeHolder.id = `jitsiConference${id}`;
213
-        this.iframeHolder.style.width = `${width}px`;
214
-        this.iframeHolder.style.height = `${height}px`;
237
+        this.iframeHolder.style.width = width;
238
+        this.iframeHolder.style.height = height;
215 239
 
216 240
         this.frameName = `jitsiConferenceFrame${id}`;
217 241
 

読み込み中…
キャンセル
保存