Global

Members

VERSION

The library version.

Methods

check(optionsopt) → {Promise}

Computer and network check without UI.
Parameters:
Name Type Attributes Description
options Object <optional>
Options for run specific checks.
Properties
Name Type Attributes Description
browser boolean <optional>
Browser check.
camera boolean <optional>
Camera check.
microphone boolean <optional>
Microphone check.
screen boolean <optional>
Screen check.
network boolean <optional>
Network check.
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
Name Type Attributes Default Description
provider string <optional>
"jwt" Authorization provider (jwt, plain).
token string | function | Promise <optional>
JSON Web Token with specific payload.
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({ 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() → {Promise}

Log out from the session.
Returns:
Type
Promise
Example
supervisor.logout();

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
Name Type Attributes Description
lang string <optional>
UI language ("en" or "ru").
face File | string <optional>
File or identifier of face image.
passport File | string <optional>
File or identifier of passport image.
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
Name Type Attributes Default Description
format string <optional>
"image/jpeg" Image format (image/jpeg or image/png).
quality number <optional>
0.8 Image quality.
scale number <optional>
1 Image scale factor.
filename string <optional>
File name for saving as File.
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
Name Type Attributes Description
token string <optional>
Session token.
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
Name Type Attributes Description
type string <optional>
Recognize the user's face or passport.
filename string <optional>
File name for base64 source.
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
});