diff --git a/lms/static/js/verify_student/CameraCapture.as b/lms/static/js/verify_student/CameraCapture.as index a3f68863c6..1d55f80b37 100644 --- a/lms/static/js/verify_student/CameraCapture.as +++ b/lms/static/js/verify_student/CameraCapture.as @@ -58,6 +58,7 @@ package ExternalInterface.addCallback("reset", reset); ExternalInterface.addCallback("imageDataUrl", imageDataUrl); ExternalInterface.addCallback("cameraAuthorized", cameraAuthorized); + ExternalInterface.addCallback("hasCamera", hasCamera); // Notify the container that the SWF is ready to be called. ExternalInterface.call("setSWFIsReady"); @@ -108,6 +109,10 @@ package return permissionGiven; } + public function hasCamera():Boolean { + return (Camera.names.length != 0); + } + public function statusHandler(event:StatusEvent):void { switch (event.code) { diff --git a/lms/static/js/verify_student/CameraCapture.swf b/lms/static/js/verify_student/CameraCapture.swf index 47f87c9493..5ad17e7631 100644 Binary files a/lms/static/js/verify_student/CameraCapture.swf and b/lms/static/js/verify_student/CameraCapture.swf differ diff --git a/lms/static/js/verify_student/photocapture.js b/lms/static/js/verify_student/photocapture.js index e29f02ebed..ad36fe8f2f 100644 --- a/lms/static/js/verify_student/photocapture.js +++ b/lms/static/js/verify_student/photocapture.js @@ -1,5 +1,10 @@ var onVideoFail = function(e) { - console.log('Failed to get camera access!', e); + if(e == 'NO_DEVICES_FOUND') { + $('#no-webcam').show(); + } + else { + console.log('Failed to get camera access!', e); + } }; // Returns true if we are capable of video capture (regardless of whether the @@ -110,6 +115,7 @@ function initSnapshotHandler(names, hasHtml5CameraSupport) { if (hasHtml5CameraSupport) { ctx = canvas[0].getContext('2d'); } + var localMediaStream = null; function snapshot(event) { @@ -188,13 +194,38 @@ function initSnapshotHandler(names, hasHtml5CameraSupport) { } +function browserHasFlash() { + var hasFlash = false; + try { + var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); + if(fo) hasFlash = true; + } catch(e) { + if(navigator.mimeTypes["application/x-shockwave-flash"] != undefined) hasFlash = true; + } + return hasFlash; +} + function objectTagForFlashCamera(name) { - return ''; + // detect whether or not flash is available + if(browserHasFlash()) { + // I manually update this to have ?v={2,3,4, etc} to avoid caching of flash + // objects on local dev. + return ''; + } + else { + // display a message informing the user to install flash + $('#no-flash').show(); + } +} + +function linkNewWindow(e) { + window.open($(e.target).attr('href')); + e.preventDefault(); } $(document).ready(function() { @@ -233,9 +264,18 @@ $(document).ready(function() { if (!hasHtml5CameraSupport) { $("#face_capture_div").html(objectTagForFlashCamera("face_flash")); $("#photo_id_capture_div").html(objectTagForFlashCamera("photo_id_flash")); + // wait for the flash object to be loaded + // TODO: we need a better solution for this + setTimeout(function() { + if(browserHasFlash() && !$('#face_flash')[0].hasOwnProperty('hasCamera')) { + onVideoFail('NO_DEVICES_FOUND'); + } + }, 1000); } analytics.pageview("Capture Face Photo"); initSnapshotHandler(["photo_id", "face"], hasHtml5CameraSupport); + $('a[rel="external"]').attr('title', gettext('This link will open in a new browser window/tab')).bind('click', linkNewWindow); + }); diff --git a/lms/templates/verify_student/photo_verification.html b/lms/templates/verify_student/photo_verification.html index 3249e5bcd4..bec59216be 100644 --- a/lms/templates/verify_student/photo_verification.html +++ b/lms/templates/verify_student/photo_verification.html @@ -13,6 +13,32 @@ <%block name="content"> + + + + + +