Class: Motion::Channel

Inherits:
ActionCable::Channel::Base
  • Object
show all
Includes:
ActionCableExtentions::DeclarativeNotifications, ActionCableExtentions::DeclarativeStreams, ActionCableExtentions::LogSuppression
Defined in:
lib/motion/channel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActionCableExtentions::LogSuppression

#initialize, #logger

Methods included from ActionCableExtentions::DeclarativeStreams

#declarative_stream_target, #initialize, #stop_all_streams, #streaming_from

Methods included from ActionCableExtentions::Synchronization

#initialize, #perform_action, #subscribe_to_channel, #synchronize_entrypoint!, #unsubscribe_from_channel

Methods included from ActionCableExtentions::DeclarativeNotifications

#declarative_notifications, #initialize, #periodically_notify

Instance Attribute Details

#component_connectionObject (readonly)

Returns the value of attribute component_connection.



23
24
25
# File 'lib/motion/channel.rb', line 23

def component_connection
  @component_connection
end

Class Method Details

.action_methodsObject

Don’t use the ActionCable heuristic for deciding what actions can be called from JavaScript. Instead, hard-code the list so we can make other methods public without worrying about them being called from JavaScript.



19
20
21
# File 'lib/motion/channel.rb', line 19

def self.action_methods
  ACTION_METHODS
end

Instance Method Details

#process_broadcast(broadcast, message) ⇒ Object



55
56
57
58
# File 'lib/motion/channel.rb', line 55

def process_broadcast(broadcast, message)
  component_connection.process_broadcast(broadcast, message)
  synchronize
end

#process_motion(data) ⇒ Object



48
49
50
51
52
53
# File 'lib/motion/channel.rb', line 48

def process_motion(data)
  motion, raw_event = data.values_at("name", "event")

  component_connection.process_motion(motion, Event.from_raw(raw_event))
  synchronize
end

#process_periodic_timer(timer) ⇒ Object



60
61
62
63
# File 'lib/motion/channel.rb', line 60

def process_periodic_timer(timer)
  component_connection.process_periodic_timer(timer)
  synchronize
end

#subscribedObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/motion/channel.rb', line 25

def subscribed
  state, client_version = params.values_at("state", "version")

  if Gem::Version.new(Motion::VERSION) < Gem::Version.new(client_version)
    raise IncompatibleClientError.new(Motion::VERSION, client_version)
  end

  @component_connection =
    ComponentConnection.from_state(state, log_helper: log_helper)

  synchronize
rescue => error
  reject

  handle_error(error, "connecting a component")
end

#unsubscribedObject



42
43
44
45
46
# File 'lib/motion/channel.rb', line 42

def unsubscribed
  component_connection&.close

  @component_connection = nil
end