Sha256: 5de156039710826b7c04df5125189e39ce2749996c5d09b0601eddfd6ab9ca27

Contents?: true

Size: 1.09 KB

Versions: 21

Compression:

Stored size: 1.09 KB

Contents

module ApplicationCable
  class Channel < ActionCable::Channel::Base; end
  class Connection < ActionCable::Connection::Base; end
end

module Hyperloop
  class ActionCableChannel < ApplicationCable::Channel
    class << self
      def subscriptions
        @subscriptions ||= Hash.new { |h, k| h[k] = 0 }
      end
    end

    def inc_subscription
      self.class.subscriptions[params[:hyperloop_channel]] =
        self.class.subscriptions[params[:hyperloop_channel]] + 1
    end

    def dec_subscription
      self.class.subscriptions[params[:hyperloop_channel]] =
        self.class.subscriptions[params[:hyperloop_channel]] - 1
    end

    def subscribed
      session_id = params["client_id"]
      authorization = Hyperloop.authorization(params["salt"], params["hyperloop_channel"], session_id)
      if params["authorization"] == authorization
        inc_subscription
        stream_from "hyperloop-#{params[:hyperloop_channel]}"
      else
        reject
      end
    end

    def unsubscribed
      Hyperloop::Connection.disconnect(params[:hyperloop_channel]) if dec_subscription == 0
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
hyper-operation-0.99.6 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.99.5 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.99.4 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.99.3 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.99.2 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.99.1 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.99.0 lib/hyper-operation/transport/action_cable.rb
hyper-operation-1.0.0.lap28 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.12 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.11 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.10 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.9 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.8 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.7 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.6 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.5 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.4 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.3 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.2 lib/hyper-operation/transport/action_cable.rb
hyper-operation-0.5.1 lib/hyper-operation/transport/action_cable.rb