socket established + chat actualy message ui and mechanism

- need to do the mysql hookup
This commit is contained in:
Arjun Patel
2018-05-27 01:06:36 -07:00
parent 59a3bc7e7d
commit 540d83c989
5 changed files with 632 additions and 37 deletions
+33
View File
@@ -0,0 +1,33 @@
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var port = 3000;
server.listen(port, () => console.log('serving on port: ' + port));
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
var exMessages = [
{
userId: 10,
id: 1,
text: "hey anyone wanna study 61A"
},
{
userId: 1, // current user has an id of 1
id: 2, // id of message itself
text: "Yea im down"
}
];
io.on('connection', function (socket) {
console.log(socket.id);
exMessages.map((msg) => {
socket.emit('message', msg);
console.log('sending msg by msg');
});
io.on('test', () => console.log('worked~'));
});
+7
View File
@@ -0,0 +1,7 @@
<h1>Welcome</h1>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
socket.emit('test');
</script>