-
Notifications
You must be signed in to change notification settings - Fork 1
/
frame.php
242 lines (221 loc) · 8.88 KB
/
frame.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Proview
*
* This module provides support for remote proctoring quizzes and assessments using Proview
*
* @package local_proview
* @copyright Talview, 2020
* @author Talview Inc.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// Include config.php.
// @codingStandardsIgnoreStart
// Let codechecker ignore the next line because otherwise it would complain about a missing login check
// after requiring config.php which is really not needed.
require_once('../../config.php');
// @codingStandardsIgnoreEnd
// Globals.
global $PAGE, $COURSE;
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('embedded');
$PAGE->set_heading("Proview Quiz");
$PAGE->set_url('/local/proview/frame.php');
$sesskey = sesskey();
echo $OUTPUT->header();
?>
<iframe id="contentIFrame" title="Iframe application" style="width: 98vw; height:95vh; border: 0px;">
<p>Your browser does not support iframes.</p>
</iframe>
<script src="https://browser.sentry-cdn.com/5.18.1/bundle.min.js"
integrity="sha384-4zdOhGLDdcXl+MRlpApt/Nvfe6A3AqGGBil9+lwFSkXNTv0rVx0eCyM1EaJCXS7r"
crossorigin="anonymous">
</script>
<script>
var childOrigin = '*';
Sentry.init({
dsn: 'https://[email protected]/5304587'
});
// Defining function for event handling on postMessage from any window
function receiveMessage(event) {
try {
if(event.data.type == 'startProview') {
startProview(...event.data.args);
}
if(event.data.type == 'stopProview') {
stopProview(event.data.url);
}
} catch (error) {
if( error && error.error ) {
Sentry.captureException(error.error);
} else {
Sentry.captureException(error);
}
document.getElementById('contentIFrame').src = 'https://pages.talview.com/proview/error/index.html';
}
}
window.addEventListener("message", receiveMessage, false);
//Javascript function to start proview invoked upon postMessage from iframe
function startProview(
authToken,
profileId,
session,
session_type = "ai_proctor",
proview_url,
additionalInstruction,
reference_link,
proview_playback_url,
skipHardwareTest,
previewStyle,
clear) {
const referenceLinksArray = reference_link.match(/\[([^\]]+)\]\(([^)]+)\)/g)?.map(markdownLink => {
const match = markdownLink.match(/\[([^\]]+)\]\(([^)]+)\)/);
if (match) {
const caption = match[1];
const url = match[2];
return { 'url': url, 'caption': caption };
}
return null;
}).filter(link => link !== null);
let url = proview_url || '//cdn.proview.io/init.js';
document.getElementById('contentIFrame').src = window.iframeUrl;
//script to load the proview STARTS
(function(i,s,o,g,r,a,m){i['TalviewProctor']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script',url,'tv');
tv('init', authToken,{
profileId: profileId,
session: session,
session_type: session_type,
additionalInstruction: additionalInstruction,
referenceLinks: JSON.stringify(referenceLinksArray),
clear: clear || false,
skipHardwareTest: skipHardwareTest || false,
previewStyle: previewStyle || 'position: fixed; bottom: 0px;',
initCallback: createCallback(proview_playback_url, profileId, session_type)/* onProviewStart */
});
}
function createCallback (proview_playback_url, profile_id, session_type) {
return function onProviewStart(err, id) {
try {
const urlParams = new URLSearchParams(window.location.search);
window.ProviewStatus = 'start';
let iframeWindow = document.getElementById('contentIFrame').contentWindow;
//Lock quiz logic STARTS
const button = iframeWindow.document.getElementById('id_quizpassword');
if( button ) { //checking if the password is enabled for the quiz or not
button.value = window.quizPassword; //fetching the password value from the window object
iframeWindow.document.getElementById('mod_quiz_preflight_form').submit(); //submitting the password form
}
const id_submitbutton = iframeWindow.document.getElementById('id_submitbutton');
if( id_submitbutton ) { //handle if the test is timed quiz
id_submitbutton.click();//submitting the form
}
//Lock quiz logic ENDS
iframeWindow.postMessage({
type: 'startedProview',
args: [
err, //Error on proview stating, if any
id // Playback ID
]
}, childOrigin);
const arr = {
"user_id" : profile_id,
"quiz_id" : urlParams.get('quizId'),
"proview_url" : proview_playback_url+'/'+id,
"sesskey" : "<?php echo $sesskey ?>",
"proctor_type" : session_type
}
const xmlhttp = new XMLHttpRequest();
let retries=5;
function run(){
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState === 4) {
}
if (xmlhttp.status == 404) {
if (retries > 0) {
retries-=1;
run();
}else if(xmlhttp.readyState === 4) {
Sentry.captureException(new Error(xmlhttp));
}
}
}
xmlhttp.open("POST","datastore.php",true);
xmlhttp.send(JSON.stringify(arr));
}
run();
} catch (error) {
console.log("Enter catch")
if( error && error.error ) {
Sentry.captureException(error.error);
} else {
Sentry.captureException(error);
}
document.getElementById('contentIFrame').src = 'https://pages.talview.com/proview/error/index.html';
}
}
}
function stopProview(url) {
//Post message to application loaded into application on recording stop
if ( window.ProviewStatus && window.ProviewStatus == 'start') {
ProctorClient3.stop(function() {
window.ProviewStatus = 'stop';
document.getElementById('contentIFrame').contentWindow.postMessage({
type: 'stoppedProview',
url: url
}, childOrigin);
window.location.href = url;
});
} else {
document.getElementById('contentIFrame').contentWindow.postMessage({
type: 'stoppedProview',
url: url
}, childOrigin);
window.location.href = url;
}
}
(function() {
try {
const urlParams = new URLSearchParams(window.location.search);
window.iframeUrl = urlParams.get('url');
const xmlhttp = new XMLHttpRequest();
function run(){
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState === 4 && this.status == 200) {
response=xmlhttp.responseText;
response=JSON.parse(response);
window.quizPassword = response.quiz_password;
startProview(response.token, response.profile_id, response.session_id, response.session_type, response.proview_url, response.instructions, response.reference_link, response.proview_playback_url);
}
}
xmlhttp.open("GET", "datastore.php?quiz_id=" + urlParams.get('quizId') + "&sesskey=" + "<?php echo $sesskey?>" , true);
xmlhttp.send();
}
run();
} catch (error) {
if( error && error.error ) {
Sentry.captureException(error.error);
} else {
Sentry.captureException(error);
}
document.getElementById('contentIFrame').src = 'https://pages.talview.com/proview/error/index.html';
}
})();
</script>
<?php echo $OUTPUT->footer();