소스 검색

fix(iframe_api): Change the format of the arguments in the constructor

master
hristoterezov 8 년 전
부모
커밋
70122789e7
2개의 변경된 파일98개의 추가작업 그리고 43개의 파일을 삭제
  1. 27
    25
      doc/api.md
  2. 71
    18
      modules/API/external/external_api.js

+ 27
- 25
doc/api.md 파일 보기

9
 ```javascript
9
 ```javascript
10
 <script src="https://meet.jit.si/external_api.js"></script>
10
 <script src="https://meet.jit.si/external_api.js"></script>
11
 ```
11
 ```
12
-
13
 ## API
12
 ## API
14
 
13
 
15
-### `api = new JitsiMeetExternalAPI(domain, room, [width], [height], [htmlElement], [configOverwite], [interfaceConfigOverwrite], [noSsl], [jwt])`
14
+### `api = new JitsiMeetExternalAPI(domain, options)`
16
 
15
 
17
 The next step for embedding Jitsi Meet is to create the Jitsi Meet API object.
16
 The next step for embedding Jitsi Meet is to create the Jitsi Meet API object.
18
 Its constructor gets a number of options:
17
 Its constructor gets a number of options:
19
 
18
 
20
 * **domain**: domain used to build the conference URL, "meet.jit.si" for
19
 * **domain**: domain used to build the conference URL, "meet.jit.si" for
21
   example.
20
   example.
22
-* **room**: name of the room to join.
23
-* **width**: (optional) width for the iframe which will be created.
24
-* **height**: (optional) height for the iframe which will be created.
25
-* **htmlElement**: (optional) HTL DOM Element where the iframe will be added as
26
-  a child.
27
-* **configOverwite**: (optional) JS object with overrides for options defined in
28
-  [config.js].
29
-* **interfaceConfigOverwrite**: (optional) JS object with overrides for options
30
-  defined in [interface_config.js].
31
-* **noSsl**: (optional, defaults to true) Boolean indicating if the server
32
-  should be contacted using HTTP or HTTPS.
33
-* **jwt**: (optional) [JWT](https://jwt.io/) token.
21
+* **options**: object with properties - the optional arguments:
22
+    * **room**: (optional) name of the room to join.
23
+    * **width**: (optional) width for the iframe which will be created.
24
+    * **height**: (optional) height for the iframe which will be created.
25
+    * **htmlElement**: (optional) HTL DOM Element where the iframe will be added as a child.
26
+    * **configOverwite**: (optional) JS object with overrides for options defined in [config.js].
27
+    * **interfaceConfigOverwrite**: (optional) JS object with overrides for options defined in [interface_config.js].
28
+    * **noSsl**: (optional, defaults to true) Boolean indicating if the server should be contacted using HTTP or HTTPS.
29
+    * **jwt**: (optional) [JWT](https://jwt.io/) token.
34
 
30
 
35
 Example:
31
 Example:
36
 
32
 
37
 ```javascript
33
 ```javascript
38
-var domain = "meet.jit.si";
39
-var room = "JitsiMeetAPIExample";
40
-var width = 700;
41
-var height = 700;
42
-var htmlElement = document.querySelector('#meet');
43
-var api = new JitsiMeetExternalAPI(domain, room, width, height, htmlElement);
34
+var options = {
35
+    domain: "meet.jit.si",
36
+    room: "JitsiMeetAPIExample",
37
+    width: 700,
38
+    height: 700,
39
+    htmlElement: document.querySelector('#meet')
40
+}
41
+var api = new JitsiMeetExternalAPI(domain, options);
44
 ```
42
 ```
45
 
43
 
46
 You can overwrite options set in [config.js] and [interface_config.js].
44
 You can overwrite options set in [config.js] and [interface_config.js].
47
 For example, to enable the filmstrip-only interface mode, you can use:
45
 For example, to enable the filmstrip-only interface mode, you can use:
48
 
46
 
49
 ```javascript
47
 ```javascript
50
-var interfaceConfigOverwrite = {filmStripOnly: true};
51
-var api = new JitsiMeetExternalAPI(domain, room, width, height, undefined, undefined, interfaceConfigOverwrite);
48
+var options = {
49
+    interfaceConfigOverwrite: {filmStripOnly: true}
50
+};
51
+var api = new JitsiMeetExternalAPI(domain, options);
52
 ```
52
 ```
53
 
53
 
54
 You can also pass a jwt token to Jitsi Meet:
54
 You can also pass a jwt token to Jitsi Meet:
55
 
55
 
56
  ```javascript
56
  ```javascript
57
-var jwt = "<jwt_token>";
58
-var noSsl = false;
59
-var api = new JitsiMeetExternalAPI(domain, room, width, height, htmlElement, configOverwrite, interfaceConfigOverwrite, noSsl, jwt);
57
+var options = {
58
+    jwt: "<jwt_token>",
59
+    noSsl: false
60
+};
61
+var api = new JitsiMeetExternalAPI(domain, options);
60
  ```
62
  ```
61
 
63
 
62
 ### Controlling the embedded Jitsi Meet Conference
64
 ### Controlling the embedded Jitsi Meet Conference

+ 71
- 18
modules/API/external/external_api.js 파일 보기

142
     return url;
142
     return url;
143
 }
143
 }
