From a8c989645fc3e586303df1b8791feedda52f5b86 Mon Sep 17 00:00:00 2001
From: Joao Siebel <joaos_desenv@imdt.com.br>
Date: Wed, 5 May 2021 14:52:50 -0300
Subject: [PATCH] Add try/catch on video-streams methods

---
 .../server/methods/userShareWebcam.js         | 39 ++++++++++---------
 .../server/methods/userUnshareWebcam.js       | 38 ++++++++++--------
 2 files changed, 42 insertions(+), 35 deletions(-)

diff --git a/bigbluebutton-html5/imports/api/video-streams/server/methods/userShareWebcam.js b/bigbluebutton-html5/imports/api/video-streams/server/methods/userShareWebcam.js
index 8d21a6182a..82098a5ea7 100644
--- a/bigbluebutton-html5/imports/api/video-streams/server/methods/userShareWebcam.js
+++ b/bigbluebutton-html5/imports/api/video-streams/server/methods/userShareWebcam.js
@@ -5,27 +5,30 @@ import RedisPubSub from '/imports/startup/server/redis';
 import { extractCredentials } from '/imports/api/common/server/helpers';
 
 export default function userShareWebcam(stream) {
-  const REDIS_CONFIG = Meteor.settings.private.redis;
-  const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
-  const EVENT_NAME = 'UserBroadcastCamStartMsg';
-  const { meetingId, requesterUserId } = extractCredentials(this.userId);
+  try {
+    const REDIS_CONFIG = Meteor.settings.private.redis;
+    const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
+    const EVENT_NAME = 'UserBroadcastCamStartMsg';
+    const { meetingId, requesterUserId } = extractCredentials(this.userId);
 
-  check(meetingId, String);
-  check(requesterUserId, String);
-  check(stream, String);
+    check(meetingId, String);
+    check(requesterUserId, String);
+    check(stream, String);
 
-  Logger.info(`user sharing webcam: ${meetingId} ${requesterUserId}`);
+    Logger.info(`user sharing webcam: ${meetingId} ${requesterUserId}`);
 
+    // const actionName = 'joinVideo';
+    /* TODO throw an error if user has no permission to share webcam
+    if (!isAllowedTo(actionName, credentials)) {
+      throw new Meteor.Error('not-allowed', `You are not allowed to share webcam`);
+    } */
 
-  // const actionName = 'joinVideo';
-  /* TODO throw an error if user has no permission to share webcam
-  if (!isAllowedTo(actionName, credentials)) {
-    throw new Meteor.Error('not-allowed', `You are not allowed to share webcam`);
-  } */
+    const payload = {
+      stream,
+    };
 
-  const payload = {
-    stream,
-  };
-
-  return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
+    RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
+  } catch (err) {
+    Logger.error(`Exception while invoking method userShareWebcam ${err.stack}`);
+  }
 }
diff --git a/bigbluebutton-html5/imports/api/video-streams/server/methods/userUnshareWebcam.js b/bigbluebutton-html5/imports/api/video-streams/server/methods/userUnshareWebcam.js
index dd2400bee5..afae00c436 100644
--- a/bigbluebutton-html5/imports/api/video-streams/server/methods/userUnshareWebcam.js
+++ b/bigbluebutton-html5/imports/api/video-streams/server/methods/userUnshareWebcam.js
@@ -5,26 +5,30 @@ import RedisPubSub from '/imports/startup/server/redis';
 import { extractCredentials } from '/imports/api/common/server/helpers';
 
 export default function userUnshareWebcam(stream) {
-  const REDIS_CONFIG = Meteor.settings.private.redis;
-  const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
-  const EVENT_NAME = 'UserBroadcastCamStopMsg';
-  const { meetingId, requesterUserId } = extractCredentials(this.userId);
+  try {
+    const REDIS_CONFIG = Meteor.settings.private.redis;
+    const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
+    const EVENT_NAME = 'UserBroadcastCamStopMsg';
+    const { meetingId, requesterUserId } = extractCredentials(this.userId);
 
-  check(meetingId, String);
-  check(requesterUserId, String);
-  check(stream, String);
+    check(meetingId, String);
+    check(requesterUserId, String);
+    check(stream, String);
 
-  Logger.info(`user unsharing webcam: ${meetingId} ${requesterUserId}`);
+    Logger.info(`user unsharing webcam: ${meetingId} ${requesterUserId}`);
 
-  // const actionName = 'joinVideo';
-  /* TODO throw an error if user has no permission to share webcam
-  if (!isAllowedTo(actionName, credentials)) {
-    throw new Meteor.Error('not-allowed', `You are not allowed to share webcam`);
-  } */
+    // const actionName = 'joinVideo';
+    /* TODO throw an error if user has no permission to share webcam
+    if (!isAllowedTo(actionName, credentials)) {
+      throw new Meteor.Error('not-allowed', `You are not allowed to share webcam`);
+    } */
 
-  const payload = {
-    stream,
-  };
+    const payload = {
+      stream,
+    };
 
-  return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
+    RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
+  } catch (err) {
+    Logger.error(`Exception while invoking method userUnshareWebcam ${err.stack}`);
+  }
 }
-- 
GitLab