Browse Source

feat: use LogCollector to capture JS console logs

master
paweldomas 8 years ago
parent
commit
36bcc6831b
2 changed files with 74 additions and 1 deletions
  1. 65
    1
      app.js
  2. 9
    0
      conference.js

+ 65
- 1
app.js View File

20
 window.toastr = require("toastr");
20
 window.toastr = require("toastr");
21
 
21
 
22
 const Logger = require("jitsi-meet-logger");
22
 const Logger = require("jitsi-meet-logger");
23
+const LogCollector = Logger.LogCollector;
23
 
24
 
24
 import URLProcessor from "./modules/config/URLProcessor";
25
 import URLProcessor from "./modules/config/URLProcessor";
25
 import RoomnameGenerator from './modules/util/RoomnameGenerator';
26
 import RoomnameGenerator from './modules/util/RoomnameGenerator';
34
 import getTokenData from "./modules/tokendata/TokenData";
35
 import getTokenData from "./modules/tokendata/TokenData";
35
 import translation from "./modules/translation/translation";
36
 import translation from "./modules/translation/translation";
36
 
37
 
38
+const ConferenceEvents = JitsiMeetJS.events.conference;
37
 
39
 
38
 /**
40
 /**
39
  * Tries to push history state with the following parameters:
41
  * Tries to push history state with the following parameters:
131
     settings,
133
     settings,
132
     conference,
134
     conference,
133
     translation,
135
     translation,
136
+    /**
137
+     * The log collector which captures JS console logs for this app.
138
+     * @type {LogCollector}
139
+     */
140
+    logCollector: null,
141
+    /**
142
+     * Indicates if the log collector has been started (it will not be started
143
+     * if the welcome page is displayed).
144
+     */
145
+    logCollectorStarted : false,
134
     /**
146
     /**
135
      * After the APP has been initialized provides utility methods for dealing
147
      * After the APP has been initialized provides utility methods for dealing
136
      * with the conference room URL(address).
148
      * with the conference room URL(address).
140
     connection: null,
152
     connection: null,
141
     API,
153
     API,
142
     init () {
154
     init () {
143
-        configureLoggingLevels();
155
+        this.initLogging();
144
         this.keyboardshortcut =
156
         this.keyboardshortcut =
145
             require("./modules/keyboardshortcut/keyboardshortcut");
157
             require("./modules/keyboardshortcut/keyboardshortcut");
146
         this.configFetch = require("./modules/config/HttpConfigFetch");
158
         this.configFetch = require("./modules/config/HttpConfigFetch");
147
         this.tokenData = getTokenData();
159
         this.tokenData = getTokenData();
160
+    },
161
+    initLogging () {
162
+        // Adjust logging level
163
+        configureLoggingLevels();
164
+        // Start the LogCollector and register it as the global log transport
165
+        if (!this.logCollector) {
166
+            this.logCollector = new LogCollector({
167
+                storeLogs: (logJSON) => {
168
+                    // Try catch was used, because there are many variables
169
+                    // on the way that could be uninitialized if the storeLogs
170
+                    // attempt would be made very early (which is unlikely)
171
+                    try {
172
+                        // Currently it makes sense to store the log only
173
+                        // if CallStats is enabled
174
+                        if (APP.logCollectorStarted
175
+                                && APP.conference
176
+                                && APP.conference.isCallstatsEnabled()) {
177
+                            APP.conference.logJSON(logJSON);
178
+                        }
179
+                    } catch (error) {
180
+                        // NOTE console is intentional here
181
+                        console.error(
182
+                            "Failed to store the logs: ", logJSON, error);
183
+                    }
184
+                }
185
+            });
186
+            Logger.addGlobalTransport(this.logCollector);
187
+            JitsiMeetJS.addGlobalLogTransport(this.logCollector);
188
+        }
148
     }
189
     }
149
 };
190
 };
150
 
191
 
168
     replaceHistoryState(APP.ConferenceUrl.getInviteUrl());
209
     replaceHistoryState(APP.ConferenceUrl.getInviteUrl());
169
     var isUIReady = APP.UI.start();
210
     var isUIReady = APP.UI.start();
170
     if (isUIReady) {
211
     if (isUIReady) {
212
+        // Start the LogCollector's periodic "store logs" task only if we're in
213
+        // the conference and not on the welcome page.
214
+        APP.logCollector.start();
215
+        APP.logCollectorStarted = true;
216
+
171
         APP.conference.init({roomName: buildRoomName()}).then(function () {
217
         APP.conference.init({roomName: buildRoomName()}).then(function () {
218
+
219
+            // Will flush the logs, before the stats are disposed
220
+            if (APP.logCollector) {
221
+                APP.conference.addConferenceListener(
222
+                    ConferenceEvents.BEFORE_STATISTICS_DISPOSED,
223
+                    () => {
224
+                        if (APP.logCollector) {
225
+                            APP.logCollector.flush();
226
+                        }
227
+                    }
228
+                );
229
+            }
230
+
172
             APP.UI.initConference();
231
             APP.UI.initConference();
173
 
232
 
174
             APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
233
             APP.UI.addListener(UIEvents.LANG_CHANGED, function (language) {
237
 });
296
 });
238
 
297
 
239
 $(window).bind('beforeunload', function () {
298
 $(window).bind('beforeunload', function () {
299
+    // Stop the LogCollector
300
+    if (APP.logCollectorStarted) {
301
+        APP.logCollector.stop();
302
+        APP.logCollectorStarted = false;
303
+    }
240
     APP.API.dispose();
304
     APP.API.dispose();
241
 });
305
 });
242
 
306
 

+ 9
- 0
conference.js View File

1743
             room.sendApplicationLog(JSON.stringify({name, value}));
1743
             room.sendApplicationLog(JSON.stringify({name, value}));
1744
         }
1744
         }
1745
     },
1745
     },
1746
+    /**
1747
+     * Methods logs an application event given in the JSON format.
1748
+     * @param {string} logJSON an event to be logged in JSON format
1749
+     */
1750
+    logJSON(logJSON) {
1751
+        if (room) {
1752
+            room.sendApplicationLog(logJSON);
1753
+        }
1754
+    },
1746
     /**
1755
     /**
1747
      * Disconnect from the conference and optionally request user feedback.
1756
      * Disconnect from the conference and optionally request user feedback.
1748
      * @param {boolean} [requestFeedback=false] if user feedback should be
1757
      * @param {boolean} [requestFeedback=false] if user feedback should be

Loading…
Cancel
Save