summaryrefslogtreecommitdiff
path: root/app/models/pager_group.rb
blob: 5c9c6ad5ae8e2b8eed2fe34b9ffa96fffbfb8bee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class PagerGroup < ActiveRecord::Base
  attr_accessible :sip_account_id, :callback_url

  has_many :pager_group_destinations, :dependent => :destroy
  belongs_to :sip_account

  validates_presence_of :sip_account_id

  after_create :call
  before_destroy :hangup_all

  def identifier
    "pager#{self.id}"
  end

  def call
    self.sip_account.call("f-pager-#{self.id}")
  end

  def hangup_all
    require 'freeswitch_event'
    return FreeswitchAPI.execute(
      'conference', "#{self.identifier} hup all", 
      true
    );
  end
end