144
 
144
 
145
+/**
146
+ * Parses the arguments passed to the constructor. If the old format is used
147
+ * the function translates the arguments to the new format.
148
+ *
149
+ * @param {Array} args - The arguments to be parsed.
150
+ * @returns {Object} JS object with properties.
151
+ */
152
+function parseArguments(args) {
153
+    if (!args.length) {
154
+        return {};
155
+    }
156
+
157
+    const firstArg = args[0];
158
+
159
+    switch (typeof firstArg) {
160
+    case 'string': // old arguments format
161
+    case undefined: // eslint-disable-line no-case-declarations
162
+    // not sure which format but we are trying to parse the old
163
+    // format because if the new format is used everything will be undefined
164
+    // anyway.
165
+        const [
166
+            roomName,
167
+            width,
168
+            height,
169
+            parentNode,
170
+            configOverwrite,
171
+            interfaceConfigOverwrite,
172
+            noSSL,
173
+            jwt
174
+        ] = args;
175
+
176
+        return {
177
+            roomName,
178
+            width,
179
+            height,
180
+            parentNode,
181
+            configOverwrite,
182
+            interfaceConfigOverwrite,
183
+            noSSL,
184
+            jwt
185
+        };
186
+    case 'object': // new arguments format
187
+        return args[0];
188
+    default:
189
+        throw new Error('Can\'t parse the arguments!');
190
+    }
191
+}
192
+
145
 /**
193
 /**
146
  * The IFrame API interface class.
194
  * The IFrame API interface class.
147
  */
195
  */
151
      *
199
      *
152
      * @param {string} domain - The domain name of the server that hosts the
200
      * @param {string} domain - The domain name of the server that hosts the
153
      * conference.
201
      * conference.
154
-     * @param {string} [roomName] - The name of the room to join.
155
-     * @param {number} [width] - Width of the iframe.
156
-     * @param {number} [height] - Height of the iframe.
157
-     * @param {DOMElement} [parentNode] - The node that will contain the
202
+     * @param {Object} [options] - Optional arguments.
203
+     * @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.
206
+     * @param {DOMElement} [options.parentNode] - The node that will contain the
158
      * iframe.
207
      * iframe.
159
-     * @param {Object} [configOverwrite] - Object containing configuration
160
-     * options defined in config.js to be overridden.
161
-     * @param {Object} [interfaceConfigOverwrite] - Object containing
208
+     * @param {Object} [options.configOverwrite] - Object containing
209
+     * configuration options defined in config.js to be overridden.
210
+     * @param {Object} [options.interfaceConfigOverwrite] - Object containing
162
      * configuration options defined in interface_config.js to be overridden.
211
      * configuration options defined in interface_config.js to be overridden.
163
-     * @param {boolean} [noSSL] - If the value is true https won't be used.
164
-     * @param {string} [jwt] - The JWT token if needed by jitsi-meet for
212
+     * @param {boolean} [options.noSSL] - If the value is true https won't be
213
+     * used.
214
+     * @param {string} [options.jwt] - The JWT token if needed by jitsi-meet for
165
      * authentication.
215
      * authentication.
166
      */
216
      */
167
-    constructor(domain, // eslint-disable-line max-params
168
-        roomName = '',
169
-        width = MIN_WIDTH,
170
-        height = MIN_HEIGHT,
171
-        parentNode = document.body,
172
-        configOverwrite = {},
173
-        interfaceConfigOverwrite = {},
174
-        noSSL = false,
175
-        jwt = undefined) {
217
+    constructor(domain, ...args) {
176
         super();
218
         super();
219
+        const {
220
+            roomName = '',
221
+            width = MIN_WIDTH,
222
+            height = MIN_HEIGHT,
223
+            parentNode = document.body,
224
+            configOverwrite = {},
225
+            interfaceConfigOverwrite = {},
226
+            noSSL = false,
227
+            jwt = undefined
228
+        } = parseArguments(args);
229
+
177
         this._parentNode = parentNode;
230
         this._parentNode = parentNode;
178
         this._url = generateURL(domain, {
231
         this._url = generateURL(domain, {
179
             configOverwrite,
232
             configOverwrite,

Loading…
취소
저장