Sha256: 858fcff9e6cb8b0eca28fdde8dc8b0edcec2c95e4b148f9a1013109d4f26f775

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

module WebsocketRails
  class InternalEvents
    def self.events
      Proc.new do
        namespace :websocket_rails do
          subscribe :pong, :to => InternalController, :with_method => :do_pong
          subscribe :reload!, :to => InternalController, :with_method => :reload_controllers!
          subscribe :subscribe, :to => InternalController, :with_method => :subscribe_to_channel
        end
      end
    end
  end

  class InternalController < BaseController
    include Logging

    def subscribe_to_channel
      channel_name = event.data[:channel]
      unless WebsocketRails[channel_name].is_private?
        WebsocketRails[channel_name].subscribe connection
        trigger_success
      else
        trigger_failure( { :reason => "channel is private", :hint => "use subscibe_private instead." } )
      end
    end

    def reload_controllers!
      return unless defined?(Rails) and Rails.env.development? || Rails.env.test?
      log 'reloading controllers'
      @_dispatcher.reload_controllers!
    end

    def do_pong
      connection.pong = true
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
websocket-rails-0.3.0 lib/websocket_rails/internal_events.rb
websocket-rails-0.2.1 lib/websocket_rails/internal_events.rb
websocket-rails-0.2.0 lib/websocket_rails/internal_events.rb
websocket-rails-0.1.9 lib/websocket_rails/internal_events.rb
websocket-rails-0.1.8 lib/websocket_rails/internal_events.rb
websocket-rails-0.1.7 lib/websocket_rails/internal_events.rb
websocket-rails-0.1.6 lib/websocket_rails/internal_events.rb