Permalink
Browse files

make faker close the connection on exit

  • Loading branch information...
1 parent b2f1936 commit 9317125b997bbc6b412a3ea6135408142b6f8d52 @jedahan jedahan committed Sep 9, 2011
Showing with 16 additions and 17 deletions.
  1. +4 −4 src/faker.coffee
  2. +12 −13 src/public/scripts/lepidoptera.coffee
View
@@ -74,16 +74,16 @@ fakeData = (feed_name="mpg", swarm_id=config.swarms[Math.floor(Math.random() * c
req.write '\n'
reqs.push req
-process.on 'SIGTERM', () ->
+process.on 'SIGTERM', ->
process.exit 1
-process.on 'SIGINT', () ->
+process.on 'SIGINT', ->
process.exit 1
-process.on 'exit', () ->
+process.on 'exit', ->
console.log 'sending presence unavailable'
for req in reqs
- req.write JSON.stringify presence: {type:"unavailable"}
+ req.end
fakeData()
app.listen 33
@@ -16,34 +16,33 @@ lepidoptera = ->
markers = []
# the javascript api handles message callbacks as a consumer only
- SWARM.join apikey: "#{config.consumer_key}", swarms: config.swarms, callback: (message) ->
- from = message.presence?.from or message.message?.from
+ SWARM.join apikey: "#{config.consumer_key}", swarms: config.swarms, callback: (stanza) ->
+ from = stanza.presence?.from or stanza.message?.from
resource_id = from?.split('/')[1]
if resource_id?.indexOf('web') is -1
if resource_id?.indexOf('browser') is -1
# for _messages_, update the readout
- if message.message?.body?
- if JSON.parse(message.message.body.data).presence is 'unavailable'
- $("##{resource_id}").toggleClass 'alive', false
- else
- try
- updateFeed resource_id, message.message.body
- catch err
- console.error "#{message.message.body}"
+ if stanza.message?.body?
+ try
+ updateFeed resource_id, stanza.message.body
+ catch err
+ console.error "#{stanza.message.body}"
# for _presence_, determine if a resource just joined or just left
- if message.presence?.type?
- updatePresence resource_id, message.presence.type is 'available'
+ if stanza.presence?.type?
+ updatePresence resource_id, stanza.presence.type is 'available'
updatePresence = (resource_id, alive) ->
console.log "updatePresence(#{resource_id}, #{alive})"
# if the resource doesn't exist, add it
dom_resource = $("#resources > ##{resource_id}")
- if alive and not dom_resource[0]?
+ if not dom_resource[0]?
dom_resource = $("#resources").append("<li class='resource alive' id='#{resource_id}'><h1 class='car_icon_wrapper'><span class='car_icon'>Car Icon</span></h1><span class='car_name'></span><ul class='feeds'></ul></li>")
+ dom_resource.toggleClass 'alive', alive
+
updateFeed = (resource_id, body) ->
feed = body.feed
data = JSON.parse body.data

0 comments on commit 9317125

Please sign in to comment.