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

View File

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