From 144219964742c35eebf6d75ae27ad17732c89dae Mon Sep 17 00:00:00 2001
From: enahum <nahumhbl@gmail.com>
Date: Tue, 3 Jan 2017 12:08:21 -0300
Subject: PLT-4644 Update webrtc client (#4922)

* PLT-4644 Update webrtc client

* update webrtc-adapter

* Use default ice server if none is provided
---
 webapp/components/webrtc/webrtc_controller.jsx | 37 +++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 6 deletions(-)

(limited to 'webapp/components/webrtc/webrtc_controller.jsx')

diff --git a/webapp/components/webrtc/webrtc_controller.jsx b/webapp/components/webrtc/webrtc_controller.jsx
index 7e0cdb098..36278b3f4 100644
--- a/webapp/components/webrtc/webrtc_controller.jsx
+++ b/webapp/components/webrtc/webrtc_controller.jsx
@@ -7,7 +7,7 @@ import WebrtcStore from 'stores/webrtc_store.jsx';
 
 import Client from 'client/web_client.jsx';
 import WebSocketClient from 'client/web_websocket_client.jsx';
-import WebrtcSession from 'client/webrtc_session.jsx';
+import Janus from 'janus';
 
 import SearchBox from '../search_bar.jsx';
 import WebrtcHeader from './components/webrtc_header.jsx';
@@ -44,6 +44,8 @@ export default class WebrtcController extends React.Component {
         this.close = this.close.bind(this);
         this.clearError = this.clearError.bind(this);
 
+        this.getLocalMedia = this.getLocalMedia.bind(this);
+        this.stopMediaStream = this.stopMediaStream.bind(this);
         this.previewVideo = this.previewVideo.bind(this);
         this.stopRinging = this.stopRinging.bind(this);
 
@@ -160,6 +162,30 @@ export default class WebrtcController extends React.Component {
         }, Constants.WEBRTC_CLEAR_ERROR_DELAY);
     }
 
+    getLocalMedia(constraints, element, callback) {
+        const media = constraints || {audio: true, video: true};
+        navigator.mediaDevices.getUserMedia(media).
+        then((stream) => {
+            if (element) {
+                element.srcObject = stream;
+            }
+
+            if (callback && typeof callback === 'function') {
+                callback(null, stream);
+            }
+        }).
+        catch((error) => {
+            callback(error);
+        });
+    }
+
+    stopMediaStream(stream) {
+        const tracks = stream.getTracks();
+        tracks.forEach((track) => {
+            track.stop();
+        });
+    }
+
     previewVideo() {
         if (this.mounted) {
             if (this.localMedia) {
@@ -169,7 +195,7 @@ export default class WebrtcController extends React.Component {
                 });
                 this.localMedia.enabled = true;
             } else {
-                WebrtcSession.getLocalMedia(
+                this.getLocalMedia(
                     {
                         audio: true,
                         video: {
@@ -399,12 +425,11 @@ export default class WebrtcController extends React.Component {
 
         if (this.session) {
             this.session.destroy();
-            this.session.disconnect();
             this.session = null;
         }
 
         if (this.localMedia) {
-            WebrtcSession.stopMediaStream(this.localMedia);
+            this.stopMediaStream(this.localMedia);
             this.localMedia = null;
         }
 
@@ -648,8 +673,8 @@ export default class WebrtcController extends React.Component {
                         });
                     }
 
-                    this.session = new WebrtcSession({
-                        debug: global.mm_config.EnableDeveloper === 'true',
+                    Janus.init({debug: global.mm_config.EnableDeveloper === 'true'});
+                    this.session = new Janus({
                         server: info.gateway_url,
                         iceServers,
                         token: info.token,
-- 
cgit v1.2.3-1-g7c22

