Sha256: d36d3d1aabd1426901e802dc39445a2ed8fe1fd5f123aec25281be6f3d718b1d

Contents?: true

Size: 773 Bytes

Versions: 3

Compression:

Stored size: 773 Bytes

Contents

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 # always reconnect unless stopping
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 # intercept ctrl-c
  puts "Stopping..."
  @start = false      # stop reconnecting
  es.close            # close socket
  es.wait             # wait for shutting down
  wr.puts             # unblock main thread
end

rd.gets               # main thread blocks here

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rest-firebase-1.1.0 example/daemon.rb
rest-firebase-1.0.3 example/daemon.rb
rest-firebase-1.0.2 example/daemon.rb