Skip to content

Commit

Permalink
Re-written in coffee-script
Browse files Browse the repository at this point in the history
  • Loading branch information
scarvell committed Apr 15, 2012
1 parent 5e04ed1 commit fdd8987
Show file tree
Hide file tree
Showing 598 changed files with 237,179 additions and 687 deletions.
13 changes: 13 additions & 0 deletions README.md
@@ -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');
73 changes: 73 additions & 0 deletions app.coffee
@@ -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
1 change: 1 addition & 0 deletions node_modules/.bin/uglifyjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions node_modules/socket.io/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

160 changes: 160 additions & 0 deletions node_modules/socket.io/History.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions node_modules/socket.io/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions node_modules/socket.io/Readme.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdd8987

Please sign in to comment.