瀏覽代碼

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,54 +9,56 @@ To embed Jitsi Meet in your application you need to add the Jitsi Meet API libra
9 9
 ```javascript
10 10
 <script src="https://meet.jit.si/external_api.js"></script>
11 11
 ```
12
-
13 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 16
 The next step for embedding Jitsi Meet is to create the Jitsi Meet API object.
18 17
 Its constructor gets a number of options:
19 18
 
20 19
 * **domain**: domain used to build the conference URL, "meet.jit.si" for
21 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 31
 Example:
36 32
 
37 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 44
 You can overwrite options set in [config.js] and [interface_config.js].
47 45
 For example, to enable the filmstrip-only interface mode, you can use:
48 46
 
49 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 54
 You can also pass a jwt token to Jitsi Meet:
55 55
 
56 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 64
 ### Controlling the embedded Jitsi Meet Conference

+ 71
- 18
modules/API/external/external_api.js 查看文件

@@ -142,6 +142,54 @@ function generateURL(domain, options = {}) {
142 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 194
  * The IFrame API interface class.
147 195
  */
@@ -151,29 +199,34 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
151 199
      *
152 200
      * @param {string} domain - The domain name of the server that hosts the
153 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 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 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 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 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 230
         this._parentNode = parentNode;
178 231
         this._url = generateURL(domain, {
179 232
             configOverwrite,

Loading…
取消
儲存