You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
var http = require('http');
|
|
|
|
var fs = require('fs');
|
|
|
|
var express = require('express');
|
|
|
|
var app = express();
|
|
|
|
var path = require('path');
|
|
|
|
|
|
|
|
var server = http.createServer(app);
|
|
|
|
var port = 8000;
|
|
|
|
|
|
|
|
var io = require('socket.io')(server);
|
|
|
|
|
|
|
|
io.on('connection', function(socket) {
|
|
|
|
console.log('Node.js is listening!!');
|
|
|
|
|
|
|
|
socket.on("hello", (arg, callback) => {
|
|
|
|
console.log("hellohelo"); // "world"
|
|
|
|
io.emit('blink');
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('chat message', (msg) => {
|
|
|
|
console.log('[user][' + socket.id + '][' + msg + ']');
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('userposition', (msg) => {
|
|
|
|
console.log('[user][' + socket.id + '][position: ' + msg[0] + ',' + msg[1] + ']');
|
|
|
|
socket.to('expo').emit(socket.id, msg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
server.listen(port, () => {
|
|
|
|
console.log("Server is listening at port %d", port);
|
|
|
|
});
|
|
|
|
|
|
|
|
app.use(express.static(path.join(__dirname, "public")));
|