From 248dc7fa0850caf03ecb8ae4460214e35f9660ad Mon Sep 17 00:00:00 2001
From: prlanzarin <prlanzarin@inf.ufrgs.br>
Date: Fri, 17 Nov 2017 18:55:59 +0000
Subject: [PATCH] Fixed HTML5 video API import

Added chrome extension ID to HTML5 screenshare call
---
 .../resources/prod/BigBlueButton.html         |  2 +-
 .../resources/prod/lib/kurento-extension.js   |  4 +-
 .../api/screenshare/client/bridge/kurento.js  |  4 +-
 .../imports/api/video/server/eventHandlers.js |  2 +-
 .../server/handlers/userSharedHtml5Webcam.js  |  1 +
 .../handlers/userUnsharedHtml5Webcam.js       |  1 +
 .../video/server/methods/userShareWebcam.js   | 10 +---
 .../video/server/methods/userUnshareWebcam.js | 10 +---
 .../video/server/modifiers/sharedWebcam.js    |  1 +
 .../video/server/modifiers/unsharedWebcam.js  |  1 +
 .../ui/components/video-dock/component.jsx    | 49 ++++++++++---------
 .../public/js/adjust-videos.js                |  2 -
 bigbluebutton-html5/server/main.js            |  1 +
 13 files changed, 41 insertions(+), 47 deletions(-)

diff --git a/bigbluebutton-client/resources/prod/BigBlueButton.html b/bigbluebutton-client/resources/prod/BigBlueButton.html
index a799be30e6..bc3f9c4901 100755
--- a/bigbluebutton-client/resources/prod/BigBlueButton.html
+++ b/bigbluebutton-client/resources/prod/BigBlueButton.html
@@ -143,7 +143,7 @@
     <script src="lib/verto_extension.js" language="javascript"></script>
 
     <script src="lib/kurento-extension.js" language="javascript"></script>
-    <script src="lib/kurento-utils.js" language="javascript"></script>
+    <script src="lib/kurento-utils.min.js" language="javascript"></script>
 
     <script src="lib/bbb_api_bridge.js?v=VERSION" language="javascript"></script>
     <script src="lib/sip.js?v=VERSION" language="javascript"></script>
