Sha256: 190e51160599327e4040cef4a1231879f537655da5d08bbd64b17eb328286c9d

Contents?: true

Size: 981 Bytes

Versions: 5

Compression:

Stored size: 981 Bytes

Contents

module Sinatra
  module RocketIO

    def self.push(type, data, opt={})
      Sinatra::CometIO.push type, data, opt if options[:comet]
      Sinatra::WebSocketIO.push type, data, opt if options[:websocket]
    end

    def self.sessions
      {
        :websocket => Sinatra::WebSocketIO.sessions,
        :comet => Sinatra::CometIO.sessions
      }
    end

  end
end

EventEmitter.apply Sinatra::RocketIO

Sinatra::RocketIO.once :regist_events do
  if options[:comet]
    Sinatra::CometIO.on :* do |event_name, *args|
      if args.size > 1
        Sinatra::RocketIO.emit event_name, args[0], args[1], :comet
      else
        Sinatra::RocketIO.emit event_name, args[0], :comet
      end
    end
  end
  if options[:websocket]
    Sinatra::WebSocketIO.on :* do |event_name, *args|
      if args.size > 1
        Sinatra::RocketIO.emit event_name, args[0], args[1], :websocket
      else
        Sinatra::RocketIO.emit event_name, args[0], :websocket
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sinatra-rocketio-0.0.6 lib/sinatra-rocketio/rocketio.rb
sinatra-rocketio-0.0.5 lib/sinatra-rocketio/rocketio.rb
sinatra-rocketio-0.0.4 lib/sinatra-rocketio/rocketio.rb
sinatra-rocketio-0.0.3 lib/sinatra-rocketio/rocketio.rb
sinatra-rocketio-0.0.2 lib/sinatra-rocketio/rocketio.rb