मुझे AngularJS और निर्देशों के साथ एक बहुत ही बुनियादी उदाहरण के साथ समस्या है। मैं एक निर्देश बनाना चाहता हूं जो webrtc के साथ एक वेबकैम छवि दिखाता है। मेरे कोड पूरी तरह से स्ट्रीम दिखाई लेकिन अगर मैं समय समाप्त (उदाहरण के लिए एक कैनवास ताज़ा करने के लिए) जोड़ने $ टाइमआउट काम नहीं करते इस कोड है:
wtffDirectives.directive('scannerGun',function($timeout){
return {
restrict: 'E',
template: '<div>' +
'<video ng-hide="videoStatus"></video>' +
'<canvas id="canvas-source"></canvas>' +
'</div>',
replace: true,
transclude: true,
scope: false,
link: function postLink($scope, element){
$scope.canvasStatus = true;
$scope.videoStatus = false;
width = element.width = 320;
height = element.height = 0;
/* this method draw the webcam image into a canvas */
var drawVideoCanvas = function(){
sourceContext.drawImage(vid,0,0, vid.width, vid.height);
};
/* start the timeout that take a screenshot and draw the source canvas */
var update = function(){
var timeout = $timeout(function(){
console.log("pass"); //the console log show only one "pass"
//drawVideoCanvas();
}, 2000);
};
/* this work perfectly and reproduct into the video tag the webcam */
var onSuccess = function onSuccess(stream) {
// Firefox supports a src object
if (navigator.mozGetUserMedia) {
vid.mozSrcObject = stream;
} else {
var vendorURL = window.URL || window.webkitURL;
vid.src = vendorURL.createObjectURL(stream);
}
/* Start playing the video to show the stream from the webcam*/
vid.play();
update();
};
var onFailure = function onFailure(err) {
if (console && console.log) {
console.log('The following error occured: ', err);
}
return;
};
var vid = element.find('video')[0];
var sourceCanvas = element.find('canvas')[0];
var sourceContext = sourceCanvas.getContext('2d');
height = (vid.videoHeight/((vid.videoWidth/width))) || 250;
vid.setAttribute('width', width);
vid.setAttribute('height', height);
navigator.getMedia (
// ask only for video
{
video: true,
audio: false
},
onSuccess,
onFailure
);
}
}
});
क्या समस्या है? इस समय में $ टाइमआउट क्यों काम नहीं करता है? और अंत में एक समाधान है?
धन्यवाद की अग्रिम
Ufff खेद अपना समय बर्बाद करने के लिए .... यह सही है !!! एक अच्छा दिन है – cingusoft
यदि आप आरसी संस्करण (1.2.x) का उपयोग कर रहे हैं, तो 'setInterval' और '$ scope। $ Apply' के बजाय' $ interval' का उपयोग करने पर विचार करें। '$ अंतराल 'आपके लिए डोम रीफ्रेश की देखभाल करेगा। –