diff --git a/bigbluebutton-client/resources/prod/lib/kurento-extension.js b/bigbluebutton-client/resources/prod/lib/kurento-extension.js
index 386e85339e..b697044636 100644
--- a/bigbluebutton-client/resources/prod/lib/kurento-extension.js
+++ b/bigbluebutton-client/resources/prod/lib/kurento-extension.js
@@ -189,8 +189,8 @@ Kurento.prototype.setRenderTag = function (tag) {
 
 Kurento.prototype.presenterResponse = function (message) {
   if (message.response != 'accepted') {
-    var errorMsg = message.message ? message.message : 'Unknow error';
-    console.warn('Call not accepted for the following reason: ' + errorMsg);
+    var errorMsg = message.message ? message.message : 'Unknown error';
+    console.warn('Call not accepted for the following reason: ' + JSON.stringify(errorMsg, null, 2));
     kurentoManager.exitScreenShare();
     this.onFail(errorMessage);
   } else {
diff --git a/bigbluebutton-html5/imports/api/screenshare/client/bridge/kurento.js b/bigbluebutton-html5/imports/api/screenshare/client/bridge/kurento.js
index 00f12f5b18..77e10ef49f 100755
--- a/bigbluebutton-html5/imports/api/screenshare/client/bridge/kurento.js
+++ b/bigbluebutton-html5/imports/api/screenshare/client/bridge/kurento.js
@@ -2,6 +2,8 @@ import Users from '/imports/api/users';
 import Auth from '/imports/ui/services/auth';
 import BridgeService from './service';
 
+const CHROME_EXTENSION_KEY = Meteor.settings.public.kurento.chromeExtensionKey;
+
 const getUserId = () => {
   const userID = Auth.userID;
   return userID;
@@ -39,7 +41,7 @@ export default class KurentoScreenshareBridge {
       getUsername(),
       getMeetingId(),
       null,
-      null,
+      CHROME_EXTENSION_KEY,
     );
   }
 
diff --git a/bigbluebutton-html5/imports/api/video/server/eventHandlers.js b/bigbluebutton-html5/imports/api/video/server/eventHandlers.js
index e20b6cd39a..0e773b08ea 100644
--- a/bigbluebutton-html5/imports/api/video/server/eventHandlers.js
+++ b/bigbluebutton-html5/imports/api/video/server/eventHandlers.js
@@ -1,4 +1,4 @@
-import RedisPubSub from '/imports/startup/server/redis2x';
+import RedisPubSub from '/imports/startup/server/redis';
 import handleUserSharedHtml5Webcam from './handlers/userSharedHtml5Webcam';
 import handleUserUnsharedHtml5Webcam from './handlers/userUnsharedHtml5Webcam';
 
diff --git a/bigbluebutton-html5/imports/api/video/server/handlers/userSharedHtml5Webcam.js b/bigbluebutton-html5/imports/api/video/server/handlers/userSharedHtml5Webcam.js
index b0c21ee31c..e0101f9991 100644
--- a/bigbluebutton-html5/imports/api/video/server/handlers/userSharedHtml5Webcam.js
+++ b/bigbluebutton-html5/imports/api/video/server/handlers/userSharedHtml5Webcam.js
@@ -1,4 +1,5 @@
 import sharedWebcam from '../modifiers/sharedWebcam';
+import {check} from 'meteor/check';
 
 export default function handleUserSharedHtml5Webcam({ header, payload }) {
   const meetingId = header.meetingId;
diff --git a/bigbluebutton-html5/imports/api/video/server/handlers/userUnsharedHtml5Webcam.js b/bigbluebutton-html5/imports/api/video/server/handlers/userUnsharedHtml5Webcam.js
index bf0f0994f9..d982c8daab 100644
--- a/bigbluebutton-html5/imports/api/video/server/handlers/userUnsharedHtml5Webcam.js
+++ b/bigbluebutton-html5/imports/api/video/server/handlers/userUnsharedHtml5Webcam.js
@@ -1,4 +1,5 @@
 import unsharedWebcam from '../modifiers/unsharedWebcam';
+import { check } from 'meteor/check';
 
 export default function handleUserUnsharedHtml5Webcam({ header, payload }) {
   const meetingId = header.meetingId;
diff --git a/bigbluebutton-html5/imports/api/video/server/methods/userShareWebcam.js b/bigbluebutton-html5/imports/api/video/server/methods/userShareWebcam.js
index 6121725948..9dbcabf1dd 100644
--- a/bigbluebutton-html5/imports/api/video/server/methods/userShareWebcam.js
+++ b/bigbluebutton-html5/imports/api/video/server/methods/userShareWebcam.js
@@ -1,7 +1,7 @@
 import { Meteor } from 'meteor/meteor';
 import { check } from 'meteor/check';
 import Logger from '/imports/startup/server/logger';
-import RedisPubSub from '/imports/startup/server/redis2x';
+import RedisPubSub from '/imports/startup/server/redis';
 
 export default function userShareWebcam(credentials, message) {
   const REDIS_CONFIG = Meteor.settings.redis;
@@ -28,11 +28,5 @@ export default function userShareWebcam(credentials, message) {
     isHtml5Client: true,
   };
 
-  const header = {
-    meetingId,
-    name: EVENT_NAME,
-    userId: requesterUserId,
-  };
-
-  return RedisPubSub.publish(CHANNEL, EVENT_NAME, meetingId, payload, header);
+  return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
 }
diff --git a/bigbluebutton-html5/imports/api/video/server/methods/userUnshareWebcam.js b/bigbluebutton-html5/imports/api/video/server/methods/userUnshareWebcam.js
index 62b83be491..ebec447808 100644
--- a/bigbluebutton-html5/imports/api/video/server/methods/userUnshareWebcam.js
+++ b/bigbluebutton-html5/imports/api/video/server/methods/userUnshareWebcam.js
@@ -1,7 +1,7 @@
 import { Meteor } from 'meteor/meteor';
 import { check } from 'meteor/check';
 import Logger from '/imports/startup/server/logger';
-import RedisPubSub from '/imports/startup/server/redis2x';
+import RedisPubSub from '/imports/startup/server/redis';
 
 export default function userUnshareWebcam(credentials, message) {
   const REDIS_CONFIG = Meteor.settings.redis;
@@ -28,11 +28,5 @@ export default function userUnshareWebcam(credentials, message) {
     isHtml5Client: true,
   };
 
-  const header = {
-    meetingId,
-    name: EVENT_NAME,
-    userId: requesterUserId,
-  };
-
-  return RedisPubSub.publish(CHANNEL, EVENT_NAME, meetingId, payload, header);
+  return RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
 }
diff --git a/bigbluebutton-html5/imports/api/video/server/modifiers/sharedWebcam.js b/bigbluebutton-html5/imports/api/video/server/modifiers/sharedWebcam.js
index 0a8f96321b..749407ffc4 100644
--- a/bigbluebutton-html5/imports/api/video/server/modifiers/sharedWebcam.js
+++ b/bigbluebutton-html5/imports/api/video/server/modifiers/sharedWebcam.js
@@ -1,5 +1,6 @@
 import Logger from '/imports/startup/server/logger';
 import Users from '/imports/api/users';
+import { check }  from 'meteor/check';
 
 export default function sharedWebcam(meetingId, userId) {
   check(meetingId, String);
diff --git a/bigbluebutton-html5/imports/api/video/server/modifiers/unsharedWebcam.js b/bigbluebutton-html5/imports/api/video/server/modifiers/unsharedWebcam.js
index 817031199b..0ef8f0be36 100644
--- a/bigbluebutton-html5/imports/api/video/server/modifiers/unsharedWebcam.js
+++ b/bigbluebutton-html5/imports/api/video/server/modifiers/unsharedWebcam.js
@@ -1,5 +1,6 @@
 import Logger from '/imports/startup/server/logger';
 import Users from '/imports/api/users';
+import { check } from 'meteor/check';
 
 export default function unsharedWebcam(meetingId, userId) {
   check(meetingId, String);
diff --git a/bigbluebutton-html5/imports/ui/components/video-dock/component.jsx b/bigbluebutton-html5/imports/ui/components/video-dock/component.jsx
index 90a1bd17d8..47232fb938 100644
--- a/bigbluebutton-html5/imports/ui/components/video-dock/component.jsx
+++ b/bigbluebutton-html5/imports/ui/components/video-dock/component.jsx
@@ -1,6 +1,8 @@
 import React, { Component } from 'react';
 import ScreenshareContainer from '/imports/ui/components/screenshare/container';
 import styles from './styles';
+import { log } from '/imports/ui/services/api';
+
 
 window.addEventListener('resize', () => {
   window.adjustVideos('webcamArea', true);
@@ -48,7 +50,6 @@ export default class VideoDock extends Component {
     const { users } = this.props;
     for (let i = 0; i < users.length; i++) {
       if (users[i].has_stream) {
-        console.log("COMPONENT DID MOUNT => " + users[i].userId);
         this.start(users[i].userId, false, this.refs.videoInput);
       }
     }
@@ -59,8 +60,8 @@ export default class VideoDock extends Component {
     ws.addEventListener('message', (msg) => {
       const parsedMessage = JSON.parse(msg.data);
 
-      console.debug('Received message new ws message: ');
-      console.debug(parsedMessage);
+      log('debug', 'Received message new ws message: ');
+      log('debug', parsedMessage);
 
       switch (parsedMessage.id) {
 
@@ -88,11 +89,11 @@ export default class VideoDock extends Component {
           if (webRtcPeer !== null) {
             webRtcPeer.addIceCandidate(parsedMessage.candidate, (err) => {
               if (err) {
-                return console.error(`Error adding candidate: ${err}`);
+                return log('error', `Error adding candidate: ${err}`);
               }
             });
           } else {
-            console.error(' [ICE] Message arrived before webRtcPeer?');
+            log('error', ' [ICE] Message arrived before webRtcPeer?');
           }
 
           break;
@@ -106,8 +107,8 @@ export default class VideoDock extends Component {
 
     const ws = this.state.ws;
 
-    console.log(`Starting video call for video: ${id}`);
-    console.log('Creating WebRtcPeer and generating local sdp offer ...');
+    log('info', `Starting video call for video: ${id}`);
+    log('info', 'Creating WebRtcPeer and generating local sdp offer ...');
 
     const onIceCandidate = function (candidate) {
       const message = {
@@ -148,8 +149,8 @@ export default class VideoDock extends Component {
 
     this.state.webRtcPeers[id] = new peerObj(options, function (error) {
       if (error) {
-        console.error(' [ERROR] Webrtc error');
-        console.error(error);
+        log('error', ' [ERROR] Webrtc error');
+        log('error', error);
         return;
       }
 
@@ -160,10 +161,10 @@ export default class VideoDock extends Component {
 
       this.generateOffer((error, offerSdp) => {
         if (error) {
-          return console.error(error);
+          return log('error', error);
         }
 
-        console.info(`Invoking SDP offer callback function ${location.host}`);
+        log('info', `Invoking SDP offer callback function ${location.host}`);
         const message = {
           id: 'start',
           sdpOffer: offerSdp,
@@ -183,7 +184,7 @@ export default class VideoDock extends Component {
     const webRtcPeer = this.state.webRtcPeers[id];
 
     if (webRtcPeer) {
-      console.log('Stopping WebRTC peer');
+      log('info', 'Stopping WebRTC peer');
 
       if (id == this.state.myId) {
         this.state.sharedWebcam.dispose();
@@ -193,7 +194,7 @@ export default class VideoDock extends Component {
       webRtcPeer.dispose();
       delete this.state.webRtcPeers[id];
     } else {
-      console.log('NO WEBRTC PEER TO STOP?');
+      log('info', 'NO WEBRTC PEER TO STOP?');
     }
 
     const videoTag = document.getElementById(`video-elem-${id}`);
@@ -214,7 +215,7 @@ export default class VideoDock extends Component {
   }
 
   unshareWebcam() {
-    console.log("Unsharing webcam");
+    log('info', "Unsharing webcam");
     const { users } = this.props;
     const id = users[0].userId;
     this.sendUserUnshareWebcam(id);
@@ -225,18 +226,18 @@ export default class VideoDock extends Component {
     const webRtcPeer = this.state.webRtcPeers[id];
 
     if (message.sdpAnswer == null) {
-      return console.debug('Null sdp answer. Camera unplugged?');
+      return log('debug', 'Null sdp answer. Camera unplugged?');
     }
 
     if (webRtcPeer == null) {
-      return console.debug('Null webrtc peer ????');
+      return log('debug', 'Null webrtc peer ????');
     }
 
-    console.log('SDP answer received from server. Processing ...');
+    log('info', 'SDP answer received from server. Processing ...');
 
     webRtcPeer.processAnswer(message.sdpAnswer, (error) => {
       if (error) {
-        return console.error(error);
+        return log(error);
       }
     });
 
@@ -248,10 +249,10 @@ export default class VideoDock extends Component {
 
     if (ws.readyState == WebSocket.OPEN) {
       const jsonMessage = JSON.stringify(message);
-      console.log(`Sending message: ${jsonMessage}`);
+      log('info', `Sending message: ${jsonMessage}`);
       ws.send(jsonMessage, (error) => {
         if (error) {
-          console.error(`client: Websocket error "${error}" on message "${jsonMessage.id}"`);
+          log('debug', `client: Websocket error "${error}" on message "${jsonMessage.id}"`);
         }
       });
     } else {
@@ -260,19 +261,19 @@ export default class VideoDock extends Component {
   }
 
   handlePlayStop(message) {
-    console.log('Handle play stop <--------------------');
+    log('info', 'Handle play stop <--------------------');
 
     this.stop(message.cameraId);
   }
 
   handlePlayStart(message) {
-    console.log('Handle play start <===================');
+    log('info', 'Handle play start <===================');
 
     window.adjustVideos('webcamArea', true);
   }
 
   handleError(message) {
-    console.log(` Handle error ---------------------> ${message.message}`);
+    log('error', ` Handle error ---------------------> ${message.message}`);
   }
 
   render() {
@@ -296,7 +297,7 @@ export default class VideoDock extends Component {
         if (users && users[i] &&
               nextUsers && nextUsers[i]) {
           if (users[i].has_stream !== nextUsers[i].has_stream) {
-            console.log(`User ${nextUsers[i].has_stream ? '' : 'un'}shared webcam ${users[i].userId}`);
+            log('info', `User ${nextUsers[i].has_stream ? '' : 'un'}shared webcam ${users[i].userId}`);
 
             if (nextUsers[i].has_stream) {
               this.start(users[i].userId, false, this.refs.videoInput);
diff --git a/bigbluebutton-html5/public/js/adjust-videos.js b/bigbluebutton-html5/public/js/adjust-videos.js
index 5d8e44e942..bdacb7f984 100644
--- a/bigbluebutton-html5/public/js/adjust-videos.js
+++ b/bigbluebutton-html5/public/js/adjust-videos.js
@@ -85,7 +85,5 @@
     videos.attr('height', best.height);
   }
 
-  console.log(" ---------------------------------- bro!!!");
-
   window.adjustVideos = adjustVideos;
 })();
diff --git a/bigbluebutton-html5/server/main.js b/bigbluebutton-html5/server/main.js
index 1dab09e287..ac582ccc46 100644
--- a/bigbluebutton-html5/server/main.js
+++ b/bigbluebutton-html5/server/main.js
@@ -14,6 +14,7 @@ import '/imports/api/chat/server';
 import '/imports/api/screenshare/server';
 import '/imports/api/voice-users/server';
 import '/imports/api/whiteboard-multi-user/server';
+import '/imports/api/video/server';
 
 // Commons
 import '/imports/api/log-client/server';
-- 
GitLab