Class: RubyAMI::Stream
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- RubyAMI::Stream
show all
- Defined in:
- lib/ruby_ami/stream.rb
Defined Under Namespace
Classes: ConnectionStatus
Constant Summary
collapse
- Connected =
Class.new ConnectionStatus
- Disconnected =
Class.new ConnectionStatus
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(event_callback) ⇒ Stream
Returns a new instance of Stream.
18
19
20
21
22
23
24
25
|
# File 'lib/ruby_ami/stream.rb', line 18
def initialize(event_callback)
super()
@event_callback = event_callback
@logger = Logger.new($stdout)
@logger.level = Logger::FATAL
@logger.debug "Starting up..."
@lexer = Lexer.new self
end
|
Class Method Details
.start(host, port, event_callback) ⇒ Object
14
15
16
|
# File 'lib/ruby_ami/stream.rb', line 14
def self.start(host, port, event_callback)
EM.connect host, port, self, event_callback
end
|
Instance Method Details
#message_received(message) ⇒ Object
Also known as:
error_received
46
47
48
49
|
# File 'lib/ruby_ami/stream.rb', line 46
def message_received(message)
@logger.debug "[RECV] #{message.inspect}"
@event_callback.call message
end
|
#post_init ⇒ Object
31
32
33
34
|
# File 'lib/ruby_ami/stream.rb', line 31
def post_init
@state = :started
@event_callback.call Connected.new
end
|
#receive_data(data) ⇒ Object
41
42
43
44
|
# File 'lib/ruby_ami/stream.rb', line 41
def receive_data(data)
@logger.debug "[RECV] #{data}"
@lexer << data
end
|
#send_action(action) ⇒ Object
36
37
38
39
|
# File 'lib/ruby_ami/stream.rb', line 36
def send_action(action)
@logger.debug "[SEND] #{action.to_s}"
send_data action.to_s
end
|
Called by EM when the connection is closed
55
56
57
58
|
# File 'lib/ruby_ami/stream.rb', line 55
def unbind
@state = :stopped
@event_callback.call Disconnected.new
end
|