Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
598 changed files
with
237,179 additions
and
687 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Mouse Tracker | ||
A nodejs socket mouse tracking application | ||
|
||
Installation | ||
|
||
Make sure you have the latest node and npm installed. To run: | ||
node app.js | ||
|
||
You can install any missing dependencies with: | ||
npm install -d | ||
|
||
Modify line 25 in views/layout.jade to point to the correct IP if you're testing with multiple computers: | ||
var socket = io.connect('http://10.0.1.11:3000'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
express = require 'express' | ||
io = require 'socket.io' | ||
app = module.exports = express.createServer(); | ||
|
||
io = io.listen app | ||
|
||
## Configuration | ||
io.set 'log level', 1 # Turn off annoying poll notice | ||
|
||
app.configure () -> | ||
app.set 'views', __dirname + '/views' | ||
app.set 'view engine', 'jade' | ||
app.use express.bodyParser() | ||
app.use express.methodOverride() | ||
app.use app.router | ||
app.use express.static(__dirname + '/public') | ||
|
||
app.configure 'development', () -> | ||
app.use express.errorHandler({ dumpExceptions: true, showStack: true }) | ||
|
||
app.configure 'production', () -> | ||
app.use express.errorHandler() | ||
|
||
app.get '/', (req, res) -> | ||
res.render 'index', { title: 'Node.JS Sockets'} | ||
|
||
app.listen 3000 | ||
|
||
##Player information | ||
m_players = []; | ||
i = 0 # Used for how many people are connected | ||
|
||
io.sockets.on 'connection', (socket) -> | ||
console.log "New connection: #{socket}" | ||
|
||
socket.on 'client_connected', (data) -> | ||
data.id = socket.id | ||
m_players[i] = data | ||
i++ | ||
io.sockets.emit "send_data", m_players | ||
|
||
socket.on 'update_coords', (pos) -> | ||
|
||
for x in [0..m_players.length] | ||
if m_players[x].id == socket.id | ||
m_players[x].x = pos.x; | ||
m_players[x].y = pos.y; | ||
|
||
console.log "Client: #{socket.id}" | ||
console.log "X: #{pos.x}, Y: #{pos.y}" | ||
break | ||
|
||
io.sockets.emit("send_data", m_players); | ||
|
||
socket.on 'disconnect', () -> | ||
j = 0 | ||
n = 0 | ||
tmp = [] | ||
|
||
while n < m_players.length | ||
if m_players[j].id == socket.id | ||
n++ | ||
break | ||
|
||
if n < m_players.length | ||
tmp[j] = m_players[n] | ||
j++ | ||
n++ | ||
break | ||
|
||
m_players = tmp; | ||
i = j; | ||
io.sockets.emit 'send_data', m_players |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.