Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/lericson/geoface
Browse files Browse the repository at this point in the history
Conflicts:
	client/src/app.coffee
  • Loading branch information
jnordberg committed Mar 8, 2012
2 parents 0124ed9 + 673eb57 commit f0b50f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
34 changes: 19 additions & 15 deletions server/server.coffee
Expand Up @@ -18,19 +18,22 @@ server.listen 8080
wait = new waitlist.Waitlist

[
{uid: "516251607", point: [59.33630, 18.02872]},
{uid: "123123", point: [59.31090, 18.08367]},
{uid: "123124", point: [59.312569, 18.09267]},
{uid: "123125", point: [65.640457, 22.012873]}]
{id: "516251607", point: [59.33630, 18.02872]},
{id: "123123", point: [59.31090, 18.08367]},
{id: "123124", point: [59.312569, 18.09267]},
{id: "123125", point: [65.640457, 22.012873]}]

clients = {}

new_client = (socket) ->

clients[socket.id] = {id: socket.id, socket: socket}

socket.on 'hello', (info) ->

user = uid: info.user.id, point: [info.location.coords.latitude, info.location.coords.longitude]
clients[user.uid] = client = {user: user, info: info, socket: socket}
user = id: socket.id, point: [info.location.coords.latitude, info.location.coords.longitude]
client = clients[socket.id]
client.info = info

wait.search user, (mate) ->
console.log('blah')
Expand All @@ -40,19 +43,20 @@ new_client = (socket) ->
wait.add user

else
console.log('do it')
console.log user, mate
mate = clients[mate.id]
console.log('do it', client.id, mate.id)
client.mate = mate
mate.mate = mate
client.socket.emit 'knock', clients[mate.uid].info
clients[mate.uid].socket.emit info
mate.mate = client
client.socket.emit 'knock', {id: mate.id, info: mate.info}
mate.socket.emit 'knock', {id: client.id, info: client.info}

socket.on 'privmsg', (uid, msg) ->
recipient = clients[uid]
recipient.socket.emit('privmsg', uid, msg)
socket.on 'privmsg', (id, msg) ->
console.log(id, msg)
recipient = clients[id]
recipient.socket.emit('privmsg', id, msg)

#socket.on 'message', (args...) ->
# console.log 'client said', args.join ', '
# user = uid: "666", point: [55, 18]
# user = id: "666", point: [55, 18]

sio.sockets.on 'connection', new_client
6 changes: 3 additions & 3 deletions server/waitlist.coffee
Expand Up @@ -31,16 +31,16 @@ class Waitlist
constructor: (users = []) ->
@_users = []
for user in users
@_users[user.uid] = user
@_users[user.id] = user

add: (user) ->
@_users[user.uid] = user
@_users[user.id] = user

search: (user, callback) ->
score = (other, callback) -> callback null, distance(user.point, other.point)
async.sortBy (@_users[u] for u of @_users), score, (err, results) =>
for user in results
delete @_users[user.uid]
delete @_users[user.id]
return callback user
return callback null

Expand Down

0 comments on commit f0b50f0

Please sign in to comment.