-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #471 from edx/dahlia/proctoring-master
Dahlia/proctoring master
- Loading branch information
Showing
18 changed files
with
224 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export const handlerWrapper = (Handler) => { | ||
let handler = new Handler({}); | ||
|
||
self.addEventListener("message", (message) => { | ||
switch(message.data.type) { | ||
case 'config': { | ||
handler = new Handler(message.data.options); | ||
break; | ||
} | ||
case 'startExamAttempt': { | ||
if(handler.onStartExamAttempt) { | ||
handler.onStartExamAttempt().then(() => self.postMessage({type: 'examAttemptStarted'})) | ||
} | ||
break; | ||
} | ||
case 'endExamAttempt': { | ||
if(handler.onEndExamAttempt) { | ||
handler.onEndExamAttempt().then(() => self.postMessage({type: 'examAttemptEnded'})) | ||
} | ||
break; | ||
} | ||
case 'ping': { | ||
if(handler.onPing) { | ||
handler.onPing().then(() => self.postMessage({type: 'echo'})) | ||
} | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
} | ||
export default handlerWrapper; |
95 changes: 95 additions & 0 deletions
95
edx_proctoring/static/proctoring/js/exam_action_handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
var edx = edx || {}; | ||
|
||
(function($) { | ||
'use strict'; | ||
|
||
var actionToMessageTypesMap = { | ||
'submit': { | ||
promptEventName: 'endExamAttempt', | ||
responseEventName: 'examAttemptEnded' | ||
}, | ||
'start': { | ||
promptEventName: 'startExamAttempt', | ||
responseEventName: 'examAttemptStarted' | ||
} | ||
}; | ||
|
||
function workerPromiseForEventNames(eventNames) { | ||
return function() { | ||
var proctoringBackendWorker = new Worker(edx.courseware.proctored_exam.configuredWorkerURL); | ||
return new Promise(function(resolve) { | ||
var responseHandler = function(e) { | ||
if (e.data.type === eventNames.responseEventName) { | ||
proctoringBackendWorker.removeEventListener('message', responseHandler); | ||
proctoringBackendWorker.terminate(); | ||
resolve(); | ||
} | ||
}; | ||
proctoringBackendWorker.addEventListener('message', responseHandler); | ||
proctoringBackendWorker.postMessage({ type: eventNames.promptEventName}); | ||
}); | ||
}; | ||
} | ||
|
||
// Update the state of the attempt | ||
function updateExamAttemptStatusPromise(actionUrl, action) { | ||
return function() { | ||
return Promise.resolve($.ajax({ | ||
url: actionUrl, | ||
type: 'PUT', | ||
data: { | ||
action: action | ||
} | ||
})); | ||
}; | ||
} | ||
|
||
function reloadPage() { | ||
location.reload(); | ||
} | ||
|
||
|
||
edx.courseware = edx.courseware || {}; | ||
edx.courseware.proctored_exam = edx.courseware.proctored_exam || {}; | ||
edx.courseware.proctored_exam.examStartHandler = function(e) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
|
||
var $this = $(this); | ||
var actionUrl = $this.data('change-state-url'); | ||
var action = $this.data('action'); | ||
|
||
var shouldUseWorker = window.Worker && edx.courseware.proctored_exam.configuredWorkerURL; | ||
if(shouldUseWorker) { | ||
workerPromiseForEventNames(actionToMessageTypesMap[action])() | ||
.then(updateExamAttemptStatusPromise(actionUrl, action)) | ||
.then(reloadPage); | ||
} else { | ||
updateExamAttemptStatusPromise(actionUrl, action)() | ||
.then(reloadPage); | ||
} | ||
}; | ||
edx.courseware.proctored_exam.examEndHandler = function() { | ||
|
||
$(window).unbind('beforeunload'); | ||
|
||
var $this = $(this); | ||
var actionUrl = $this.data('change-state-url'); | ||
var action = $this.data('action'); | ||
|
||
var shouldUseWorker = window.Worker && | ||
edx.courseware.proctored_exam.configuredWorkerURL && | ||
action === "submit"; | ||
if(shouldUseWorker) { | ||
|
||
updateExamAttemptStatusPromise(actionUrl, action)() | ||
.then(workerPromiseForEventNames(actionToMessageTypesMap[action])) | ||
.then(reloadPage); | ||
} else { | ||
updateExamAttemptStatusPromise(actionUrl, action)() | ||
.then(reloadPage); | ||
} | ||
} | ||
|
||
|
||
}).call(this, $); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.