-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (62 loc) · 1.6 KB
/
index.js
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
62
63
64
65
66
67
68
69
70
71
72
73
const express=require('express');
const app=express();
const http=require('http').Server(app);
const io=require('socket.io')(http, { wsEngine: 'ws' });
const path=require('path');
const knex=require('./config/knex');
app.use(express.static('static'))
app.get('/',function(req,res){
res.sendFile(path.join(__dirname + '/public/index.html'));
})
app.get('/doctor',function(req,res){
res.sendFile(path.join(__dirname + '/public/doctor2.html'));
})
app.get('/patient',function(req,res){
res.sendFile(path.join(__dirname + '/public/patient2.html'));
})
io.on('connection',function(socket){
console.log('socket connection established!');
//For normal chatting (Enable DB Support here: Use knex.js)
socket.on('new-message',function(msg){
io.emit('receive-msg',msg);
knex('chat').insert({
username:msg.username,
text:msg.text,
})
.then(function(rows){
console.log(rows);
})
.catch(function(err){
console.error(err);
})
})
//For Patient's form submission
socket.on('patient-data',function(msg){
//Emit this info to the doctor
io.emit('patient-to-doctor',msg);
f=(msg.fever) ? 1: 0;
n=(msg.nausea) ? 1: 0;
c=(msg.cough) ? 1: 0;
//Insertion into `patient_data` table in database
knex('patient_data').insert({
name:msg.name,
age:msg.age,
fever:f,
nausea:n,
cough:c
},'id')
.then(function(row){
console.log(row);
})
.catch(function(err){
console.error(err);
})
})
//For starting of chat by Doctor's permission
socket.on('start-chat',function(msg){
io.emit('start-chat',msg);
})
})
http.listen(4000,function(){
console.log('Connected at Port 4000');
})