class AsteriskManager::ChannelEventPoller

Attributes

connection[RW]
poll_thread[RW]

Public Class Methods

new(arguments = {}) click to toggle source
# File lib/asterisk-manager/channel_event_poller.rb, line 6
def initialize(arguments = {})
  self.connection = arguments[:connection]
end

Public Instance Methods

core_show_channel(event) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/asterisk-manager/channel_event_poller.rb, line 10
def subscribe(event_listener)
  event_listener.subscribe self, 'CoreShowChannel'
end