pass along reservation_no from Archimedes
This commit is contained in:
parent
60b5f21f76
commit
66b8ef945f
@ -12,7 +12,8 @@ const HTTP_PORT = app.httpPort;
|
|||||||
import { Server, IncomingMessage, ServerResponse } from 'http'
|
import { Server, IncomingMessage, ServerResponse } from 'http'
|
||||||
|
|
||||||
interface ArchimedesMessage {
|
interface ArchimedesMessage {
|
||||||
examId: string;
|
examId: string,
|
||||||
|
reservation_no: string
|
||||||
}
|
}
|
||||||
|
|
||||||
class XhrListener {
|
class XhrListener {
|
||||||
@ -28,15 +29,18 @@ class XhrListener {
|
|||||||
logger.debugLog.info("XhrListener running");
|
logger.debugLog.info("XhrListener running");
|
||||||
}
|
}
|
||||||
|
|
||||||
public relayEvent(event: string, channel: string): boolean {
|
public relayEvent(event: string, archMsg: ArchimedesMessage): boolean {
|
||||||
logger.debugLog.info(`XhrListener:relayEvent(event: ${event}, channel: ${channel})`);
|
logger.debugLog.info(`XhrListener:relayEvent(event: ${event}, channel: ${archMsg.examId})`);
|
||||||
for (let c of this.#cm.channels) {
|
for (let c of this.#cm.channels) {
|
||||||
if (channel === c.id) {
|
if (archMsg.examId === c.id) {
|
||||||
let dmCount: number = 0;
|
let dmCount: number = 0;
|
||||||
for (let client of c.clients) {
|
for (let client of c.clients) {
|
||||||
let nonce: string = crypto.randomBytes(4).toString("hex");
|
let nonce: string = crypto.randomBytes(4).toString("hex");
|
||||||
// TODO: verify the nonce against the received reply, which we currently ignore
|
// TODO: verify the nonce against the received reply, which we currently ignore
|
||||||
client.directMessage(JSON.stringify({ message_type: "broadcast", message: { event_type: event, seq_id: nonce } }));
|
client.directMessage(JSON.stringify({
|
||||||
|
message_type: "broadcast",
|
||||||
|
message: { event_type: event, seq_id: nonce, reservation_no: archMsg.reservation_no }
|
||||||
|
}));
|
||||||
dmCount++;
|
dmCount++;
|
||||||
}
|
}
|
||||||
// dmCount of 1 would be normal. more than 1 is odd, but not necessarily bad. 0 means Exam UI has gone away somehow.
|
// dmCount of 1 would be normal. more than 1 is odd, but not necessarily bad. 0 means Exam UI has gone away somehow.
|
||||||
@ -63,13 +67,13 @@ class XhrListener {
|
|||||||
let returnVal: [number, string] = [-1, ""];
|
let returnVal: [number, string] = [-1, ""];
|
||||||
let authorized: boolean = request.headers['x-proctoru-signature'] === AUTH_TOKEN;
|
let authorized: boolean = request.headers['x-proctoru-signature'] === AUTH_TOKEN;
|
||||||
|
|
||||||
// body of POST is JSON: '{"examId":"proctor_u_id"}'
|
// body of POST is JSON: '{"examId":"proctor_u_id", "reservation_no":"primary_key_from_archimedes"}'
|
||||||
switch (true) {
|
switch (true) {
|
||||||
// match /event/pause*
|
// match /event/pause*
|
||||||
case /^\/event\/pause([/]+.*)*$/.test(endpoint):
|
case /^\/event\/pause([/]+.*)*$/.test(endpoint):
|
||||||
if (authorized) {
|
if (authorized) {
|
||||||
let amsg: ArchimedesMessage = JSON.parse(Buffer.concat(body).toString());
|
let amsg: ArchimedesMessage = JSON.parse(Buffer.concat(body).toString());
|
||||||
if (this.relayEvent("pauseExam", amsg.examId)) {
|
if (this.relayEvent("pauseExam", amsg)) {
|
||||||
returnVal = [200, "pause event was successfully relayed"];
|
returnVal = [200, "pause event was successfully relayed"];
|
||||||
} else {
|
} else {
|
||||||
logger.errorLog.info(`XhrListener: could not relay pause event "${amsg}" to Exam UI; body: "${body}"`);
|
logger.errorLog.info(`XhrListener: could not relay pause event "${amsg}" to Exam UI; body: "${body}"`);
|
||||||
@ -83,7 +87,7 @@ class XhrListener {
|
|||||||
case /^\/event\/resume([/]+.*)*$/.test(endpoint):
|
case /^\/event\/resume([/]+.*)*$/.test(endpoint):
|
||||||
if (authorized) {
|
if (authorized) {
|
||||||
let amsg: ArchimedesMessage = JSON.parse(Buffer.concat(body).toString());
|
let amsg: ArchimedesMessage = JSON.parse(Buffer.concat(body).toString());
|
||||||
if (this.relayEvent("resumeExam", amsg.examId)) {
|
if (this.relayEvent("resumeExam", amsg)) {
|
||||||
returnVal = [200, "resume event was successfully relayed"];
|
returnVal = [200, "resume event was successfully relayed"];
|
||||||
} else {
|
} else {
|
||||||
logger.errorLog.info(`XhrListener: could not relay resume event "${amsg}" to Exam UI; body: "${body}"`);
|
logger.errorLog.info(`XhrListener: could not relay resume event "${amsg}" to Exam UI; body: "${body}"`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user