Browse Source

Merge pull request #1446 from jitsi/iframe_api_params

fix(iframe_api): Passing config params is not working
j8
Saúl Ibarra Corretgé 8 years ago
parent
commit
e8de8735e2
1 changed files with 29 additions and 16 deletions
  1. 29
    16
      modules/API/external/external_api.js

+ 29
- 16
modules/API/external/external_api.js View File

@@ -80,6 +80,27 @@ function changeParticipantNumber(APIInstance, number) {
80 80
     APIInstance.numberOfParticipants += number;
81 81
 }
82 82
 
83
+/**
84
+ * Generates array with URL params based on the passed config object that will
85
+ * be used for the Jitsi Meet URL generation.
86
+ *
87
+ * @param config {object} the config object.
88
+ * @returns {Array<string>} the array with URL param strings.
89
+ */
90
+function configToURLParamsArray(config) {
91
+    const params = [];
92
+
93
+    for (const key in config) {
94
+        try {
95
+            params.push(key + '='
96
+                + encodeURIComponent(JSON.stringify(config[key])));
97
+        } catch (e) {
98
+            console.warn(`Error encoding ${key}: ${e}`);
99
+        }
100
+    }
101
+    return params;
102
+}
103
+
83 104
 /**
84 105
  * Constructs new API instance. Creates iframe element that loads
85 106
  * Jitsi Meet.
@@ -130,24 +151,16 @@ function JitsiMeetExternalAPI(domain, room_name, width, height, parentNode,
130 151
 
131 152
     this.url += "#jitsi_meet_external_api_id=" + id;
132 153
 
133
-    var key;
134
-    if (configOverwrite) {
135
-        for (key in configOverwrite) {
136
-            if (!configOverwrite.hasOwnProperty(key) ||
137
-                typeof key !== 'string')
138
-                continue;
139
-            this.url += "&config." + key + "=" + configOverwrite[key];
140
-        }
154
+    const configURLParams = configToURLParamsArray(configOverwrite);
155
+    if (configURLParams.length) {
156
+        this.url += '&config.' + configURLParams.join('&config.');
141 157
     }
142 158
 
143
-    if (interfaceConfigOverwrite) {
144
-        for (key in interfaceConfigOverwrite) {
145
-            if (!interfaceConfigOverwrite.hasOwnProperty(key) ||
146
-                typeof key !== 'string')
147
-                continue;
148
-            this.url += "&interfaceConfig." + key + "=" +
149
-                interfaceConfigOverwrite[key];
150
-        }
159
+    const interfaceConfigURLParams
160
+        = configToURLParamsArray(interfaceConfigOverwrite);
161
+    if (interfaceConfigURLParams.length) {
162
+        this.url += '&interfaceConfig.'
163
+            + interfaceConfigURLParams.join('&interfaceConfig.');
151 164
     }
152 165
 
153 166
     this.frame = document.createElement("iframe");

Loading…
Cancel
Save