bah, websockets
This commit is contained in:
parent
e274c91c9f
commit
43d3ce1423
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user