-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
62 lines (53 loc) · 1.52 KB
/
server.js
File metadata and controls
62 lines (53 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var http = require('http');
var sys = require('util');
var nowjs = require('now');
var fs = require('fs');
var server = http.createServer(function (req,res){
fs.readFile('./index.html', function(error, content) {
if (error) {
res.writeHead(500);
res.end();
}
else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(content, 'utf-8');
}
});
});
var everyone = nowjs.initialize(server);
var chatGroup = nowjs.getGroup("cool_kids");
nowjs.on('connect', function(){
// Username & Password
var valid = true;
if (valid) {
this.user.name = this.now.name;
chatGroup.addUser(this.user.clientId);
console.log("Joined: " + this.user.name);
}
});
//nowjs.on('disconnect', function(){
// console.log("Left: " + this.now.name);
//});
chatGroup.on('join', function() {
chatGroup.now.userJoin(this.user.name);
}
chatGroup.on('leave', function() {
var self = this;
chatGroup.now.userLeft(self.user.name);
}
chatGroup.now.distributeMessage = function(message) {
// Store in Redis
nowjs.getGroup(chatGroup).now.receiveMessage(this.user.name, message);
}
chatGroup.now.changePassword = function(oldPassword, newPassword) {
// change password
});
/*everyone.now.distributeMessage = function(message){
nowjs.getGroup(chatGroup).hasClient(this.user.clientId, function(bool) {
if(bool) { // user is valid
nowjs.getGroup(chatGroup).now.receiveMessage(this.now.name, message);
}
});
};*/
server.listen(8080);
console.log("Listening on 8080");