Skip to content

Commit

Permalink
add a daemon example
Browse files Browse the repository at this point in the history
  • Loading branch information
godfat committed Jan 11, 2015
1 parent 24944b5 commit 30b7c33
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions example/daemon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

require 'rest-firebase'

es = RestFirebase.new(:auth => false).
event_source('https://SampleChat.firebaseIO-demo.com/')

es.onerror do |error|
puts "ERROR: #{error}"
end

es.onreconnect do
!!@start
end

es.onmessage do |event, data|
puts "EVENT: #{event}, DATA: #{data}"
end

puts "Starting..."
@start = true
es.start

rd, wr = IO.pipe

Signal.trap('INT') do
puts "Stopping..."
@start = false
es.close
es.wait
wr.puts
end

rd.gets

# Now try:
# curl -X POST -d '{"message": "Hi!"}' https://SampleChat.firebaseIO-demo.com/godfat.json

0 comments on commit 30b7c33

Please sign in to comment.