socket established + chat actualy message ui and mechanism
- need to do the mysql hookup
This commit is contained in:
@@ -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~'));
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
<h1>Welcome</h1>
|
||||
|
||||
<script src="/socket.io/socket.io.js"></script>
|
||||
<script>
|
||||
var socket = io();
|
||||
socket.emit('test');
|
||||
</script>
|
||||
Reference in New Issue
Block a user