Sha256: cc4b6b4a1e6d71879af707fe3bc44974fef5bbedc9f79d03f9ed5c946d65641d

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module Sinatra
  module RocketIO

    def self.push(type, data, opt={})
      if options[:websocket]
        if !opt[:to] or Sinatra::WebSocketIO.sessions.include? opt[:to]
          Sinatra::WebSocketIO.push type, data, opt
        end
      end
      if options[:comet]
        if !opt[:to] or Sinatra::CometIO.sessions.include? opt[:to]
          Sinatra::CometIO.push type, data, opt
        end
      end
    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

1 entries across 1 versions & 1 rubygems

Version Path
sinatra-rocketio-0.0.7 lib/sinatra-rocketio/rocketio.rb