summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/phones/uacsta.lua
blob: 61cb7882bc75fa948fc20c0e399e572b89fafe7c (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
-- CommonModule: Uacsta
--
module(...,package.seeall)

Uacsta = {}

-- Create Uacsta object
function Uacsta.new(self, arg)
  arg = arg or {}
  object = arg.object or {}
  setmetatable(object, self)
  self.__index = self
  self.log = arg.log;

  return object
end

function Uacsta.send(self, sip_account, domain, body)
  local event = freeswitch.Event("NOTIFY");
  event:addHeader("profile", "gemeinschaft");
  event:addHeader("event-string", "uaCSTA");
  event:addHeader("user", sip_account);
  event:addHeader("host", domain);
  event:addHeader("content-type", "application/csta+xml");
  event:addBody(body);
  event:fire();
end

function Uacsta.make_call(self, sip_account, domain, number)
  local body = 
[[<?xml version="1.0" encoding="UTF-8"?> 
<MakeCall xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4"> 
  <callingDevice>]] .. sip_account .. [[</callingDevice> 
  <calledDirectoryNumber>]] .. number .. [[</calledDirectoryNumber> 
  <autoOriginate>doNotPrompt</autoOriginate> 
</MakeCall>]]

  self:send(sip_account, domain, body);
end

function Uacsta.answer_call(self, sip_account, domain)
  local body = 
[[<?xml version="1.0" encoding="UTF-8"?> 
<AnswerCall xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed4">
  <callToBeAnswered>
    <deviceID>]] .. sip_account .. [[</deviceID>
  </callToBeAnswered>
</AnswerCall>]]

  self:send(sip_account, domain, body);
end

function Uacsta.set_microphone_mute(self, sip_account, domain, value)
  local body = 
[[<?xml version="1.0" encoding="UTF-8"?> 
<SetMicrophoneMute xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed3">
  <device>]] .. sip_account .. [[</device>
  <auditoryApparatus>1</auditoryApparatus>
  <microphoneMuteOn>]] .. tostring(value) .. [[</microphoneMuteOn>
</SetMicrophoneMute>]]

  self:send(sip_account, domain, body);
end

function Uacsta.set_speaker_volume(self, sip_account, domain, value)
  local body = 
[[<?xml version="1.0" encoding="UTF-8"?> 
<SetSpeakerVolume xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed3">
  <device>]] .. sip_account .. [[</device>
  <auditoryApparatus>1</auditoryApparatus>
  <speakerVolume>]] .. tonumber(value) .. [[</speakerVolume>
</SetSpeakerVolume>]]

  self:send(sip_account, domain, body);
end

function Uacsta.set_do_not_disturb(self, sip_account, domain, value)
  local body = 
[[<?xml version="1.0" encoding="UTF-8"?> 
<SetDoNotDisturb xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed3">
  <device>]] .. sip_account .. [[</device>
  <doNotDisturbOn>]] .. tostring(value) .. [[</doNotDisturbOn>
</SetDoNotDisturb>]]

  self:send(sip_account, domain, body);
end

function Uacsta.set_forwarding(self, sip_account, domain, forwarding_type, number, activate)
  local forwarding_types = { "forwardImmediate", "forwardBusy", "forwardNoAns" }
  local body = 
[[<?xml version="1.0" encoding="UTF-8"?> 
<SetForwarding xmlns="http://www.ecma-international.org/standards/ecma-323/csta/ed3">
  <device>]] .. sip_account .. [[</device>
  <forwardingType>]] .. tostring(forwarding_types[tonumber(forwarding_type)]) .. [[</forwardingType>
  <forwardDN>]] .. number .. [[</forwardDN>
  <activateForward>]] .. tostring(activate) .. [[</activateForward>
</SetForwarding>]]

  self:send(sip_account, domain, body);
end