Skip to content

Commit

Permalink
swaths of code
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Dahan committed Aug 8, 2011
1 parent 3ce6f2f commit 57e358e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/faker.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ startFakingData = (swarm_id) ->
swarm: swarm_id
timer: fakeTimer swarm_id
stream: request.put
uri: "http://#{host}/resources/#{resource.name}/feeds/location?swarm_id=#{swarm_id}"
uri: "http://#{host}/resources/#{resource.user_id}/feeds/location?swarm_id=#{swarm_id}"
headers: header
(error, response, body) ->
console.error " #{error}" if error?
Expand Down
47 changes: 23 additions & 24 deletions src/map.jade
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ html
buglabs = { lat: 40.72498216901785, lon: -73.99708271026611 }
console.log 'creating socketio server'
console.log 'connecting to swarm'
try
socket = io.connect 'http://107.20.250.52'
Expand All @@ -39,47 +39,46 @@ html
socket.on 'connect', ->
socket.emit 'apikey', 'eae9f2188a375c4635138928b93c4b9f97d30803'
console.log 'connected'
# on any message
# check that the swarm exists, if not, add it to the dom
# check that the resource exists in that swarm, if not add it to the dom
# set the correct class for that resource to show presence
# update the location and mpg
socket.on 'message', (message) ->
console.log message
data = JSON.parse message.message
console.log "data: #{JSON.stringify data}"
if message.presence?
swarm = message.presence.from?.split('@')[0]
dom_swarm = $ "##{swarm}" || $("#swarms").append "<ul id=#{swarm} class='swarm'>#{swarm}</ul>"
console.log "swarm: #{swarm}, dom_swarm: #{dom_swarm}"
if data.body?
resource = message.from?.split('/')[1].split('-')[1]
alive = message.body?.type is 'available '
location = data.body
console.log "message from #{alive} #{resource} in swarm #{swarm}:"
console.log " #{location}"
swarm = ""
dom_swarm = ""
if message?.presence?
swarm = message.presence.from.split('@')[0]
dom_swarm = $("##{swarm}")[0] || $("#swarms").append "<ul id=#{swarm} class='swarm'>#{swarm}</ul>"
else
resource = message.message.from?.split('/')[1]
if resource?
data = message.message.body
dom_resource = $("##{resource}") || $("##{swarm}").append "<li id=#{resource}>#{resource} (#{data.mpg} mpg)</li>"
dom_resource.attr class: (alive? 'alive': 'dead')
# add the elements to the dom if not found and keep up to date
dom_resource = $ "##{resource}" || $("##{swarm}").append "<li id=#{resource}>#{resource} (#{data.mpg} mpg)</li>"
alive = data.body?.type is 'groupchat'
location = data.body
dom_resource.attr class: (alive? 'alive': 'dead')
console.log "#{alive} #{resource} @ #{swarm}: #{data}"
updateResource dom_resource, data
updateResource dom_resource, data
socket.on 'connected to backend', ->
console.log 'connected'
socket.emit 'message', { presence: { to: "#{swarms[0]}@swarms.bugswarm.net/web" } }
console.log 'connected to backend'
console.log 'creating map centered around BUG Labs'
console.log "rendering map"
mapOptions = zoom: 12, center: new google.maps.LatLng(buglabs.lat, buglabs.lon) , mapTypeId: google.maps.MapTypeId.ROADMAP
mapCanvas = document.getElementById "map_canvas"
mapGoogle = new google.maps.Map mapCanvas, mapOptions
markers = []
updateResource = (dom_resource, data) ->
console.log "updating #{JSON.stringify dom_resource[0]} with #{data}"
marker = new google.maps.Marker
position: new google.maps.LatLng data.latitude, data.longitude
icon: "http://robohash.org/#{data.id}.png?size=40x40&set=set3"
Expand All @@ -89,9 +88,9 @@ html
# if you click on a resource, highlight it in the list!
google.maps.event.addListener marker, 'click', () ->
console.log "time to highlight #{dom_resource}"
dom_resource.parent.expand
dom_resource.highlight
alert "time to highlight"
#dom_resource.parent.expand
#dom_resource.highlight
markers.push marker
Expand Down

0 comments on commit 57e358e

Please sign in to comment.