new channel change request and exam status request

This commit is contained in:
Josh Burman 2019-03-25 02:44:35 -04:00
parent 273390d73e
commit 30d0d76b77
5 changed files with 14 additions and 9 deletions

View File

@ -91,8 +91,9 @@ class ChannelManager {
var channel = this.createChannel(changeRequest);
this.addClientToChannel(client, channel.id);
var message = {message_type: 'requestExamStatus'};
channel.broadcastMessage(client, message);
this.purgeEmptyChannels();
console.log(this.channels)
}
purgeEmptyChannels() {

View File

@ -45,7 +45,7 @@ class ChannelBase {
return false;
}
broadcastMessage(from: ClientBase|MHSClient|null, message: string) {
broadcastMessage(from: ClientBase|null, message: string) {
for (let client of this.clients) {
if (client != from) {
client.ws.send(message);

View File

@ -1,17 +1,17 @@
import ClientBase from '../../clients/clientBase';
import MHSClient from '../../clients/sites/mhsClient';
import ChannelBase from '../channelBase';
var logger = require('../../logger');
class MHSChannel extends ChannelBase {
broadcastMessage(from: ClientBase|MHSClient|null, message: any) {
broadcastMessage(from: MHSClient, message: any) {
for (let client of this.clients) {
if (client != from && client.data.user_type == 'teacher') {
if (client != from && client.data.user_type != from.data.user_type) {
console.log('sending message: ' + JSON.stringify(message))
client.ws.send(JSON.stringify(message));
logger.accessLog.info(`sent to ${client.id}`, { data: { message: message }});
} else {
logger.accessLog.info(`client either not a teacher or is the sender: ${client.id}`, { data: { message: message }});
logger.accessLog.info(`client either a ${client.data.user_type} or is the sender: ${client.id}`, { data: { message: message }});
}
}

View File

@ -36,18 +36,18 @@ class ClientBase {
return this.data.client;
}
connectToChannel(channel: ChannelBase|MHSChannel) {
connectToChannel(channel: MHSChannel) {
this.channel = channel;
var messageListener = (message: any) => {
logger.accessLog.info(`starting message transaction on channel ${channel.id}: `, {message: message});
this.ws.removeListener('message', messageListener);
message = messageManager.prepareMessage(message)
message = messageManager.prepareMessage(message);
if (!message.error) {
if (message['message_type'] == 'broadcast') {
channel.broadcastMessage(this, message);
} else if (message['message_type'] == 'changeChannel') {
this.ws.removeListener('message', messageListener);
this.channelManager.changeChannel(this, message);
}

View File

@ -8,11 +8,15 @@ let schema = {
current_index: Joi.number().integer(),
total_questions: Joi.number().integer(),
time_elapsed: Joi.number(),
time_left: Joi.any(),
status: Joi.string(),
channel: Joi.string(),
client: Joi.string(),
client_type: Joi.string(),
user_id: Joi.number().integer(),
user_exam_id: Joi.number().integer(),
user_name: Joi.string(),
exam_title: Joi.string()
};
module.exports = {