-
-
Save dekzok/8c1d18a14763c0f372a3d667192f76cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('express')(); | |
var http = require('http').Server(app); | |
var io = require('socket.io')(http); | |
var os = require('os'); | |
var html_dir = '/html+css/'; | |
var router = require('express').Router(); | |
//this does not work | |
router.use(function(req, res, next) { | |
res.sendFile(__dirname + html_dir + 'desktop.html'); | |
console.log('res sendfile'); | |
console.log('%s %s %s', req.method, req.url, req.path); | |
next(); | |
}); | |
//this does not work either | |
router.use('/',function(req, res,next) { | |
res.sendFile(__dirname + html_dir + 'desktop.html'); | |
console.log('res sendfile'); | |
next(); | |
}); | |
//however, 'http 37098 running' gets clogged. | |
http.listen(37098, function(){ | |
console.log('http 37098 running'); | |
console.log(html_dir); | |
console.log(__dirname); | |
}); | |
//this does not work | |
app.use('/',function(req, res,next) { | |
res.sendFile(require('path').resolve(html_dir + 'desktop.html')); | |
console.log('res sendfile'); | |
next(); | |
}); | |
//this does not work | |
app.get('/', function(req, res) { | |
console.log("es"); | |
res.sendFile(require('path').resolve(html_dir + 'desktop.html')); | |
}); | |
//i havent even tried the lines after this | |
app.get('/phone', function(req, res) { | |
res.sendfile(html_dir + 'phone.html'); | |
}); | |
app.get('/back.png', function(req, res) { | |
res.sendfile(html_dir + 'back.png'); | |
}); | |
/*app.get("/", app.authenticateUser, function (req, res) { | |
res.redirect(html_dir + 'phone.html'); | |
}); | |
res.set({ 'content-type': 'application/json; charset=utf-8' })*/ | |
app.use( function(req, res, next) { | |
// this line of code will see that the | |
// request is for "/" and fire | |
if (req.url == '/') { | |
// the page now appears to render, because you are forcing the | |
// res.render code inside of your middleware, which isn't always | |
// recommended, but it is working for you in this example | |
// because its the only place in your example that can do anything | |
// when the '/' request is made | |
//res.sendfile(html_dir + 'desktop.html'); | |
console.log('res sendfile'); | |
} else { | |
// this is common middleware design pattern, the next() | |
// function tells the express framework to "move on to the next function" | |
// in the middleware stack | |
console.log('a'); | |
next(); | |
} | |
}); | |
var bedrijfsnamen = []; | |
var clients = []; | |
var socketids = []; | |
var bedrijven = []; | |
var ontvanger = []; | |
var userss = []; | |
io.on('connection', function(socket){ | |
socket.on('chat', function(msg,k,recipient){ | |
var h = []; | |
if(arguments[0].afz==false||arguments[0].afz==true){h.push(JSON.parse(JSON.stringify(arguments[0])))} | |
if(arguments[1].afz==false||arguments[1].afz==true){h.push(JSON.parse(JSON.stringify(arguments[1])))} | |
if(arguments[2]!=undefined){ | |
if(arguments[2].afz==false||arguments[2].afz==true){h.push(JSON.parse(JSON.stringify(arguments[2])))}} | |
var kk = h[0]; | |
setTimeout(function(){ | |
if(kk.afz===false) { | |
console.log(kk); | |
//wordt verzonden naar bedrijf | |
console.log('NAAR BEDRIJF'); | |
var a = bedrijven.filter(function(e){ | |
return recipient.bedrijfsnaam ==e.bedrijfsnaam; | |
}); | |
if(a){var b0 = a[0];} | |
var o=[]; | |
if(a!=null&&a!=0&&a!=undefined&&a.length!=0){ | |
var b = userss.filter(function(e){ | |
return e.mail ==kk.mail; | |
}); | |
if(userss.indexOf(b[0])==-1){console.log('return false;');return false;}else{ | |
kk.index=userss.indexOf(b[0]);} | |
if(userss[kk.index].chats.length==0){ | |
var uchat = new Object; | |
q(uchat); | |
} else{ | |
var zid=userss[kk.index].chats.filter(function(e){ | |
return e.name==recipient.bedrijfsnaam && e.vac==k.vacatures; | |
}); | |
if(zid!=null&&zid!=0&&zid!=undefined&&zid.length!=0){ | |
var inde = userss[kk.index].chats.indexOf(zid[0]); | |
var mm = new Object; | |
mm.afz = 's'; | |
mm.content = msg; | |
userss[kk.index].chats[inde].msgs.push(mm); | |
console.log(userss[kk.index].chats[inde],'userss[kk.index].chats[inde]'); | |
userss[kk.index].chats[inde].vac=kk.vacatures; | |
console.log(kk); | |
var ei = userss[kk.index]; | |
console.log(userss[kk.index]); | |
io.to(userss[kk.index].id).emit('chat message', msg,ei,recipient); | |
} else { | |
var uchat = new Object; | |
q(uchat); | |
console.log(',zidwasonvindbaar'); | |
} | |
} | |
function q(uchat){ | |
if(!uchat.name){ | |
uchat.name=recipient.bedrijfsnaam; | |
} | |
if(!uchat.msgs){ | |
uchat.msgs=new Array; | |
} | |
uchat.vac = kk.vacatures; | |
var mm = new Object; | |
mm.afz = 's'; | |
mm.content = msg; | |
uchat.msgs.push(mm); | |
userss[kk.index].chats.push(uchat); | |
var ei = userss[kk.index]; | |
console.log(userss[kk.index]); | |
io.to(userss[kk.index].id).emit('chat message', msg,ei,recipient); | |
console.log('CHAT MESSAGE SenT TO USER'); | |
} | |
for(i=0;i<b0.vacatures.length;i++){ | |
if(b0.vacatures[i].name==kk.vacatures){ | |
if(b0.vacatures[i].chats.length!=0){ | |
for(ii=0;ii<b0.vacatures[i].chats.length;ii++){ | |
if(b0.vacatures[i].chats[ii].k==kk.index){ | |
var chat = b0.vacatures[i].chats[ii]; | |
console.log('tha case'); | |
var mm = new Object; | |
mm.afz = 's'; | |
mm.content = msg; | |
chat.msgs.push(mm); | |
} else{ | |
var chat = new Object; | |
y(chat); | |
} | |
} | |
} else { | |
var chat = new Object; | |
y(chat); | |
} | |
function y(chat){ | |
chat.k = kk.index; | |
var u = Math.random();var u = u*10000;var u = Math.round(u); | |
chat.name = u; | |
chat.msgs =[]; | |
var mm = new Object; | |
mm.afz = 's'; | |
mm.content = msg; | |
chat.msgs.push(mm); | |
b0.vacatures[i].chats.push(chat); | |
console.log(chat); | |
console.log(b0.vacatures[i].chats); | |
console.log(chat.msgs); | |
} | |
if(o.length!=0){o.length=0} | |
o.push(b0); | |
} | |
} | |
var j = o[0]; | |
setTimeout(function(){delete kk.mail;io.to(a[0].id).emit('chat message', msg, kk,j);},40); | |
} | |
} else{ | |
//gaat naar sollicitant | |
console.log('NAAR SOLLICITANT'); | |
var b = bedrijven.filter(function(e){ | |
return e.bedrijfsnaam==kk.bedrijfsnaam; | |
}); | |
var bi =bedrijven.indexOf(b[0]); | |
var c = b[0].vacatures.filter(function(e){ | |
return e.name ==kk.vacature; | |
}); | |
var vi = bedrijven[bi].vacatures.indexOf(c[0]); | |
var d = bedrijven[bi].vacatures[vi].chats.filter(function(e){ | |
return e.k==kk.ai; | |
}); | |
var di = bedrijven[bi].vacatures[vi].chats.indexOf(d[0]); | |
var mm = new Object; | |
mm.afz = 'b'; | |
mm.content = msg; | |
bedrijven[bi].vacatures[vi].chats[di].msgs.push(mm); | |
setTimeout(function(){ | |
io.to(bedrijven[bi].id).emit('chat message', msg, kk); | |
},4000); | |
userss[kk.ai].chats.forEach(function(e){ | |
if(e.name==bedrijven[bi].bedrijfsnaam){ | |
var h=new Object; | |
h.afz='b'; | |
h.content=msg; | |
e.msgs.push(h); | |
var ei = userss[kk.ai]; | |
io.to(userss[kk.ai].id).emit('chat message', msg,ei); | |
} | |
}) | |
} | |
},50); | |
}); | |
socket.on('loginb',function(login){ | |
var a = bedrijven.filter(function (e) { | |
return e.bedrijfsnaam == login.bnaam && e.pwd==login.pwd; | |
}); | |
var b = a[0]; | |
if(a==null){socket.emit('loginb',false)} else {socket.emit('loginb',b)} | |
}); | |
socket.on('updateID', function(data){ | |
var a = userss.filter(function(e){ | |
return e.mail == data.mail; | |
}); | |
if(a!=null&&a!=0&&a!=undefined&&a.length!=0){ | |
if(userss.indexOf(a[0])==-1){return false;}else{ | |
userss[userss.indexOf(a[0])].id = data.id; | |
} | |
} | |
setTimeout(function(){ | |
console.log('ai',ai); | |
socket.emit('bedrijven', ai); | |
},400); | |
}); | |
socket.on('update', function(bedrijf) { | |
var a = bedrijven.filter(function(e){ | |
return bedrijf.bedrijfsnaam ==e.bedrijfsnaam; | |
}); | |
if(a!=null&&a!=0&&a!=undefined&&a.length!=0){ | |
var index = bedrijven.indexOf(a[0]); | |
bedrijven[index].id = bedrijf.id | |
bedrijven[index].sollicitatievragen=bedrijf.sollicitatievragen; | |
socket.emit('update',bedrijven[index]); | |
} else {return false;} | |
}); | |
socket.on('newUser', function(data){ | |
var a = userss.filter(function(e){ | |
return e.mail == data.mail; | |
}); | |
if(a!=null&&a!=0&&a!=undefined&&a.length!=0){ | |
return false; | |
} else{ | |
data.chats=new Array; | |
userss.push(data); | |
} | |
console.log(userss); | |
}); | |
socket.on('email', function(data){ | |
var a = userss.filter(function(e){ | |
return e.mail == data; | |
}); | |
//if(a!=null&&a!=0&&a!=undefined&&a.length!=0){ | |
//} | |
if(a==undefined||a.length==0||a==null||a==0){socket.emit('email',null)}else{socket.emit('email',a[0].mail)} | |
}); | |
socket.on('login', function(data){ | |
console.log(data); | |
var a = userss.filter(function(e){ | |
return e.mail == data.mail && e.pwd == data.pwd; | |
}); | |
var b= a[0]; | |
if(a==null){socket.emit('login', 0)} else{ | |
socket.emit('login', b); | |
} | |
}); | |
socket.on('bedrijfobj', function(data){ | |
console.log(bedrijven); | |
var bedrijf ={}; | |
bedrijf.bedrijfsnaam = data.bedrijfsnaam; | |
bedrijf.vacatures = data.vacatures; | |
bedrijf.id=socket.id; | |
bedrijf.pwd=data.pwd; | |
bedrijf.bedrijfscultuur=data.bedrijfscultuur; | |
if(bedrijfsnamen.indexOf(data.bedrijfsnaam)==-1){ | |
bedrijfsnamen.push(bedrijf.bedrijfsnaam); | |
bedrijven.push(bedrijf); | |
console.log(bedrijven); | |
console.log(bedrijf.vacatures); | |
socket.emit('bedrijf', bedrijf); | |
setTimeout(function(){socket.broadcast.emit('bedrijven', ai); | |
console.log(bedrijven,ai,kopie);},400); | |
} else{ | |
socket.emit('alr', 'alr'); | |
} | |
}); | |
var kopie = JSON.parse(JSON.stringify(bedrijven)); | |
var ai = b(kopie); | |
function b(kopie){ | |
kopie.forEach(func); | |
function func(e) { | |
for(i = 0; i < e.vacatures.length; i++){ | |
if(e.vacatures[i].name){ | |
e.vacatures[i]=e.vacatures[i].name | |
} | |
} | |
delete e.pwd; | |
} | |
console.log(kopie); | |
return kopie; | |
} | |
// socket.on('phone', function(data){ | |
// socket.emit('stuurbedrijfsnaam', 'stuurbedrijfsnaam'); | |
// socket.on('connection', function(socket){ | |
// } | |
// ); | |
//}); | |
io.sockets.on('connect', function(socket) { | |
var sessionid = socket.id; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
look at the first few lines to see the problem