Members
(readonly) VERSION
Get the SDK version.
(readonly) el
Get the current HTML element.
Methods
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
});
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' });