Class: RubyAMI::Client

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/ruby_ami/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
# File 'lib/ruby_ami/client.rb', line 10

def initialize(options)
  @options        = options
  @event_handler  = @options[:event_handler]
  @state          = :stopped
  client          = current_actor
  @events_stream  = new_stream ->(event) { client.async.handle_event event }
  @actions_stream = new_stream ->(message) { client.async.handle_message message }
end

Instance Attribute Details

#actions_streamObject (readonly)

Returns the value of attribute actions_stream.



8
9
10
# File 'lib/ruby_ami/client.rb', line 8

def actions_stream
  @actions_stream
end

#events_streamObject (readonly)

Returns the value of attribute events_stream.



8
9
10
# File 'lib/ruby_ami/client.rb', line 8

def events_stream
  @events_stream
end

Instance Method Details

#handle_event(event) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/ruby_ami/client.rb', line 44

def handle_event(event)
  logger.trace "[RECV-EVENTS]: #{event.inspect}"
  case event
  when Stream::Connected, Stream::Disconnected
  else
    pass_event event
  end
end

#handle_message(message) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby_ami/client.rb', line 33

def handle_message(message)
  logger.trace "[RECV-ACTIONS]: #{message.inspect}"
  case message
  when Stream::Connected
    send_action 'Events', 'EventMask' => 'Off'
  when Stream::Disconnected
  when Event
    pass_event message
  end
end

#send_action(*args) ⇒ Object



29
30
31
# File 'lib/ruby_ami/client.rb', line 29

def send_action(*args)
  actions_stream.send_action *args
end

#startObject



23
24
25
26
27
# File 'lib/ruby_ami/client.rb', line 23

def start
  @events_stream.async.run
  @actions_stream.async.run
  @state = :started
end