Class: Hyperloop::ActionCableChannel

Inherits:
ApplicationCable::Channel show all
Defined in:
lib/hyper-operation/transport/action_cable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.subscriptionsObject


9
10
11
# File 'lib/hyper-operation/transport/action_cable.rb', line 9

def subscriptions
  @subscriptions ||= Hash.new { |h, k| h[k] = 0 }
end

Instance Method Details

#dec_subscriptionObject


19
20
21
22
# File 'lib/hyper-operation/transport/action_cable.rb', line 19

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

#inc_subscriptionObject


14
15
16
17
# File 'lib/hyper-operation/transport/action_cable.rb', line 14

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

#subscribedObject


24
25
26
27
28
29
30
31
32
33
# File 'lib/hyper-operation/transport/action_cable.rb', line 24

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

#unsubscribedObject


35
36
37
# File 'lib/hyper-operation/transport/action_cable.rb', line 35

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