Skip to content

Commit

Permalink
[RazortoothRTC#39] Reparing apps
Browse files Browse the repository at this point in the history
  • Loading branch information
chrqls committed Jun 9, 2014
1 parent 43415ff commit 29d0004
Show file tree
Hide file tree
Showing 6 changed files with 924 additions and 686 deletions.
158 changes: 92 additions & 66 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var MESSAGE_WAIT_CONNECT = {

var game = new Game();

var PRIVATE_MESSAGES = [];

exports.handleQuestionGet = function(req, res) {
var questions = game.questions.getQuestions(req.id);
if (questions instanceof Error) {
Expand Down Expand Up @@ -111,6 +113,30 @@ exports.handleDeleteIQSet = function(req, res) {
});
};

exports.postPrivateMessageForStudent = function(req, res) {

PRIVATE_MESSAGES.push(req.body);
console.log("\nPrivate message added to the stack");
console.log("%j\n", req.body);

return res.sendText(HTTP_STATUS_OK, OK);
}

exports.getPrivateMessageForStudent = function(req, res) {

var messageToForward = null;

for(var i=0; i<PRIVATE_MESSAGES.length; i++) {

if(PRIVATE_MESSAGES[i].IP === req.body.IP) {
messageToForward = PRIVATE_MESSAGES[i];
console.log('messageToForward');
console.log("%j\n", messageToForward);
PRIVATE_MESSAGES.splice(PRIVATE_MESSAGES[i], 1);
}
}
return res.sendJSON(HTTP_STATUS_OK, messageToForward);
}

/**
Save a new iqset from teacher app
Expand All @@ -123,7 +149,7 @@ exports.handlePostNewIQSet = function(req, res) {
var headers = req.headers;
var iqset;

if (headers['content-type'] === 'application/json; charset=UTF-8') {
if (headers['content-type'] === 'application/json; charset=UTF-8') {
console.log('Handle post of iqset from json');
//
// Handle the upload from JSON
Expand Down Expand Up @@ -595,7 +621,7 @@ exports.handlePushMessage = function(req, res) {
};

/**
Creating a session with teacher name, session title, and group name
Creating a session with teacher name, session title, and group name
**/
exports.createSessionFromTeacherApp = function(req, res) {

Expand Down Expand Up @@ -712,35 +738,35 @@ exports.handleQuestionHtmlGet = function(req, res) {
res.writeHead(200, {
'Content-Type' : 'text/html; charset=utf-8',
});
// Preparing values for solving questions screen
var json_solving_questions = {
questionNum: (questionNumber + 1),
author: studentName,
question: question.Q,
questionType: question.TYPE,
picturePath: '/smile/current/'+questionNumber+".jpg",
option1: question.O1,
option2: question.O2,
option3: question.O3,
option4: question.O4
};

var solving_questions = JSON.stringify(json_solving_questions);

var headers = {
'Content-Type': 'application/json',
'Content-Length': solving_questions.length
};

var options = {
host: 'localhost',
port: 80,
path: '/smile/current/'+questionNumber+'.html',
method: 'POST',
headers: headers
};
// Preparing values for solving questions screen
var json_solving_questions = {
questionNum: (questionNumber + 1),
author: studentName,
question: question.Q,
questionType: question.TYPE,
picturePath: '/smile/current/'+questionNumber+".jpg",
option1: question.O1,
option2: question.O2,
option3: question.O3,
option4: question.O4
};

var solving_questions = JSON.stringify(json_solving_questions);

var headers = {
'Content-Type': 'application/json',
'Content-Length': solving_questions.length
};

var options = {
host: 'localhost',
port: 80,
path: '/smile/current/'+questionNumber+'.html',
method: 'POST',
headers: headers
};
// Setup the request. The options parameter is the object defined above.
var http = require('http');
req = http.request(options, function(res) {
Expand Down Expand Up @@ -850,40 +876,40 @@ exports.handleQuestionResultHtmlGet = function(req, res) {
res.writeHead(200, {
'Content-Type' : 'text/html; charset=utf-8',
});
// Preparing values for detailresult.xml
var detail_result = {
questionNum: (questionNumber + 1),
author: studentName,
question: question.Q,
questionType: question.TYPE,
picturePath: '/smile/current/'+questionNumber+".jpg",
answer: question.A,
option1: question.O1,
option2: question.O2,
option3: question.O3,
option4: question.O4,
numCorrectPeople: game.questionCorrectCountMap[questionNumber],
numberOfStudents: game.students.getNumberOfStudents(),
averageRating: game.getQuestionAverageRating(questionNumber)
};

var detail_resultString = JSON.stringify(detail_result);

var headers = {
'Content-Type': 'application/json',
'Content-Length': detail_resultString.length
};

var options = {
host: 'localhost',
port: 80,
path: '/smile/current/'+questionNumber+'_result.html',
method: 'POST',
headers: headers
};
// Preparing values for detailresult.xml
var detail_result = {
questionNum: (questionNumber + 1),
author: studentName,
question: question.Q,
questionType: question.TYPE,
picturePath: '/smile/current/'+questionNumber+".jpg",
answer: question.A,
option1: question.O1,
option2: question.O2,
option3: question.O3,
option4: question.O4,
numCorrectPeople: game.questionCorrectCountMap[questionNumber],
numberOfStudents: game.students.getNumberOfStudents(),
averageRating: game.getQuestionAverageRating(questionNumber)
};

var detail_resultString = JSON.stringify(detail_result);

var headers = {
'Content-Type': 'application/json',
'Content-Length': detail_resultString.length
};

var options = {
host: 'localhost',
port: 80,
path: '/smile/current/'+questionNumber+'_result.html',
method: 'POST',
headers: headers
};
// Setup the request. The options parameter is the object defined above.
var http = require('http');
req = http.request(options, function(res) {
Expand All @@ -906,7 +932,7 @@ req.on('error', function(e) {

// XXX What is this for??
console.log('JSON request ==> '+detail_resultString);
res.write(detail_resultString);
res.write(detail_resultString);
res.end();
};

Expand Down
10 changes: 10 additions & 0 deletions smileplug.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ js.get('/smile/iqset/:id', routes.handleGetIQSet, true);
@method /smile/iqset
**/

/**
Add a private message to the stack for a specific student.
It has NOTHING TO DO with 'messages' added to /smile/all
**/
js.post('/smile/talk/teacher/post', routes.postPrivateMessageForStudent);
js.post('/smile/talk/student/get', routes.getPrivateMessageForStudent);
/* To send messages to the teacher, uncomment the 2 lines and implement it in index.js:
js.post('/smile/talk/teacher/get', routes.listenIfPrivateMessageForTeacher);
js.post('/smile/talk/student/post', routes.addPrivateMessageForTeacher);*/

/**
Save a new iqset from teacher app
**/
Expand Down
Loading

0 comments on commit 29d0004

Please sign in to comment.