|
@@ -45,18 +45,6 @@ const events = {
|
45
|
45
|
*/
|
46
|
46
|
let id = 0;
|
47
|
47
|
|
48
|
|
-/**
|
49
|
|
- * The minimum height for the Jitsi Meet frame
|
50
|
|
- * @type {number}
|
51
|
|
- */
|
52
|
|
-const MIN_HEIGHT = 300;
|
53
|
|
-
|
54
|
|
-/**
|
55
|
|
- * The minimum width for the Jitsi Meet frame
|
56
|
|
- * @type {number}
|
57
|
|
- */
|
58
|
|
-const MIN_WIDTH = 790;
|
59
|
|
-
|
60
|
48
|
/**
|
61
|
49
|
* Adds given number to the numberOfParticipants property of given APIInstance.
|
62
|
50
|
*
|
|
@@ -190,6 +178,34 @@ function parseArguments(args) {
|
190
|
178
|
}
|
191
|
179
|
}
|
192
|
180
|
|
|
181
|
+/**
|
|
182
|
+ * Compute valid values for height and width. If a number is specified it's
|
|
183
|
+ * treated as pixel units. If the value is expressed in px, em, pt or
|
|
184
|
+ * percentage, it's used as is.
|
|
185
|
+ *
|
|
186
|
+ * @param {any} value - The value to be parsed.
|
|
187
|
+ * @returns {string|undefined} The parsed value that can be used for setting
|
|
188
|
+ * sizes through the style property. If invalid value is passed the method
|
|
189
|
+ * retuns undefined.
|
|
190
|
+ */
|
|
191
|
+function parseSizeParam(value) {
|
|
192
|
+ let parsedValue;
|
|
193
|
+
|
|
194
|
+ // This regex parses values of the form 100px, 100em, 100pt or 100%.
|
|
195
|
+ // Values like 100 or 100px are handled outside of the regex, and
|
|
196
|
+ // invalid values will be ignored and the minimum will be used.
|
|
197
|
+ const re = /([0-9]*\.?[0-9]+)(em|pt|px|%)$/;
|
|
198
|
+
|
|
199
|
+ if (typeof value === 'string' && String(value).match(re) !== null) {
|
|
200
|
+ parsedValue = value;
|
|
201
|
+ } else if (typeof value === 'number') {
|
|
202
|
+ parsedValue = `${value}px`;
|
|
203
|
+ }
|
|
204
|
+
|
|
205
|
+ return parsedValue;
|
|
206
|
+}
|
|
207
|
+
|
|
208
|
+
|
193
|
209
|
/**
|
194
|
210
|
* The IFrame API interface class.
|
195
|
211
|
*/
|
|
@@ -201,8 +217,10 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
|
201
|
217
|
* conference.
|
202
|
218
|
* @param {Object} [options] - Optional arguments.
|
203
|
219
|
* @param {string} [options.roomName] - The name of the room to join.
|
204
|
|
- * @param {number} [options.width] - Width of the iframe.
|
205
|
|
- * @param {number} [options.height] - Height of the iframe.
|
|
220
|
+ * @param {number|string} [options.width] - Width of the iframe. Check
|
|
221
|
+ * parseSizeParam for format details.
|
|
222
|
+ * @param {number|string} [options.height] - Height of the iframe. Check
|
|
223
|
+ * parseSizeParam for format details.
|
206
|
224
|
* @param {DOMElement} [options.parentNode] - The node that will contain the
|
207
|
225
|
* iframe.
|
208
|
226
|
* @param {Object} [options.configOverwrite] - Object containing
|
|
@@ -218,8 +236,8 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
|
218
|
236
|
super();
|
219
|
237
|
const {
|
220
|
238
|
roomName = '',
|
221
|
|
- width = MIN_WIDTH,
|
222
|
|
- height = MIN_HEIGHT,
|
|
239
|
+ width = '100%',
|
|
240
|
+ height = '100%',
|
223
|
241
|
parentNode = document.body,
|
224
|
242
|
configOverwrite = {},
|
225
|
243
|
interfaceConfigOverwrite = {},
|
|
@@ -252,49 +270,49 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
|
252
|
270
|
/**
|
253
|
271
|
* Creates the iframe element.
|
254
|
272
|
*
|
255
|
|
- * @param {number} height - The height of the iframe.
|
256
|
|
- * @param {number} width - The with of the iframe.
|
|
273
|
+ * @param {number|string} height - The height of the iframe. Check
|
|
274
|
+ * parseSizeParam for format details.
|
|
275
|
+ * @param {number|string} width - The with of the iframe. Check
|
|
276
|
+ * parseSizeParam for format details.
|
257
|
277
|
* @returns {void}
|
258
|
278
|
*
|
259
|
279
|
* @private
|
260
|
280
|
*/
|
261
|
281
|
_createIFrame(height, width) {
|
262
|
|
- // Compute valid values for height and width. If a number is specified
|
263
|
|
- // it's treated as pixel units and our minimum constraints are applied.
|
264
|
|
- // If the value is expressed in em, pt or percentage, it's used as is.
|
265
|
|
- // Also protect ourselves from undefined, because
|
266
|
|
- // Math.max(undefined, 100) === NaN, obviously.
|
267
|
|
- //
|
268
|
|
- // This regex parses values of the form 100em, 100pt or 100%. Values
|
269
|
|
- // like 100 or 100px are handled outside of the regex, and invalid
|
270
|
|
- // values will be ignored and the minimum will be used.
|
271
|
|
- const re = /([0-9]*\.?[0-9]+)(em|pt|%)$/;
|
272
|
|
-
|
273
|
|
- /* eslint-disable no-param-reassign */
|
274
|
|
-
|
275
|
|
- if (String(height).match(re) === null) {
|
276
|
|
- height = parseInt(height, 10) || MIN_HEIGHT;
|
277
|
|
- height = `${Math.max(height, MIN_HEIGHT)}px`;
|
278
|
|
- }
|
279
|
|
-
|
280
|
|
- if (String(width).match(re) === null) {
|
281
|
|
- width = parseInt(width, 10) || MIN_WIDTH;
|
282
|
|
- width = `${Math.max(width, MIN_WIDTH)}px`;
|
283
|
|
- }
|
284
|
|
-
|
285
|
282
|
const frameName = `jitsiConferenceFrame${id}`;
|
286
|
283
|
|
287
|
284
|
this._frame = document.createElement('iframe');
|
288
|
285
|
this._frame.src = this._url;
|
289
|
286
|
this._frame.name = frameName;
|
290
|
287
|
this._frame.id = frameName;
|
291
|
|
- this._frame.style.width = width;
|
292
|
|
- this._frame.style.height = height;
|
|
288
|
+ this._setSize(height, width);
|
293
|
289
|
this._frame.setAttribute('allowFullScreen', 'true');
|
294
|
290
|
this._frame.style.border = 0;
|
295
|
291
|
this._frame = this._parentNode.appendChild(this._frame);
|
296
|
292
|
}
|
297
|
293
|
|
|
294
|
+ /**
|
|
295
|
+ * Sets the size of the iframe element.
|
|
296
|
+ *
|
|
297
|
+ * @param {number|string} height - The height of the iframe.
|
|
298
|
+ * @param {number|string} width - The with of the iframe.
|
|
299
|
+ * @returns {void}
|
|
300
|
+ *
|
|
301
|
+ * @private
|
|
302
|
+ */
|
|
303
|
+ _setSize(height, width) {
|
|
304
|
+ const parsedHeight = parseSizeParam(height);
|
|
305
|
+ const parsedWidth = parseSizeParam(width);
|
|
306
|
+
|
|
307
|
+ if (parsedHeight !== undefined) {
|
|
308
|
+ this._frame.style.height = parsedHeight;
|
|
309
|
+ }
|
|
310
|
+
|
|
311
|
+ if (parsedWidth !== undefined) {
|
|
312
|
+ this._frame.style.width = parsedWidth;
|
|
313
|
+ }
|
|
314
|
+ }
|
|
315
|
+
|
298
|
316
|
/**
|
299
|
317
|
* Setups listeners that are used internally for JitsiMeetExternalAPI.
|
300
|
318
|
*
|