Members
VERSION
Get the SDK version.
el
Get the current HTML element.
Methods
check(optionsopt) → {Promise}
Computer and network check without UI.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Options for run specific checks.
Properties
|
Returns:
- Type
- Promise
Example
// run all checks
supervisor.check().then(function() {
// success
}).catch(function(err) {
// error
});
// run specific checks
supervisor.check({ browser: true }).then(function() {
// success
}).catch(function(err) {
// error
});
close() → {Promise}
Close the session without stopping.
It will be possible to continue the session by calling the start again.
Returns:
- Type
- Promise
Example
supervisor.close();
emit(event, data) → {Promise}
Dispatch event.
Parameters:
Name | Type | Description |
---|---|---|
event |
string | Array.<string> | Type of event. |
data |
Object | Event data. |
Returns:
Called after the event is sent.
- Type
- Promise
init(options) → {Promise}
Initialize proctoring session from specific payload.
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Initialization options.
Properties
|
Returns:
Session token.
- Type
- Promise
Example
var iat = ~~(Date.now() / 1000); // in seconds since UNIX epoch
var payload = {
// JWT validation
iat: iat, // issued at
exp: iat + 12*60*60, // expires after 12 hours
// user fields
username: 'user1', // unique user ID
nickname: 'Ivan Petrov', // any string
// session fields
identifier: '98cb5846-3fed-11e7-a919-92ebcb67fe33', // unique session ID
subject: 'Test 1', // any string
timeout: 30 // session timeout in minutes
};
// initialize the session with JWT
supervisor.init({ provider: 'jwt', token: generateToken('secret', payload) });
// or initialize the session with plain object (not recommended for production)
// supervisor.init({ provider: 'plain', ...payload });
// Helper function for generate JWT token on client via KJUR library
// <script src="//kjur.github.io/jsrsasign/jsrsasign-all-min.js"></script>
// Attention! For safety generate the token on your server.
function generateToken(secret, payload) {
var header = {
alg: 'HS256',
typ: 'JWT'
};
return KJUR.jws.JWS.sign(null, header, payload, secret);
}
logout(options) → {Promise}
Log out from the session.
Parameters:
Name | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Log out options.
Properties
|
Returns:
- Type
- Promise
Example
supervisor.logout({ redirect: true });
lookup(…argsopt) → {Object}
Lookup the session fields.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
args |
string | Array.<string> |
<optional> <repeatable> |
List of fields. |
Returns:
Fields and values of the session.
- Type
- Object
Example
supervisor.lookup('identifier', 'username', 'subject', 'duration');
off(event, callbackopt)
Remove event handler.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
event |
string | Array.<string> | Type of event. | |
callback |
Supervisor~eventHandler |
<optional> |
Callback function for event. |
Example
// single event
supervisor.off('stop');
// multiple events
supervisor.off(['face', 'metrics']);
on(event, callback)
Add event handler.
Parameters:
Name | Type | Description |
---|---|---|
event |
string | Array.<string> | Type of event. |
callback |
Supervisor~eventHandler | Callback function for event. |
Example
// single event
supervisor.on('stop', function() {
// event occurred
});
// multiple events
supervisor.on(['face', 'metrics'], function(data) {
// events occurred
});
profile(options) → {Promise}
Update the user profile.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Profile object for update.
Properties
|
Returns:
- Type
- Promise
Example
var video = document.getElementById('video');
// capture an image from the video element
var file = supervisor.snapshot(video, { filename: 'face.jpg' });
// update the user's profile
supervisor.profile({ face: file });
qrcode() → {Promise}
Get token and QR code for the session.
Returns:
- Type
- Promise
Example
supervisor.qrcode();
snapshot(video, optionsopt) → {string|File}
Take a snapshot of the video.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
video |
HTMLVideoElement | Video element. | ||||||||||||||||||||||||||
options |
Object |
<optional> |
Options for capture the image.
Properties
|
Returns:
-
Image as base64.
- Type
- string
-
Image as File.
- Type
- File
Example
var video = document.getElementById('video');
// capture video from the user's camera
navigator.mediaDevices.getUserMedia({
video: true
}).then(function(stream) {
video.srcObject = stream;
video.play();
}).catch(function(err) {
alert(err.toString());
});
video.onplaying = function () {
// capture an image from the video element
var dataUrl = supervisor.snapshot(video);
}
start() → {Promise}
Start or resume the session.
Fires:
Returns:
- Type
- Promise
Example
supervisor.start();
stop() → {Promise}
Stop the session.
Fires:
Returns:
- Type
- Promise
Example
supervisor.stop();
sync(options) → {Promise}
Synchronize the session state by token.
Parameters:
Name | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
options |
Object | Initialization options.
Properties
|
Returns:
- Type
- Promise
Example
supervisor.sync({ token: 'SESSION_TOKEN' });
upload(file, optionsopt) → {Promise}
Upload a file to server.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
file |
File | Base64 | File source. | |||||||||||||
options |
Object |
<optional> |
Upload options.
Properties
|
Returns:
- Type
- Promise
Example
var video = document.getElementById('video');
// capture an image in base64 from the video element
var file = supervisor.snapshot(video);
// upload the file to server
supervisor.upload(file, {
filename: 'face.jpg',
type: 'face'
}).then(function(attach) {
// attach.id - File ID
// attach.mimetype - Mime type
// attach.filename - File name
// attach.size - File size in bytes
// attach.createdAt - Upload date
// attach.metadata - Metadata
});