bah, websockets

This commit is contained in:
John Bintz 2012-04-12 19:46:03 -04:00
parent e274c91c9f
commit 43d3ce1423
2 changed files with 15 additions and 3 deletions

View File

@ -4,6 +4,7 @@ Flowerbox =
Flowerbox.contact('ping')
messageQueue: []
pulling: false
contact: (url, data...) ->
Flowerbox.started = true
@ -12,16 +13,19 @@ Flowerbox =
message = [ url, data ]
Flowerbox.messageQueue.push(message)
Flowerbox.queuePuller() if Flowerbox.socket
if Flowerbox.socket && !Flowerbox.pulling
Flowerbox.queuePuller()
started: false
done: false
queuePuller: ->
Flowerbox.pulling = true
if Flowerbox.messageQueue.length > 0
message = Flowerbox.messageQueue.shift()
Flowerbox.socket.send JSON.stringify(message), {}, ->
Flowerbox.socket.onmessage = (data) ->
if message[0] == 'results'
if __$instrument?
Flowerbox.socket.send JSON.stringify(['instrument', __$instrument]) {}, ->
@ -31,6 +35,10 @@ Flowerbox =
Flowerbox.queuePuller()
Flowerbox.socket.send JSON.stringify(message)
else
setTimeout(Flowerbox.queuePuller, 10) if !Flowerbox.done
fail: ->
class Flowerbox.Exception

View File

@ -49,7 +49,11 @@ module Flowerbox
output = runner.send(command, [ data ].flatten)
ws.send(output) if command == 'load'
if command == 'load'
ws.send(output)
else
ws.send("ok")
end
}
end