Pārlūkot izejas kodu

Don't rely on JitsiMeetJS being global

While we have JitsiMeetJS defined as a global variable in Jitsi Meet, it
doesn't sound like an absolutely necessary and beautiful requirement
inside the library itself.
dev1
Lyubomir Marinov 9 gadus atpakaļ
vecāks
revīzija
2605abe2a3
3 mainītis faili ar 31 papildinājumiem un 12 dzēšanām
  1. 1
    0
      JitsiConference.js
  2. 13
    4
      JitsiConnection.js
  3. 17
    8
      JitsiMeetJS.js

+ 1
- 0
JitsiConference.js Parādīt failu

@@ -48,6 +48,7 @@ function JitsiConference(options) {
48 48
         disableThirdPartyRequests: this.options.config.disableThirdPartyRequests
49 49
     });
50 50
     setupListeners(this);
51
+    var JitsiMeetJS = this.connection.JitsiMeetJS;
51 52
     JitsiMeetJS._gumFailedHandler.push(function(error) {
52 53
         this.statistics.sendGetUserMediaFailed(error);
53 54
     }.bind(this));

+ 13
- 4
JitsiConnection.js Parādīt failu

@@ -4,12 +4,20 @@ var XMPP = require("./modules/xmpp/xmpp");
4 4
 /**
5 5
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
6 6
  * JitsiConference interface.
7
+ * @param JitsiMeetJS the JitsiMeetJS instance which is initializing the new
8
+ * JitsiConnection instance
7 9
  * @param appID identification for the provider of Jitsi Meet video conferencing services.
8 10
  * @param token the JWT token used to authenticate with the server(optional)
9 11
  * @param options Object with properties / settings related to connection with the server.
10 12
  * @constructor
11 13
  */
12
-function JitsiConnection(appID, token, options) {
14
+function JitsiConnection(JitsiMeetJS, appID, token, options) {
15
+    /**
16
+     * The {JitsiMeetJS} instance which has initialized this {JitsiConnection}
17
+     * instance.
18
+     * @public
19
+     */
20
+    this.JitsiMeetJS = JitsiMeetJS;
13 21
     this.appID = appID;
14 22
     this.token = token;
15 23
     this.options = options;
@@ -70,9 +78,10 @@ JitsiConnection.prototype.setToken = function (token) {
70 78
  * @returns {JitsiConference} returns the new conference object.
71 79
  */
72 80
 JitsiConnection.prototype.initJitsiConference = function (name, options) {
73
-    this.conferences[name] = new JitsiConference({name: name, config: options,
74
-        connection: this});
75
-    return this.conferences[name];
81
+    var conference
82
+        = new JitsiConference({name: name, config: options, connection: this});
83
+    this.conferences[name] = conference;
84
+    return conference;
76 85
 }
77 86
 
78 87
 /**

+ 17
- 8
JitsiMeetJS.js Parādīt failu

@@ -37,7 +37,6 @@ var LibJitsiMeet = {
37 37
 
38 38
     version: '{#COMMIT_HASH#}',
39 39
 
40
-    JitsiConnection: JitsiConnection,
41 40
     events: {
42 41
         conference: JitsiConferenceEvents,
43 42
         connection: JitsiConnectionEvents,
@@ -61,10 +60,10 @@ var LibJitsiMeet = {
61 60
             var oldOnErrorHandler = window.onerror;
62 61
             window.onerror = function (message, source, lineno, colno, error) {
63 62
 
64
-                JitsiMeetJS.getGlobalOnErrorHandler(
63
+                this.getGlobalOnErrorHandler(
65 64
                     message, source, lineno, colno, error);
66 65
 
67
-                if(oldOnErrorHandler)
66
+                if (oldOnErrorHandler)
68 67
                     oldOnErrorHandler(message, source, lineno, colno, error);
69 68
             }
70 69
         }
@@ -168,11 +167,12 @@ var LibJitsiMeet = {
168 167
             'Line: ' + lineno,
169 168
             'Column: ' + colno,
170 169
             'StackTrace: ', error);
171
-
172
-        JitsiMeetJS._globalOnErrorHandler.forEach(function (handler) {
173
-            handler(error);
174
-        });
175
-        if(!JitsiMeetJS._globalOnErrorHandler.length){
170
+        var globalOnErrorHandler = this._globalOnErrorHandler;
171
+        if (globalOnErrorHandler.length) {
172
+          globalOnErrorHandler.forEach(function (handler) {
173
+              handler(error);
174
+          });
175
+        } else {
176 176
             Statistics.sendUnhandledError(error);
177 177
         }
178 178
     },
@@ -187,6 +187,15 @@ var LibJitsiMeet = {
187 187
     }
188 188
 };
189 189
 
190
+// XXX JitsiConnection or the instances it initializes and is associated with
191
+// (e.g. JitsiConference) may need a reference to LibJitsiMeet (aka
192
+// JitsiMeetJS). An approach could be to declare LibJitsiMeet global (which is
193
+// what we do in Jitsi Meet) but that could be seen as not such a cool decision
194
+// certainly looks even worse within the lib-jitsi-meet library itself. That's
195
+// why the decision is to provide LibJitsiMeet as a parameter of
196
+// JitsiConnection.
197
+LibJitsiMeet.JitsiConnection = JitsiConnection.bind(null, LibJitsiMeet);
198
+
190 199
 //Setups the promise object.
191 200
 window.Promise = window.Promise || require("es6-promise").Promise;
192 201
 

Notiek ielāde…
Atcelt
Saglabāt