summaryrefslogtreecommitdiff
path: root/app/models/call.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-12 13:53:28 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-12 13:53:28 +0100
commitc9066760fd1f5f2f892ce2be5cf2a83bb5210246 (patch)
tree82ecdd528e803ccd1b469dc13482e06cf8ea0b8e /app/models/call.rb
parent0b97717b2171820dea41de8df705f8f0e4b71464 (diff)
parentfb66a5e5a4c5d5f9eac4a5e8de6a286482cb55d5 (diff)
Release a new beta.5.1-beta4
Diffstat (limited to 'app/models/call.rb')
-rw-r--r--app/models/call.rb70
1 files changed, 53 insertions, 17 deletions
diff --git a/app/models/call.rb b/app/models/call.rb
index 57961ec..c0f0f08 100644
--- a/app/models/call.rb
+++ b/app/models/call.rb
@@ -1,36 +1,72 @@
class Call < ActiveRecord::Base
- self.table_name = 'channels'
+ self.table_name = 'detailed_calls'
self.primary_key = 'uuid'
- # Makes sure that this is a readonly model.
def readonly?
return true
end
-
- # Prevent objects from being destroyed
- def before_destroy
- raise ActiveRecord::ReadOnlyRecord
- end
- # Prevent objects from being deleted
- def self.delete_all
- raise ActiveRecord::ReadOnlyRecord
+ def destroy
+ return self.delete
end
- # Prevent objects from being deleted
def delete
- raise ActiveRecord::ReadOnlyRecord
+ require 'freeswitch_event'
+ return FreeswitchAPI.execute('uuid_kill', self.uuid, true);
end
def sip_account
- auth_name = self.name.match('^.+[/:](.+)@.+$')
- if auth_name && ! auth_name[1].blank?
- return SipAccount.where(:auth_name => auth_name[1]).first
+ result = self.presence_id.match('^(.+)@(.+)$')
+
+ if result && ! result[1].blank? and ! result[2].blank?
+ domain = SipDomain.where(:host => result[2]).first
+ if domain
+ return SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first
+ end
end
end
- def kill
+ def sip_account_bleg
+ result = self.b_presence_id.match('^(.+)@(.+)$')
+
+ if result && ! result[1].blank? and ! result[2].blank?
+ domain = SipDomain.where(:host => result[2]).first
+ if domain
+ return SipAccount.where(:auth_name => result[1], :sip_domain_id => domain.id).first
+ end
+ end
+ end
+
+ def get_variable_from_uuid(channel_uuid, variable_name)
+ if channel_uuid.blank?
+ return nil
+ end
+
require 'freeswitch_event'
- return FreeswitchAPI.execute('uuid_kill', self.uuid, true);
+ result = FreeswitchAPI.channel_variable_get(channel_uuid, variable_name);
+
+ if result == '_undef_'
+ return nil
+ end
+
+ return result
+ end
+
+ def get_variable(variable_name)
+ return get_variable_from_uuid(self.uuid, variable_name);
+ end
+
+ def get_variable_bleg(variable_name)
+ return get_variable_from_uuid(self.b_uuid, variable_name);
+ end
+
+ def is_sip
+ return self.name.match('^sofia') != nil
+ end
+
+ def is_caller
+ if (self.uuid == self.call_uuid) || self.call_uuid.blank?
+ true
+ end
end
end