Skip to content

Commit 2e4076c

Browse files
quotation mark style and domain constructor fixes
1 parent 5ac08e7 commit 2e4076c

File tree

8 files changed

+45
-38
lines changed

8 files changed

+45
-38
lines changed

application/chatserver/controller/connectionController.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
Room = require("../../../domain/room.js")["Room"];
2-
User = require("../../../domain/user.js")["User"];
3-
UserCommunication = require("../../../domain/communication.js")["UserCommunication"];
4-
SystemCommunication = require("../../../domain/communication.js")["SystemCommunication"];
5-
DownloadCommunication = require("../../../domain/communication.js")["DownloadCommunication"];
1+
var Room = require('../../../domain/room.js')['Room'];
2+
var User = require('../../../domain/user.js')['User'];
3+
var UserCommunication = require('../../../domain/communication.js')['UserCommunication'];
4+
var SystemCommunication = require('../../../domain/communication.js')['SystemCommunication'];
5+
var DownloadCommunication = require('../../../domain/communication.js')['DownloadCommunication'];
66

7-
var room = new Room("default");
7+
var room = new Room('default', SystemCommunication);
88
var userId = 0;
99
var outgoingHandlers = {};
1010
var renderer = null;

application/chatserver/renderer/objectRenderer.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
var render = function(communication) {
2-
var renderedCommunication;
3-
if (communication instanceof UserCommunication) {
4-
renderedCommunication = { type: 'user', username: communication.user.name, message: communication.message };
5-
} else if (communication instanceof SystemCommunication) {
6-
renderedCommunication = { type: 'system', message: communication.message };
7-
} else if (communication instanceof DownloadCommunication) {
8-
renderedCommunication = { type: 'download', filename: communication.filename, filetype: communication.filetype, url: communication.url };
2+
var renderedCommunication = {};
3+
if (communication.type === 'user') {
4+
renderedCommunication = { type: communication.type, username: communication.user.name, message: communication.message };
5+
} else {
6+
for (field in communication) {
7+
if (communication.hasOwnProperty(field)) {
8+
renderedCommunication[field] = communication[field];
9+
}
10+
renderedCommunication.type = communication.type;
11+
}
912
}
1013

1114
return renderedCommunication;

application/client/css/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import url("/vendor/bootstrap/css/bootstrap.min.css");
1+
@import url('/vendor/bootstrap/css/bootstrap.min.css');
22

33
.navbar-inner {
44
border-radius: 0;

application/filesharing/filesharing.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
var util = require('util');
22
var fs = require('fs');
33
var mime = require('mime');
4-
var formidable = require("formidable");
4+
var formidable = require('formidable');
55

66
var handleUpload = function(request, response, inform) {
77
var form = new formidable.IncomingForm();
88
form.parse(request, function(error, fields, files) {
9-
fs.rename(files.file.path, "/tmp/bivouac_upload_" + files.file.name, function(err) {
9+
fs.rename(files.file.path, '/tmp/bivouac_upload_' + files.file.name, function(err) {
1010
inform(files.file.name, files.file.type);
1111
response.writeHead(200, {'content-type': 'text/plain'});
1212
response.end('ok');
@@ -15,16 +15,16 @@ var handleUpload = function(request, response, inform) {
1515
}
1616

1717
var handleDownload = function(filename, response) {
18-
var path = "/tmp/bivouac_upload_" + filename;
19-
fs.readFile(path, "binary", function(error, file) {
18+
var path = '/tmp/bivouac_upload_' + filename;
19+
fs.readFile(path, 'binary', function(error, file) {
2020
if(error) {
2121
response.writeHead(500, {'content-type': 'text/plain'});
22-
response.end(error + "\n");
22+
response.end(error + '\n');
2323
} else {
2424
response.writeHead(200, {
2525
'content-type': mime.lookup(path)
2626
});
27-
response.end(file, "binary");
27+
response.end(file, 'binary');
2828
}
2929
});
3030
}

application/webserver/webserver.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,42 @@ var start = function(documentRoot, handleUpload, uploadCallback, handleDownload)
99
var filename;
1010

1111
if (uriPath == '/upload' && request.method.toLowerCase() == 'post') {
12-
console.log("Handling upload...");
12+
console.log('Handling upload...');
1313
handleUpload(request, response, uploadCallback);
1414
return;
1515
}
1616

1717
if (uriPath.match(/\/download/) && request.method.toLowerCase() == 'get') {
1818
var parts = uriPath.match(/\/download\/(.*)/);
1919
filename = parts[1];
20-
console.log("Handling download of '" + filename + "'...");
20+
console.log('Handling download of "' + filename + '"...');
2121
handleDownload(filename, response);
2222
return;
2323
}
2424

2525
filename = path.join(documentRoot, uriPath);
26-
console.log(uriPath + " -> " + filename);
26+
console.log(uriPath + ' -> ' + filename);
2727

2828
path.exists(filename, function(exists) {
2929
if (!exists) {
30-
response.writeHead(404, {"Content-Type": "text/plain"});
31-
response.write("404 Not Found\n");
30+
response.writeHead(404, {'Content-Type': 'text/plain'});
31+
response.write('404 Not Found\n');
3232
response.end();
3333
return;
3434
}
3535

3636
if (fs.statSync(filename).isDirectory()) filename += '/index.html';
3737

38-
fs.readFile(filename, "binary", function(err, file) {
38+
fs.readFile(filename, 'binary', function(err, file) {
3939
if (err) {
40-
response.writeHead(500, {"Content-Type": "text/plain"});
41-
response.write(err + "\n");
40+
response.writeHead(500, {'Content-Type': 'text/plain'});
41+
response.write(err + '\n');
4242
response.end();
4343
return;
4444
}
4545

4646
response.writeHead(200);
47-
response.write(file, "binary");
47+
response.write(file, 'binary');
4848
response.end();
4949
});
5050
});

bivouac.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
(function () {
2-
var filesharing = require("./application/filesharing/filesharing.js");
3-
var webserver = require("./application/webserver/webserver.js");
4-
var chatserver = require("./application/chatserver/server/socketioserver.js");
5-
var renderer = require("./application/chatserver/renderer/objectRenderer.js");
6-
var connectionController = require("./application/chatserver/controller/connectionController.js");
2+
var filesharing = require('./application/filesharing/filesharing.js');
3+
var webserver = require('./application/webserver/webserver.js');
4+
var chatserver = require('./application/chatserver/server/socketioserver.js');
5+
var renderer = require('./application/chatserver/renderer/objectRenderer.js');
6+
var connectionController = require('./application/chatserver/controller/connectionController.js');
77

88
connectionController.attachRenderer(renderer);
99
connectionController.attachServer(chatserver);
10-
chatserver.start(webserver.start(process.cwd() + "/application/client", filesharing.handleUpload, connectionController.handleUpload, filesharing.handleDownload));
10+
chatserver.start(webserver.start(process.cwd() + '/application/client', filesharing.handleUpload, connectionController.handleUpload, filesharing.handleDownload));
1111
})();

domain/communication.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ var UserCommunication = function(user, message) {
22
this.user = user;
33
this.message = message;
44
}
5+
UserCommunication.prototype.type = 'user';
56

67
var SystemCommunication = function(message) {
78
this.message = message;
89
}
10+
SystemCommunication.prototype.type = 'system';
911

1012
var DownloadCommunication = function(filename, filetype, url) {
1113
this.filename = filename;
1214
this.filetype = filetype;
1315
this.url = url;
1416
}
17+
DownloadCommunication.prototype.type = 'download';
1518

1619
exports.UserCommunication = UserCommunication;
1720
exports.SystemCommunication = SystemCommunication;

domain/room.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
var util = require('util');
22

3-
var Room = function(name) {
3+
var Room = function(name, SystemCommunication) {
44
this.name = name;
5+
this.SystemCommunication = SystemCommunication;
56
this.users = [];
67
this.communications = [];
78
}
89

910
Room.prototype.addUser = function(user) {
10-
console.log("Entered room: " + user.name);
11+
console.log('Entered room: ' + user.name);
1112
this.users.push(user);
12-
var communication = new SystemCommunication("User " + user.name + " entered the chat.");
13+
var communication = new this.SystemCommunication('User ' + user.name + ' entered the chat.');
1314
this.addCommunication(communication);
1415
}
1516

0 commit comments

Comments
 (0)