From 83ce388a742ca47eb5b5d8ef0ed560c093794061 Mon Sep 17 00:00:00 2001 From: bahtiyarerden Date: Mon, 15 Apr 2019 15:31:03 +0300 Subject: [PATCH 1/2] Deprecated createObjectURL issue fixed --- qr-scanner.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/qr-scanner.js b/qr-scanner.js index 6f3a309..e615e63 100644 --- a/qr-scanner.js +++ b/qr-scanner.js @@ -15,13 +15,13 @@ angular.module('qrScanner', ["ng"]).directive('qrScanner', ['$interval', '$windo ngVideoError: '&ngVideoError' }, link: function(scope, element, attrs) { - + window.URL = window.URL || window.webkitURL || window.mozURL || window.msURL; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; - + var height = attrs.height || 300; var width = attrs.width || 250; - + var video = $window.document.createElement('video'); video.setAttribute('width', width); video.setAttribute('height', height); @@ -30,13 +30,13 @@ angular.module('qrScanner', ["ng"]).directive('qrScanner', ['$interval', '$windo canvas.setAttribute('id', 'qr-canvas'); canvas.setAttribute('width', width); canvas.setAttribute('height', height); - canvas.setAttribute('style', 'display:none;'); - + canvas.setAttribute('style', 'display:none;'); + angular.element(element).append(video); angular.element(element).append(canvas); - var context = canvas.getContext('2d'); + var context = canvas.getContext('2d'); var stopScan; - + var scan = function() { if ($window.localMediaStream) { context.drawImage(video, 0, 0, 307,250); @@ -49,7 +49,7 @@ angular.module('qrScanner', ["ng"]).directive('qrScanner', ['$interval', '$windo } var successCallback = function(stream) { - video.src = (window.URL && window.URL.createObjectURL(stream)) || stream; + video.srcObject = stream $window.localMediaStream = stream; scope.video = video; From cebebe9b13deebda6e183862ef169c3641bf8fd0 Mon Sep 17 00:00:00 2001 From: bahtiyarerden Date: Mon, 15 Apr 2019 15:37:35 +0300 Subject: [PATCH 2/2] catch error for support old browsers --- qr-scanner.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/qr-scanner.js b/qr-scanner.js index e615e63..ef35c9c 100644 --- a/qr-scanner.js +++ b/qr-scanner.js @@ -49,7 +49,11 @@ angular.module('qrScanner', ["ng"]).directive('qrScanner', ['$interval', '$windo } var successCallback = function(stream) { - video.srcObject = stream + try{ + video.srcObject = stream + }catch (error) { + video.src = (window.URL && window.URL.createObjectURL(stream)) || stream; + } $window.localMediaStream = stream; scope.video = video;