From af194a64b8691d581dfa09129e7aeee6bee47d85 Mon Sep 17 00:00:00 2001 From: Simon Eisenmann Date: Tue, 28 Jul 2015 15:08:46 +0200 Subject: [PATCH] Remove deprecated MediaStream.stop api (see https://groups.google.com/a/chromium.org/forum/#\!msg/blink-dev/s0UsMk8i2YM/WpepA4w3mPEJ for details). --- static/js/directives/buddypicturecapture.js | 4 +-- static/js/mediastream/usermedia.js | 24 +++++++++++--- static/js/mediastream/webrtc.js | 3 -- static/js/services/services.js | 9 ++++-- static/js/services/usermedia.js | 36 +++++++++++++++++++++ 5 files changed, 64 insertions(+), 12 deletions(-) create mode 100644 static/js/services/usermedia.js diff --git a/static/js/directives/buddypicturecapture.js b/static/js/directives/buddypicturecapture.js index 32e3625f..73e1a865 100644 --- a/static/js/directives/buddypicturecapture.js +++ b/static/js/directives/buddypicturecapture.js @@ -25,7 +25,7 @@ define(['jquery', 'underscore', 'text!partials/buddypicturecapture.html'], funct // buddyPictureCapture return ["$compile", "$window", function($compile, $window) { - var controller = ['$scope', 'safeApply', '$timeout', '$q', "mediaDevices", function($scope, safeApply, $timeout, $q, mediaDevices) { + var controller = ['$scope', 'safeApply', '$timeout', '$q', "mediaDevices", "userMedia", function($scope, safeApply, $timeout, $q, mediaDevices, userMedia) { // Buddy picutre capture size. $scope.captureSize = { @@ -110,7 +110,7 @@ define(['jquery', 'underscore', 'text!partials/buddypicturecapture.html'], funct var videoStop = function(stream, video) { if (stream) { video.pause(); - stream.stop(); + userMedia.stopUserMediaStream(stream); stream = null; } }; diff --git a/static/js/mediastream/usermedia.js b/static/js/mediastream/usermedia.js index b6bf2cf0..ee1dd891 100644 --- a/static/js/mediastream/usermedia.js +++ b/static/js/mediastream/usermedia.js @@ -106,6 +106,20 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr } })(); + var stopUserMediaStream = (function() { + return function(stream) { + if (stream && stream.getTracks) { + var tracks = stream.getTracks(); + _.each(tracks, function(t) { + t.stop(); + }); + } else { + console.warn("MediaStream.stop is deprecated"); + stream.stop(); + } + } + })(); + // UserMedia. var UserMedia = function(options) { @@ -201,7 +215,7 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr clearTimeout(timeout); timeout = null; } - stream.stop(); + stopUserMediaStream(stream); if (complete.done) { return; } @@ -238,6 +252,8 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr })({}); }; + UserMedia.getUserMedia = getUserMedia; + UserMedia.stopUserMediaStream = stopUserMediaStream; UserMedia.prototype.doGetUserMedia = function(currentcall, mediaConstraints) { @@ -295,7 +311,7 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr console.log('User has granted access to local media.'); if (!this.started) { - stream.stop(); + stopUserMediaStream(stream); return; } @@ -323,7 +339,7 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr oldStream.onended = function() { console.log("Silently ended replaced user media stream."); }; - oldStream.stop(); + stopUserMediaStream(oldStream); } if (stream) { @@ -368,7 +384,7 @@ define(['jquery', 'underscore', 'audiocontext', 'mediastream/dummystream', 'webr this.audioSource = null; } if (this.localStream) { - this.localStream.stop() + stopUserMediaStream(this.localStream); this.localStream = null; } if (this.audioProcessor) { diff --git a/static/js/mediastream/webrtc.js b/static/js/mediastream/webrtc.js index 946bbae0..ed8e77c5 100644 --- a/static/js/mediastream/webrtc.js +++ b/static/js/mediastream/webrtc.js @@ -357,9 +357,6 @@ function($, _, PeerCall, PeerConference, PeerXfer, PeerScreenshare, UserMedia, u var success = function(stream) { console.info("testMediaAccess success"); - if (stream) { - stream.stop(); - } cb(true); } var failed = function() { diff --git a/static/js/services/services.js b/static/js/services/services.js index 198b92ee..4fa9919a 100644 --- a/static/js/services/services.js +++ b/static/js/services/services.js @@ -69,7 +69,8 @@ define([ 'services/modules', 'services/mediadevices', 'services/sandbox', - 'services/dummystream'], function(_, + 'services/dummystream', + 'services/usermedia'], function(_, desktopNotify, playSound, safeApply, @@ -116,7 +117,8 @@ constraints, modules, mediaDevices, sandbox, -dummyStream) { +dummyStream, +userMedia) { var services = { desktopNotify: desktopNotify, @@ -165,7 +167,8 @@ dummyStream) { modules: modules, mediaDevices: mediaDevices, sandbox: sandbox, - dummyStream: dummyStream + dummyStream: dummyStream, + userMedia: userMedia }; var initialize = function(angModule) { diff --git a/static/js/services/usermedia.js b/static/js/services/usermedia.js new file mode 100644 index 00000000..5d64c87a --- /dev/null +++ b/static/js/services/usermedia.js @@ -0,0 +1,36 @@ +/* + * Spreed WebRTC. + * Copyright (C) 2013-2015 struktur AG + * + * This file is part of Spreed WebRTC. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +"use strict"; +define(['mediastream/usermedia'], function(UserMedia) { + + // userMedia + return [function() { + + // Public api. + return { + getUserMedia: UserMedia.getUserMedia, + stopUserMediaStream: UserMedia.stopUserMediaStream + } + + }]; + +}); \ No newline at end of file