From 8d162609e05311bdf0e25c3f46f4ce5cf1c8c581 Mon Sep 17 00:00:00 2001 From: hristoterezov Date: Mon, 25 Jul 2016 17:04:39 -0500 Subject: [PATCH 1/2] Handles the errors thrown by the data channel methods --- conference.js | 43 +++++++++++++++++++++++++++-------------- modules/util/helpers.js | 12 ++++++++++++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/conference.js b/conference.js index 0b21d378f..7ba63a69f 100644 --- a/conference.js +++ b/conference.js @@ -14,6 +14,8 @@ import UIEvents from './service/UI/UIEvents'; import mediaDeviceHelper from './modules/devices/mediaDeviceHelper'; +import {reportError} from './modules/util/helpers'; + const ConnectionEvents = JitsiMeetJS.events.connection; const ConnectionErrors = JitsiMeetJS.errors.connection; @@ -1153,9 +1155,13 @@ export default { ConnectionQuality.addListener(CQEvents.LOCALSTATS_UPDATED, (percent, stats) => { APP.UI.updateLocalStats(percent, stats); - room.broadcastEndpointMessage({ - type: this.commands.defaults.CONNECTION_QUALITY, - values: stats }); + try { + room.broadcastEndpointMessage({ + type: this.commands.defaults.CONNECTION_QUALITY, + values: stats }); + } catch (e) { + reportError(e); + } }); room.on(ConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, @@ -1279,22 +1285,29 @@ export default { }); APP.UI.addListener(UIEvents.SELECTED_ENDPOINT, (id) => { - room.selectParticipant(id); + try { + room.selectParticipant(id); + } catch (e) { + reportError(e); + } }); APP.UI.addListener(UIEvents.PINNED_ENDPOINT, (smallVideo, isPinned) => { var smallVideoId = smallVideo.getId(); - - if (smallVideo.getVideoType() === VIDEO_CONTAINER_TYPE - && !APP.conference.isLocalId(smallVideoId)) - if (isPinned) - room.pinParticipant(smallVideoId); - // When the library starts supporting multiple pins we would - // pass the isPinned parameter together with the identifier, - // but currently we send null to indicate that we unpin the - // last pinned. - else - room.pinParticipant(null); + try { + if (smallVideo.getVideoType() === VIDEO_CONTAINER_TYPE + && !APP.conference.isLocalId(smallVideoId)) + if (isPinned) + room.pinParticipant(smallVideoId); + // When the library starts supporting multiple pins we would + // pass the isPinned parameter together with the identifier, + // but currently we send null to indicate that we unpin the + // last pinned. + else + room.pinParticipant(null); + } catch (e) { + reportError(e); + } }); APP.UI.addListener( diff --git a/modules/util/helpers.js b/modules/util/helpers.js index 120ba7720..9d74d1ccc 100644 --- a/modules/util/helpers.js +++ b/modules/util/helpers.js @@ -19,3 +19,15 @@ export function createDeferred () { export function reload () { window.location.reload(); } + +/** + * Prints the error and reports it to the global error handler. + * @param e {Error} the error + * @param msg {string} [optional] the message printed in addition to the error + */ +export function reportError (e, msg = "") { + console.error(msg, e); + if(window.onerror) + window.onerror(msg, null, null, + null, e); +} From adefa40dcc0231b7977640f178a1b7d18921afbf Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Tue, 26 Jul 2016 08:32:25 -0500 Subject: [PATCH 2/2] Simplifies code, reduces the scope of "try". --- conference.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/conference.js b/conference.js index 7ba63a69f..1c041592c 100644 --- a/conference.js +++ b/conference.js @@ -1294,19 +1294,18 @@ export default { APP.UI.addListener(UIEvents.PINNED_ENDPOINT, (smallVideo, isPinned) => { var smallVideoId = smallVideo.getId(); - try { - if (smallVideo.getVideoType() === VIDEO_CONTAINER_TYPE - && !APP.conference.isLocalId(smallVideoId)) - if (isPinned) - room.pinParticipant(smallVideoId); - // When the library starts supporting multiple pins we would - // pass the isPinned parameter together with the identifier, - // but currently we send null to indicate that we unpin the - // last pinned. - else - room.pinParticipant(null); - } catch (e) { - reportError(e); + if (smallVideo.getVideoType() === VIDEO_CONTAINER_TYPE + && !APP.conference.isLocalId(smallVideoId)) { + + // When the library starts supporting multiple pins we would + // pass the isPinned parameter together with the identifier, + // but currently we send null to indicate that we unpin the + // last pinned. + try { + room.pinParticipant(isPinned ? smallVideoId : null); + } catch (e) { + reportError(e); + } } });