Kaynağa Gözat

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.
master
Lyubomir Marinov 9 yıl önce
ebeveyn
işleme
2605abe2a3
3 değiştirilmiş dosya ile 31 ekleme ve 12 silme
  1. 1
    0
      JitsiConference.js
  2. 13
    4
      JitsiConnection.js
  3. 17
    8
      JitsiMeetJS.js

+ 1
- 0
JitsiConference.js Dosyayı Görüntüle

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

+ 13
- 4
JitsiConnection.js Dosyayı Görüntüle

4
 /**
4
 /**
5
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
5
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
6
  * JitsiConference interface.
6
  * JitsiConference interface.
7
+ * @param JitsiMeetJS the JitsiMeetJS instance which is initializing the new
8
+ * JitsiConnection instance
7
  * @param appID identification for the provider of Jitsi Meet video conferencing services.
9
  * @param appID identification for the provider of Jitsi Meet video conferencing services.
8
  * @param token the JWT token used to authenticate with the server(optional)
10
  * @param token the JWT token used to authenticate with the server(optional)
9
  * @param options Object with properties / settings related to connection with the server.
11
  * @param options Object with properties / settings related to connection with the server.
10
  * @constructor
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
     this.appID = appID;
21
     this.appID = appID;
14
     this.token = token;
22
     this.token = token;
15
     this.options = options;
23
     this.options = options;
70
  * @returns {JitsiConference} returns the new conference object.
78
  * @returns {JitsiConference} returns the new conference object.
71
  */
79
  */
72
 JitsiConnection.prototype.initJitsiConference = function (name, options) {
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 Dosyayı Görüntüle

37
 
37
 
38
     version: '{#COMMIT_HASH#}',
38
     version: '{#COMMIT_HASH#}',
39
 
39
 
40
-    JitsiConnection: JitsiConnection,
41
     events: {
40
     events: {
42
         conference: JitsiConferenceEvents,
41
         conference: JitsiConferenceEvents,
43
         connection: JitsiConnectionEvents,
42
         connection: JitsiConnectionEvents,
61
             var oldOnErrorHandler = window.onerror;
60
             var oldOnErrorHandler = window.onerror;
62
             window.onerror = function (message, source, lineno, colno, error) {
61
             window.onerror = function (message, source, lineno, colno, error) {
63
 
62
 
64
-                JitsiMeetJS.getGlobalOnErrorHandler(
63
+                this.getGlobalOnErrorHandler(
65
                     message, source, lineno, colno, error);
64
                     message, source, lineno, colno, error);
66
 
65
 
67
-                if(oldOnErrorHandler)
66
+                if (oldOnErrorHandler)
68
                     oldOnErrorHandler(message, source, lineno, colno, error);
67
                     oldOnErrorHandler(message, source, lineno, colno, error);
69
             }
68
             }
70
         }
69
         }
168
             'Line: ' + lineno,
167
             'Line: ' + lineno,
169
             'Column: ' + colno,
168
             'Column: ' + colno,
170
             'StackTrace: ', error);
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
             Statistics.sendUnhandledError(error);
176
             Statistics.sendUnhandledError(error);
177
         }
177
         }
178
     },
178
     },
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
 //Setups the promise object.
199
 //Setups the promise object.
191
 window.Promise = window.Promise || require("es6-promise").Promise;
200
 window.Promise = window.Promise || require("es6-promise").Promise;
192
 
201
 

Loading…
İptal
Kaydet