Class: AsteriskManager::ChannelEventPoller
- Inherits:
-
Object
- Object
- AsteriskManager::ChannelEventPoller
- Defined in:
- lib/asterisk-manager/channel_event_poller.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#poll_thread ⇒ Object
Returns the value of attribute poll_thread.
Instance Method Summary collapse
- #core_show_channel(event) ⇒ Object
-
#initialize(arguments = {}) ⇒ ChannelEventPoller
constructor
A new instance of ChannelEventPoller.
- #poll ⇒ Object
- #receive_event(event) ⇒ Object
- #subscribe(event_listener) ⇒ Object
Constructor Details
#initialize(arguments = {}) ⇒ ChannelEventPoller
Returns a new instance of ChannelEventPoller.
6 7 8 |
# File 'lib/asterisk-manager/channel_event_poller.rb', line 6 def initialize(arguments = {}) self.connection = arguments[:connection] end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
3 4 5 |
# File 'lib/asterisk-manager/channel_event_poller.rb', line 3 def connection @connection end |
#poll_thread ⇒ Object
Returns the value of attribute poll_thread.
3 4 5 |
# File 'lib/asterisk-manager/channel_event_poller.rb', line 3 def poll_thread @poll_thread end |
Instance Method Details
#core_show_channel(event) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/asterisk-manager/channel_event_poller.rb', line 21 def core_show_channel(event) channel = Channel.for_unique_id(event['UniqueID']) channel.sip_id = event['Channel'] channel.state = event['ChannelStateDesc'] channel.caller_id_number = event['CallerIDnum'] channel.application_name = event['Application'] channel.application_data = event['ApplicationData'] duration_pieces = event['Duration'].split(':') duration = duration_pieces[0].to_i * 3600 + duration_pieces[1].to_i * 60 + duration_pieces[2].to_i channel.created_at = Time.now - duration if event['BridgedUniqueID'] != '' bridged_channel = Channel.for_unique_id(event['BridgedUniqueID']) bridged_channel.sip_id = event['BridgedChannel'] channel_1, channel_2 = [ channel, bridged_channel ].sort Call.for_channel_1_and_channel_2 channel_1, channel_2 end end |
#poll ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/asterisk-manager/channel_event_poller.rb', line 39 def poll self.poll_thread = Thread.new do loop do connection.send "Action: CoreShowChannels\r\n" connection.send "\r\n" sleep 5 end end end |
#receive_event(event) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/asterisk-manager/channel_event_poller.rb', line 14 def receive_event(event) case event.type when 'CoreShowChannel' core_show_channel(event) end end |
#subscribe(event_listener) ⇒ Object
10 11 12 |
# File 'lib/asterisk-manager/channel_event_poller.rb', line 10 def subscribe(event_listener) event_listener.subscribe self, 'CoreShowChannel' end |