adhearsion-xmpp-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.markdown +27 -0
- data/lib/adhearsion-xmpp-api.rb +3 -0
- data/lib/adhearsion-xmpp-api/active_call_stanza.rb +109 -0
- data/lib/adhearsion-xmpp-api/call.rb +52 -0
- data/lib/adhearsion-xmpp-api/controller.rb +406 -0
- data/test/helper.rb +10 -0
- data/test/test_adhearsion-xmpp-api.rb +7 -0
- metadata +105 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ben Langfeld
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Adhearsion XMPP API
|
2
|
+
===================
|
3
|
+
|
4
|
+
* [Docs](http://yardoc.org/docs/benlangfeld-adhearsion-xmpp-api)
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
gem install adhearsion-xmpp-api
|
9
|
+
|
10
|
+
Usage
|
11
|
+
-----
|
12
|
+
Copy example/xmpp\_api to your components directory and check the config in xmpp_api.yml
|
13
|
+
|
14
|
+
Note on Patches/Pull Requests
|
15
|
+
-----------------------------
|
16
|
+
|
17
|
+
* Fork the project.
|
18
|
+
* Make your feature addition or bug fix.
|
19
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
20
|
+
* Commit, do not mess with rakefile, version, or history.
|
21
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull)
|
22
|
+
* Send me a pull request. Bonus points for topic branches.
|
23
|
+
|
24
|
+
Copyright
|
25
|
+
---------
|
26
|
+
|
27
|
+
Copyright (c) 2010 Ben Langfeld. See LICENSE for details.
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Adhearsion
|
2
|
+
module XMPP
|
3
|
+
module API
|
4
|
+
class ActiveCallStanza < ::Blather::XMPPNode
|
5
|
+
NS = 'X-urn:xmpp:sip:active-calls'.freeze
|
6
|
+
|
7
|
+
#
|
8
|
+
# @param [Hash, nil] options child elements
|
9
|
+
def self.new(options = {})
|
10
|
+
new_node = super "active-call"
|
11
|
+
options.each_pair do |key, value|
|
12
|
+
o = "#{key.to_s}=".to_sym
|
13
|
+
new_node.send o, value
|
14
|
+
end
|
15
|
+
new_node.namespace = NS
|
16
|
+
new_node
|
17
|
+
end
|
18
|
+
|
19
|
+
def dialog_state
|
20
|
+
content_from "dialog-state"
|
21
|
+
end
|
22
|
+
|
23
|
+
def dialog_state=(value)
|
24
|
+
set_content_for "dialog-state", value
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_aor
|
28
|
+
content_from "to-aor"
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_aor=(value)
|
32
|
+
set_content_for "to-aor", value
|
33
|
+
end
|
34
|
+
|
35
|
+
def call_id
|
36
|
+
content_from "call-id"
|
37
|
+
end
|
38
|
+
|
39
|
+
def call_id=(value)
|
40
|
+
set_content_for "call-id", value
|
41
|
+
end
|
42
|
+
|
43
|
+
def from_uri
|
44
|
+
content_from "from-uri"
|
45
|
+
end
|
46
|
+
|
47
|
+
def from_uri=(value)
|
48
|
+
set_content_for "from-uri", value
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_uri
|
52
|
+
content_from "to-uri"
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_uri=(value)
|
56
|
+
set_content_for "to-uri", value
|
57
|
+
end
|
58
|
+
|
59
|
+
def from_tag
|
60
|
+
content_from "from-tag"
|
61
|
+
end
|
62
|
+
|
63
|
+
def from_tag=(value)
|
64
|
+
set_content_for "from-tag", value
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_tag
|
68
|
+
content_from "to-tag"
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_tag=(value)
|
72
|
+
set_content_for "to-tag", value
|
73
|
+
end
|
74
|
+
|
75
|
+
def branch
|
76
|
+
content_from "branch"
|
77
|
+
end
|
78
|
+
|
79
|
+
def branch=(value)
|
80
|
+
set_content_for "branch", value
|
81
|
+
end
|
82
|
+
|
83
|
+
def call_setup_id
|
84
|
+
content_from "call-setup-id"
|
85
|
+
end
|
86
|
+
|
87
|
+
def call_setup_id=(value)
|
88
|
+
set_content_for "call-setup-id", value
|
89
|
+
end
|
90
|
+
|
91
|
+
# # generate accessors
|
92
|
+
# MEMBERS.each do |member|
|
93
|
+
# define_method(member.sub('-', '_')) do
|
94
|
+
# content_from member
|
95
|
+
# end
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# # generate setters
|
99
|
+
# MEMBERS.each do |member|
|
100
|
+
# member_clean = member.sub('-', '_')
|
101
|
+
# define_method("#{member_clean}=(#{member_clean})") do
|
102
|
+
# set_content_for member, member_clean
|
103
|
+
# end
|
104
|
+
# end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Adhearsion
|
2
|
+
module XMPP
|
3
|
+
module API
|
4
|
+
class Call
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
|
8
|
+
end
|
9
|
+
|
10
|
+
#
|
11
|
+
# Find a call based on hash of parameters
|
12
|
+
#
|
13
|
+
def self.find(params)
|
14
|
+
call_id, from_tag, to_tag, uniqueid = params[:call_id], params[:from_tag], params[:to_tag], params[:uniqueid]
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.create(from, to, call_setup_id = nil)
|
19
|
+
# Setup initial leg of call to caller
|
20
|
+
Adhearsion.originate :channel => "Local/#{from}@#{Controller.outgoing_context}",
|
21
|
+
#:variables => {:foo_id => 123, :bar_id => bar.id},
|
22
|
+
:caller_id => Controller.call_setup_caller_id,
|
23
|
+
:name => Controller.call_setup_name,
|
24
|
+
:context => Controller.outgoing_context,
|
25
|
+
:application => 'AGI',
|
26
|
+
:data => nil,
|
27
|
+
:actionid => "#{call_setup_id}-caller"
|
28
|
+
end
|
29
|
+
|
30
|
+
def transfer(endpoint, target_uri)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def terminate!
|
35
|
+
if @ahn_call
|
36
|
+
@ahn_call.hangup!
|
37
|
+
#Adhearsion::VoIP::Asterisk.manager_interface.hangup @ahn_call.variables[:channel]
|
38
|
+
else
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Leg
|
44
|
+
def retract!
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,406 @@
|
|
1
|
+
module Adhearsion
|
2
|
+
module XMPP
|
3
|
+
module API
|
4
|
+
class Controller
|
5
|
+
cattr_accessor :outgoing_context, :call_setup_caller_id, :call_setup_name
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def setup(outgoing_context, call_setup_caller_id, call_setup_name, pubsub_host)
|
9
|
+
self.outgoing_context = outgoing_context
|
10
|
+
self.call_setup_caller_id = call_setup_caller_id
|
11
|
+
self.call_setup_name = call_setup_name
|
12
|
+
@@pubsub = Blather::DSL::PubSub.new XMPP::Connection.client, pubsub_host
|
13
|
+
register_command_handlers
|
14
|
+
register_disco_handlers
|
15
|
+
register_event_callbacks
|
16
|
+
end
|
17
|
+
|
18
|
+
def publish(node, payload)
|
19
|
+
@@pubsub.publish node, payload
|
20
|
+
end
|
21
|
+
|
22
|
+
def retract(node, ids)
|
23
|
+
@@pubsub.retract node, ids
|
24
|
+
end
|
25
|
+
|
26
|
+
def register_command_handlers
|
27
|
+
#
|
28
|
+
# Create call
|
29
|
+
#
|
30
|
+
Adhearsion::XMPP::Connection.command :set?, :execute?, :node => "create" do |command|
|
31
|
+
begin
|
32
|
+
r = command.reply
|
33
|
+
r.new_sessionid!
|
34
|
+
if command.form.type
|
35
|
+
if command.sessionid?
|
36
|
+
ahn_log.xmpp.debug "Active Call Commands: Create - submission"
|
37
|
+
else
|
38
|
+
ahn_log.xmpp.debug "Active Call Commands: Create - single stage - submission"
|
39
|
+
end
|
40
|
+
# Test authorization
|
41
|
+
|
42
|
+
# Setup initial leg of call to caller
|
43
|
+
options = {
|
44
|
+
:channel => "Local/sip:ben:studiotalker.com@outgoing-497",#"Local/#{command.form.field("from").value}@#{outgoing_context}",
|
45
|
+
#:variables => {:callee => command.form.field("to").value},
|
46
|
+
#:caller_id => call_setup_caller_id,
|
47
|
+
#:name => call_setup_name,
|
48
|
+
:context => outgoing_context,
|
49
|
+
:application => 'AGI',
|
50
|
+
:data => 'agi://cloudvox-api.studiotalker.com'
|
51
|
+
#:actionid => "#{command.form.field("call-setup-id").value}-caller"
|
52
|
+
}
|
53
|
+
call_originate_response = Adhearsion.originate options
|
54
|
+
|
55
|
+
if call
|
56
|
+
r.status = :completed
|
57
|
+
r.form.type = :result
|
58
|
+
r.form.fields = [{:type => 'fixed', :var => 'call-setup-id', :value => call.setupid}]
|
59
|
+
else
|
60
|
+
# Respond with error
|
61
|
+
r.form.type = :submit
|
62
|
+
r.form.fields = [{:type => 'text-single', :var => 'from', :value => command.form.field("from").value},
|
63
|
+
{:type => 'text-single', :var => 'to', :value => command.form.field("to").value}]
|
64
|
+
r = r.as_error("400", :modify)#, call
|
65
|
+
end
|
66
|
+
else
|
67
|
+
ahn_log.xmpp.debug "Active Call Commands: Create - initial request."
|
68
|
+
# Send empty form
|
69
|
+
r.status = :executing
|
70
|
+
r.allowed_actions = [:cancel, :execute]
|
71
|
+
r.primary_allowed_action = :execute
|
72
|
+
r.form
|
73
|
+
r.form.type = :form
|
74
|
+
r.form.title = "Create Call"
|
75
|
+
r.form.instructions = "Enter the SIP address of the caller and callee."
|
76
|
+
r.form.fields = [
|
77
|
+
{:label => 'From', :type => 'text-single', :var => 'from', :required => true},
|
78
|
+
{:label => 'To', :type => 'text-single', :var => 'to', :required => true},
|
79
|
+
{:label => 'Call Setup ID', :type => 'text-single', :var => 'call-setup-id'}
|
80
|
+
]
|
81
|
+
end
|
82
|
+
Adhearsion::XMPP::Connection.write_to_stream r
|
83
|
+
rescue => e
|
84
|
+
puts e.backtrace
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Terminate call
|
90
|
+
#
|
91
|
+
Adhearsion::XMPP::Connection.command :set?, :execute?, :node => "terminate" do |command|
|
92
|
+
begin
|
93
|
+
if command.form.type
|
94
|
+
if command.sessionid?
|
95
|
+
ahn_log.xmpp.debug "Active Call Commands: Terminate - submission"
|
96
|
+
else
|
97
|
+
ahn_log.xmpp.debug "Active Call Commands: Terminate - single stage - submission"
|
98
|
+
end
|
99
|
+
call = Adhearsion::XMPP::API::Call.find(:call_id => command.form.field("call-id").value, :from_tag => command.form.field("from-tag").value, :to_tag => command.form.field("to-tag").value)
|
100
|
+
|
101
|
+
# Test authorization
|
102
|
+
|
103
|
+
# Terminate call
|
104
|
+
call.terminate!
|
105
|
+
|
106
|
+
r = command.reply
|
107
|
+
if call[:status] == :terminated
|
108
|
+
r.status = :completed
|
109
|
+
r.form.type = :result
|
110
|
+
r.form.fields [{:type => 'fixed', :var => 'call-setup-id', :value => call.setupid}]
|
111
|
+
else
|
112
|
+
# Respond with error
|
113
|
+
r.form.type = :submit
|
114
|
+
r.form.fields = [
|
115
|
+
{:type => 'text-single', :var => 'from', :value => command.form.field("from").value},
|
116
|
+
{:type => 'text-single', :var => 'to', :value => command.form.field("to").value}
|
117
|
+
]
|
118
|
+
r.as_error("400", :modify, call[:errors])
|
119
|
+
end
|
120
|
+
else
|
121
|
+
ahn_log.xmpp.debug "Active Call Commands: Terminate - initial request."
|
122
|
+
# Send empty form
|
123
|
+
r = command.reply
|
124
|
+
r.status = :executing
|
125
|
+
r.new_sessionid!
|
126
|
+
r.allowed_actions = [:cancel, :execute]
|
127
|
+
r.primary_allowed_action = :execute
|
128
|
+
r.form.type = :form
|
129
|
+
r.form.title = "Terminate Call"
|
130
|
+
r.form.instructions = "Complete to terminate call."
|
131
|
+
r.form.fields = [
|
132
|
+
{:label => 'Call ID', :type => 'text-single', :var => 'call-id', :required => true},
|
133
|
+
{:label => 'From Tag', :type => 'text-single', :var => 'from-tag', :required => true},
|
134
|
+
{:label => 'To Tag', :type => 'text-single', :var => 'to-tag', :required => true}
|
135
|
+
]
|
136
|
+
end
|
137
|
+
Adhearsion::XMPP::Connection.write_to_stream r
|
138
|
+
rescue => e
|
139
|
+
puts e.backtrace
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# Transfer call
|
145
|
+
#
|
146
|
+
Adhearsion::XMPP::Connection.command :set?, :execute?, :node => "transfer" do |command|
|
147
|
+
begin
|
148
|
+
if command.form.type
|
149
|
+
if command.sessionid?
|
150
|
+
ahn_log.xmpp.debug "Active Call Commands: Transfer - submission"
|
151
|
+
else
|
152
|
+
ahn_log.xmpp.debug "Active Call Commands: Transfer - single stage - submission"
|
153
|
+
end
|
154
|
+
# Test authorization
|
155
|
+
|
156
|
+
# Transfer call
|
157
|
+
call = Adhearsion::XMPP::API::Call.find(:call_id => command.form.field("call-id").value, :from_tag => command.form.field("from-tag").value, :to_tag => command.form.field("to-tag").value)
|
158
|
+
|
159
|
+
call.transfer!(command.form.field("endpoint").value, command.form.field("target-uri").value)
|
160
|
+
|
161
|
+
# Send response
|
162
|
+
r = command.reply
|
163
|
+
if call[:status] == :success
|
164
|
+
r.status = :completed
|
165
|
+
r.form.type = :result
|
166
|
+
r.form.fields = [{:type => 'fixed', :var => 'call-setup-id', :value => call.setupid}]
|
167
|
+
else
|
168
|
+
# Respond with error
|
169
|
+
r.form.type = :submit
|
170
|
+
r.form.fields = [
|
171
|
+
{:type => 'text-single', :var => 'from', :value => command.form.field("from").value},
|
172
|
+
{:type => 'text-single', :var => 'to', :value => command.form.field("to").value}
|
173
|
+
]
|
174
|
+
r.as_error("400", :modify, call[:errors])
|
175
|
+
end
|
176
|
+
else
|
177
|
+
ahn_log.xmpp.debug "Active Call Commands: Transfer - initial request."
|
178
|
+
# Send empty form
|
179
|
+
r = command.reply
|
180
|
+
r.status = :executing
|
181
|
+
r.new_sessionid!
|
182
|
+
r.allowed_actions = [:cancel, :execute]
|
183
|
+
r.primary_allowed_action = :execute
|
184
|
+
r.form.type = :form
|
185
|
+
r.form.title = "Transfer Call"
|
186
|
+
r.form.instructions = "Enter the SIP address of the caller and callee."
|
187
|
+
r.form.fields = [
|
188
|
+
{:label => 'Call ID', :type => 'text-single', :var => 'call-id', :required => true},
|
189
|
+
{:label => 'From Tag', :type => 'text-single', :var => 'from-tag', :required => true},
|
190
|
+
{:label => 'To Tag', :type => 'text-single', :var => 'to-tag', :required => true},
|
191
|
+
{:label => 'Endpoint', :type => 'text-single', :var => 'endpoint', :required => true, :options => [
|
192
|
+
{:label => 'Callee', :value => 'callee'},
|
193
|
+
{:label => 'Caller', :value => 'caller'}
|
194
|
+
]},
|
195
|
+
{:label => 'Target URI', :type => 'text-single', :var => 'target-uri', :required => true}
|
196
|
+
]
|
197
|
+
end
|
198
|
+
Adhearsion::XMPP::Connection.write_to_stream r
|
199
|
+
rescue => e
|
200
|
+
puts e.backtrace
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# Cancel call
|
206
|
+
#
|
207
|
+
Adhearsion::XMPP::Connection.command :set?, :execute?, :node => "cancel" do |command|
|
208
|
+
if command.form.type
|
209
|
+
if command.sessionid?
|
210
|
+
ahn_log.xmpp.debug "Active Call Commands: Cancel - submission"
|
211
|
+
else
|
212
|
+
ahn_log.xmpp.debug "Active Call Commands: Cancel - single stage - submission"
|
213
|
+
end
|
214
|
+
else
|
215
|
+
ahn_log.xmpp.debug "Active Call Commands: Cancel - initial request."
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
#
|
220
|
+
# Cancel execution of command
|
221
|
+
#
|
222
|
+
Adhearsion::XMPP::Connection.command :set?, :cancel? do |command|
|
223
|
+
begin
|
224
|
+
r = command.reply
|
225
|
+
r.status = :canceled
|
226
|
+
Adhearsion::XMPP::Connection.write_to_stream r
|
227
|
+
rescue => e
|
228
|
+
puts e.backtrace
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
def register_disco_handlers
|
235
|
+
Adhearsion::XMPP::Connection.disco_info :get?, :node => nil do |iq|
|
236
|
+
begin
|
237
|
+
identities = [{:name => "Active Call Commands", :type => "generic", :category => "component"}]
|
238
|
+
features = %w{http://jabber.org/protocol/commands
|
239
|
+
http://jabber.org/protocol/disco#info
|
240
|
+
http://jabber.org/protocol/disco#items
|
241
|
+
}
|
242
|
+
iq.reply!
|
243
|
+
iq.identities = identities
|
244
|
+
iq.features = features
|
245
|
+
Adhearsion::XMPP::Connection.write_to_stream iq
|
246
|
+
rescue => e
|
247
|
+
puts e.backtrace
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
Adhearsion::XMPP::Connection.disco_items :get?, :node => nil do |iq|
|
252
|
+
begin
|
253
|
+
items = [{:jid => Adhearsion::XMPP::Connection.jid, :node => "http://jabber.org/protocol/commands", :name => "Commands"}]
|
254
|
+
iq.reply!.items = items
|
255
|
+
Adhearsion::XMPP::Connection.write_to_stream iq
|
256
|
+
rescue => e
|
257
|
+
puts e.backtrace
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
Adhearsion::XMPP::Connection.disco_info :get?, :node => "http://jabber.org/protocol/commands" do |iq|
|
262
|
+
begin
|
263
|
+
identities = [{:name => "Commands", :type => "command-list", :category => "automation"}]
|
264
|
+
features = %w{http://jabber.org/protocol/disco#info
|
265
|
+
http://jabber.org/protocol/disco#items
|
266
|
+
}
|
267
|
+
iq.reply!
|
268
|
+
iq.identities = identities
|
269
|
+
iq.features = features
|
270
|
+
Adhearsion::XMPP::Connection.write_to_stream iq
|
271
|
+
rescue => e
|
272
|
+
puts e.backtrace
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
Adhearsion::XMPP::Connection.disco_items :get?, :node => "http://jabber.org/protocol/commands" do |iq|
|
277
|
+
begin
|
278
|
+
items = []
|
279
|
+
items << {:jid => Adhearsion::XMPP::Connection.jid, :node => "create", :name => "Create Call"}
|
280
|
+
items << {:jid => Adhearsion::XMPP::Connection.jid, :node => "cancel", :name => "Cancel Call"}
|
281
|
+
items << {:jid => Adhearsion::XMPP::Connection.jid, :node => "transfer", :name => "Transfer Call"}
|
282
|
+
items << {:jid => Adhearsion::XMPP::Connection.jid, :node => "terminate", :name => "Terminate Call"}
|
283
|
+
iq.reply!.items = items
|
284
|
+
Adhearsion::XMPP::Connection.write_to_stream iq
|
285
|
+
rescue => e
|
286
|
+
puts e.backtrace
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
Adhearsion::XMPP::Connection.disco_info :get?, :node => "create" do |iq|
|
291
|
+
begin
|
292
|
+
identities = [{:name => "Create Call", :type => "command-node", :category => "automation"}]
|
293
|
+
features = %w{http://jabber.org/protocol/commands
|
294
|
+
jabber:x:data
|
295
|
+
}
|
296
|
+
iq.reply!
|
297
|
+
iq.identities = identities
|
298
|
+
iq.features = features
|
299
|
+
Adhearsion::XMPP::Connection.write_to_stream iq
|
300
|
+
rescue => e
|
301
|
+
puts e.backtrace
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
Adhearsion::XMPP::Connection.disco_info :get?, :node => "cancel" do |iq|
|
306
|
+
begin
|
307
|
+
identities = [{:name => "Cancel Call", :type => "command-node", :category => "automation"}]
|
308
|
+
features = %w{http://jabber.org/protocol/commands
|
309
|
+
jabber:x:data
|
310
|
+
}
|
311
|
+
iq.reply!
|
312
|
+
iq.identities = identities
|
313
|
+
iq.features = features
|
314
|
+
Adhearsion::XMPP::Connection.write_to_stream iq
|
315
|
+
rescue => e
|
316
|
+
puts e.backtrace
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
Adhearsion::XMPP::Connection.disco_info :get?, :node => "transfer" do |iq|
|
321
|
+
begin
|
322
|
+
identities = [{:name => "Transfer Call", :type => "command-node", :category => "automation"}]
|
323
|
+
features = %w{http://jabber.org/protocol/commands
|
324
|
+
jabber:x:data
|
325
|
+
}
|
326
|
+
iq.reply!
|
327
|
+
iq.identities = identities
|
328
|
+
iq.features = features
|
329
|
+
Adhearsion::XMPP::Connection.write_to_stream iq
|
330
|
+
rescue => e
|
331
|
+
puts e.backtrace
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
Adhearsion::XMPP::Connection.disco_info :get?, :node => "terminate" do |iq|
|
336
|
+
begin
|
337
|
+
identities = [{:name => "Terminate Call", :type => "command-node", :category => "automation"}]
|
338
|
+
features = %w{http://jabber.org/protocol/commands
|
339
|
+
jabber:x:data
|
340
|
+
}
|
341
|
+
iq.reply!
|
342
|
+
iq.identities = identities
|
343
|
+
iq.features = features
|
344
|
+
Adhearsion::XMPP::Connection.write_to_stream iq
|
345
|
+
rescue => e
|
346
|
+
puts e.backtrace
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
end
|
351
|
+
|
352
|
+
def register_event_callbacks
|
353
|
+
Adhearsion::Events.register_callback [:asterisk, :manager_interface] do |event|
|
354
|
+
# Get relevant call object
|
355
|
+
sip_call_id = Adhearsion::VoIP::Asterisk.manager_interface.send_action("GetVar", { 'Channel' => event.headers['Channel'], 'Variable' => "${SIPCALLID}" }).headers["Value"]
|
356
|
+
actionid = event.headers["ActionID"]
|
357
|
+
pubsub_item_id = event.headers['Channel']
|
358
|
+
pubsub_node = 'test'
|
359
|
+
pubsub_payload = Adhearsion::XMPP::API::ActiveCallStanza.new(
|
360
|
+
:call_id => sip_call_id,
|
361
|
+
:dialog_state => event.inspect
|
362
|
+
# :from_uri => event.
|
363
|
+
# :to_uri => event.
|
364
|
+
)
|
365
|
+
case event.name.downcase
|
366
|
+
when 'cdr'
|
367
|
+
when 'channelupdate'
|
368
|
+
when 'dial'
|
369
|
+
# if actionid == "#{call_setup_id}-caller"
|
370
|
+
# # Call callee
|
371
|
+
# ahn_log.info "Caller stage completed"
|
372
|
+
# end
|
373
|
+
when 'extensionstatus'
|
374
|
+
when 'hangup'
|
375
|
+
#call_leg = Adhearsion::XMPP::API::Call::Leg.find(:uniqueid => uniqueid)
|
376
|
+
ids = [event.headers['Channel']]
|
377
|
+
retract(pubsub_node, ids)
|
378
|
+
return
|
379
|
+
when 'musiconhold'
|
380
|
+
when 'join'
|
381
|
+
when 'leave'
|
382
|
+
when 'link'
|
383
|
+
when 'messagewaiting'
|
384
|
+
when 'newcallerid'
|
385
|
+
when 'newchannel'
|
386
|
+
when 'newexten'
|
387
|
+
when 'newstate'
|
388
|
+
when 'parkedcall'
|
389
|
+
when 'rename'
|
390
|
+
when 'setcdruserfield'
|
391
|
+
when 'unlink'
|
392
|
+
when 'unparkedcall'
|
393
|
+
else
|
394
|
+
ahn_log.ami.debug "Unprocessed AMI event: #{event.inspect}"
|
395
|
+
return
|
396
|
+
end
|
397
|
+
#publish pubsub_node, { pubsub_item_id => pubsub_payload }
|
398
|
+
ahn_log.ami.debug "AMI Event Received. Identified as type: #{event.name.downcase}.\n Event: #{event}\n PubSub Payload:#{pubsub_payload}"
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
end
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adhearsion-xmpp-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ben Langfeld
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-10 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thoughtbot-shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: adhearsion
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 53
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 8
|
47
|
+
- 5
|
48
|
+
version: 0.8.5
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Control calls in real time via XMPP Ad-Hoc Commands and PubSub
|
52
|
+
email: ben@langfeld.me
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE
|
59
|
+
- README.markdown
|
60
|
+
files:
|
61
|
+
- lib/adhearsion-xmpp-api.rb
|
62
|
+
- lib/adhearsion-xmpp-api/active_call_stanza.rb
|
63
|
+
- lib/adhearsion-xmpp-api/call.rb
|
64
|
+
- lib/adhearsion-xmpp-api/controller.rb
|
65
|
+
- LICENSE
|
66
|
+
- README.markdown
|
67
|
+
- test/helper.rb
|
68
|
+
- test/test_adhearsion-xmpp-api.rb
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: http://benlangfeld.github.com/adhearsion-xmpp-api
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options:
|
75
|
+
- --charset=UTF-8
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project: adhearsion-xmpp-api
|
99
|
+
rubygems_version: 1.3.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Adhearsion call control via XMPP
|
103
|
+
test_files:
|
104
|
+
- test/helper.rb
|
105
|
+
- test/test_adhearsion-xmpp-api.rb
|