librevox 0.3 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +2 -1
- data/README.md +23 -17
- data/TODO +4 -0
- data/lib/librevox.rb +1 -1
- data/lib/librevox/applications.rb +38 -38
- data/lib/librevox/commands.rb +14 -14
- data/lib/librevox/listener/base.rb +5 -8
- data/lib/librevox/listener/outbound.rb +12 -12
- data/lib/librevox/response.rb +1 -1
- data/librevox.gemspec +3 -6
- data/spec/helper.rb +5 -5
- data/spec/librevox/listener.rb +7 -5
- data/spec/librevox/listener/spec_outbound.rb +25 -18
- data/spec/librevox/spec_response.rb +6 -0
- metadata +30 -77
data/LICENSE
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
(c) 2009, 2010, 2011 Harry Vangberg <harry@vangberg.name>
|
2
|
+
(c) 2011, 2012 Firmafon ApS <info@firmafon.dk>
|
2
3
|
|
3
4
|
Permission is hereby granted, free of charge, to any person
|
4
5
|
obtaining a copy of this software and associated documentation
|
data/README.md
CHANGED
@@ -17,8 +17,7 @@ outbound event sockets before proceeding. The
|
|
17
17
|
[wiki page on mod_event_socket](http://wiki.freeswitch.org/wiki/Event_Socket) is
|
18
18
|
a good place to start.
|
19
19
|
|
20
|
-
Librevox
|
21
|
-
This is because Librevox uses 1.9-only features such as fibers.
|
20
|
+
Librevox is Ruby 1.9-only.
|
22
21
|
|
23
22
|
## Inbound listener
|
24
23
|
|
@@ -75,10 +74,13 @@ When a call is made and Freeswitch connects to the outbound event listener,
|
|
75
74
|
`session_initiated` is called. This is where you set up your dialplan:
|
76
75
|
|
77
76
|
def session_initiated
|
78
|
-
answer
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
answer do
|
78
|
+
set "some_var", "some value" do
|
79
|
+
playback "path/to/file" do
|
80
|
+
hangup
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
82
84
|
end
|
83
85
|
|
84
86
|
All channel variables are available as a hash named `session`.
|
@@ -88,20 +90,23 @@ you have to use callbacks to read the value, as the function itself returns
|
|
88
90
|
immediately due to the async nature of EventMachine:
|
89
91
|
|
90
92
|
def session_initiated
|
91
|
-
answer
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
answer do
|
94
|
+
play_and_get_digits "enter-number.wav", "error.wav" do |digit|
|
95
|
+
puts "User pressed #{digit}"
|
96
|
+
playback "thanks-for-the-input.wav" do
|
97
|
+
hangup
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
97
101
|
end
|
98
102
|
|
99
103
|
You can also use the commands defined in `Librevox::Command`, which, to avoid
|
100
104
|
namespace clashes, are accessed through the `api` object:
|
101
105
|
|
102
106
|
def session_initiated
|
103
|
-
answer
|
104
|
-
|
107
|
+
answer do
|
108
|
+
api.status
|
109
|
+
end
|
105
110
|
end
|
106
111
|
|
107
112
|
They can be used in conjunction with applications, and do also take a block,
|
@@ -171,14 +176,15 @@ the `Librevox::Commands` and `Librevox::Applications` modules.
|
|
171
176
|
|
172
177
|
## Extras
|
173
178
|
|
174
|
-
* Source: [http://github.com/
|
175
|
-
* API docs: [http://rdoc.info/projects/
|
179
|
+
* Source: [http://github.com/vangberg/librevox](http://github.com/vangberg/librevox)
|
180
|
+
* API docs: [http://rdoc.info/projects/vangberg/librevox](http://rdoc.info/projects/vangberg/librevox)
|
176
181
|
* Mailing list: librevox@librelist.com
|
177
182
|
* IRC: #librevox @ irc.freenode.net
|
178
183
|
|
179
184
|
## License
|
180
185
|
|
181
|
-
(c) 2009, 2010 Harry Vangberg <harry@vangberg.name>
|
186
|
+
(c) 2009, 2010, 2011 Harry Vangberg <harry@vangberg.name>
|
187
|
+
(c) 2011, 2012 Firmafon ApS <info@firmafon.dk>
|
182
188
|
|
183
189
|
Librevox was inspired by and uses code from Freeswitcher, which is distributed
|
184
190
|
under the MIT license and (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel,
|
data/TODO
CHANGED
data/lib/librevox.rb
CHANGED
@@ -8,8 +8,8 @@ module Librevox
|
|
8
8
|
module Applications
|
9
9
|
# Answers an incoming call or session.
|
10
10
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_answer
|
11
|
-
def answer
|
12
|
-
application "answer"
|
11
|
+
def answer &block
|
12
|
+
application "answer", &block
|
13
13
|
end
|
14
14
|
|
15
15
|
# Make an attended transfer
|
@@ -17,8 +17,8 @@ module Librevox
|
|
17
17
|
# att_xfer("user/davis")
|
18
18
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_att_xfer
|
19
19
|
# @todo Add support for origination_cancel_key
|
20
|
-
def att_xfer endpoint
|
21
|
-
application "att_xfer", endpoint
|
20
|
+
def att_xfer endpoint, &block
|
21
|
+
application "att_xfer", endpoint, &block
|
22
22
|
end
|
23
23
|
|
24
24
|
# Binds an application to the specified call legs.
|
@@ -29,12 +29,12 @@ module Librevox
|
|
29
29
|
# :application => "execute_extension",
|
30
30
|
# :parameters => "dx XML features"
|
31
31
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_bind_meta_app
|
32
|
-
def bind_meta_app args={}
|
32
|
+
def bind_meta_app args={}, &block
|
33
33
|
arg_string =
|
34
34
|
args.values_at(:key, :listen_to, :respond_on, :application).join(" ")
|
35
35
|
arg_string += "::#{args[:parameters]}" if args[:parameters]
|
36
36
|
|
37
|
-
application "bind_meta_app", arg_string
|
37
|
+
application "bind_meta_app", arg_string, &block
|
38
38
|
end
|
39
39
|
|
40
40
|
|
@@ -53,7 +53,7 @@ module Librevox
|
|
53
53
|
# bridge ['user/coltrane', 'user/davis'], ['user/sun-ra', 'user/taylor']
|
54
54
|
# #=> user/coltrane,user/davis|user/sun-ra,user/taylor
|
55
55
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_bridge
|
56
|
-
def bridge *args
|
56
|
+
def bridge *args, &block
|
57
57
|
variables = if args.last.is_a? Hash
|
58
58
|
# We need to sort the key/value pairs to facilitate testing.
|
59
59
|
# This can be removed once 1.8-compat is dropped.
|
@@ -70,7 +70,7 @@ module Librevox
|
|
70
70
|
args.join ","
|
71
71
|
end
|
72
72
|
|
73
|
-
application "bridge", variables + endpoints
|
73
|
+
application "bridge", variables + endpoints, &block
|
74
74
|
end
|
75
75
|
|
76
76
|
# Deflect a call by sending a REFER. Takes a SIP URI as argument, rerouting
|
@@ -83,8 +83,8 @@ module Librevox
|
|
83
83
|
# deflect "sip:miles@davis.com"
|
84
84
|
# @see #redirect
|
85
85
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_deflect
|
86
|
-
def deflect uri
|
87
|
-
application "deflect", uri
|
86
|
+
def deflect uri, &block
|
87
|
+
application "deflect", uri, &block
|
88
88
|
end
|
89
89
|
|
90
90
|
# Exports a channel variable from the A leg to the B leg. Variables and
|
@@ -98,10 +98,10 @@ module Librevox
|
|
98
98
|
# @example Only export to B-leg
|
99
99
|
# export "some_var", :local => false
|
100
100
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_export
|
101
|
-
def export var, args={}
|
101
|
+
def export var, args={}, &block
|
102
102
|
nolocal = args[:local] == false ? "nolocal:" : "" # ugly!!111
|
103
103
|
|
104
|
-
application "export", "#{nolocal}#{var}"
|
104
|
+
application "export", "#{nolocal}#{var}", &block
|
105
105
|
end
|
106
106
|
|
107
107
|
# Generate TGML tones
|
@@ -110,8 +110,8 @@ module Librevox
|
|
110
110
|
# @example Generate a DTMF string
|
111
111
|
# gentones "0800500005"
|
112
112
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_gentones
|
113
|
-
def gentones tgml
|
114
|
-
application "gentones", tgml
|
113
|
+
def gentones tgml , &block
|
114
|
+
application "gentones", tgml, &block
|
115
115
|
end
|
116
116
|
|
117
117
|
# Hang up current channel
|
@@ -120,8 +120,8 @@ module Librevox
|
|
120
120
|
# @example Hang up with a reason
|
121
121
|
# hangup "USER_BUSY"
|
122
122
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_hangup
|
123
|
-
def hangup cause=""
|
124
|
-
application "hangup", cause
|
123
|
+
def hangup cause="", &block
|
124
|
+
application "hangup", cause, &block
|
125
125
|
end
|
126
126
|
|
127
127
|
# Plays a sound file and reads DTMF presses.
|
@@ -134,7 +134,7 @@ module Librevox
|
|
134
134
|
# :timeout => 5000,
|
135
135
|
# :regexp => '\d+'
|
136
136
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_play_and_get_digits
|
137
|
-
def play_and_get_digits file, invalid_file, args={}
|
137
|
+
def play_and_get_digits file, invalid_file, args={}, &block
|
138
138
|
min = args[:min] || 1
|
139
139
|
max = args[:max] || 2
|
140
140
|
tries = args[:tries] || 3
|
@@ -148,27 +148,27 @@ module Librevox
|
|
148
148
|
|
149
149
|
params = {:variable => variable}
|
150
150
|
|
151
|
-
application "play_and_get_digits", args, params
|
151
|
+
application "play_and_get_digits", args, params, &block
|
152
152
|
end
|
153
153
|
|
154
154
|
# Plays a sound file on the current channel.
|
155
155
|
# @example
|
156
156
|
# playback "/path/to/file.wav"
|
157
157
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_playback
|
158
|
-
def playback file
|
159
|
-
application "playback", file
|
158
|
+
def playback file, &block
|
159
|
+
application "playback", file, &block
|
160
160
|
end
|
161
161
|
|
162
162
|
# Pre-answer establishes early media but does not answer.
|
163
163
|
# @example
|
164
164
|
# pre_anser
|
165
165
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_pre_answer
|
166
|
-
def pre_answer
|
167
|
-
application "pre_answer"
|
166
|
+
def pre_answer &block
|
167
|
+
application "pre_answer", &block
|
168
168
|
end
|
169
169
|
|
170
170
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_read
|
171
|
-
def read file, args={}
|
171
|
+
def read file, args={}, &block
|
172
172
|
min = args[:min] || 1
|
173
173
|
max = args[:max] || 2
|
174
174
|
terminators = args[:terminators] || "#"
|
@@ -180,7 +180,7 @@ module Librevox
|
|
180
180
|
|
181
181
|
params = {:variable => variable}
|
182
182
|
|
183
|
-
application "read", arg_string, params
|
183
|
+
application "read", arg_string, params, &block
|
184
184
|
end
|
185
185
|
|
186
186
|
# Records a message, with an optional limit on the maximum duration of the
|
@@ -190,9 +190,9 @@ module Librevox
|
|
190
190
|
# @example With 20 second limit
|
191
191
|
# record "/path/to/new/file.wac", :limit => 20
|
192
192
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_record
|
193
|
-
def record path, params={}
|
193
|
+
def record path, params={}, &block
|
194
194
|
args = [path, params[:limit]].compact.join(" ")
|
195
|
-
application "record", args
|
195
|
+
application "record", args, &block
|
196
196
|
end
|
197
197
|
|
198
198
|
# Redirect a channel to another endpoint. You must take care to not
|
@@ -206,48 +206,48 @@ module Librevox
|
|
206
206
|
# redirect "sip:freddie@hubbard.org"
|
207
207
|
# @see #deflect
|
208
208
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_redirect
|
209
|
-
def redirect uri
|
210
|
-
application "redirect", uri
|
209
|
+
def redirect uri, &block
|
210
|
+
application "redirect", uri, &block
|
211
211
|
end
|
212
212
|
|
213
213
|
# Send SIP session respond code.
|
214
214
|
# @example Send 403 Forbidden
|
215
215
|
# respond 403
|
216
216
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_respond
|
217
|
-
def respond code
|
218
|
-
application "respond", code.to_s
|
217
|
+
def respond code, &block
|
218
|
+
application "respond", code.to_s, &block
|
219
219
|
end
|
220
220
|
|
221
221
|
# Sets a channel variable.
|
222
222
|
# @example
|
223
223
|
# set "some_var", "some value"
|
224
224
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_set
|
225
|
-
def set variable, value
|
226
|
-
application "set", "#{variable}=#{value}"
|
225
|
+
def set variable, value, &block
|
226
|
+
application "set", "#{variable}=#{value}", &block
|
227
227
|
end
|
228
228
|
|
229
229
|
# Transfers the current channel to a new context.
|
230
230
|
# @example
|
231
231
|
# transfer "new_context"
|
232
232
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_transfer
|
233
|
-
def transfer context
|
234
|
-
application "transfer", context
|
233
|
+
def transfer context, &block
|
234
|
+
application "transfer", context, &block
|
235
235
|
end
|
236
236
|
|
237
237
|
# Unbinds a previously bound key with bind_meta_app
|
238
238
|
# @example
|
239
239
|
# unbind_meta_app 3
|
240
240
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_unbind_meta_app
|
241
|
-
def unbind_meta_app key
|
242
|
-
application "unbind_meta_app", key.to_s
|
241
|
+
def unbind_meta_app key, &block
|
242
|
+
application "unbind_meta_app", key.to_s, &block
|
243
243
|
end
|
244
244
|
|
245
245
|
# Unset a channel variable.
|
246
246
|
# @example
|
247
247
|
# unset "foo"
|
248
248
|
# @see http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_unset
|
249
|
-
def unset variable
|
250
|
-
application "unset", variable
|
249
|
+
def unset variable, &block
|
250
|
+
application "unset", variable, &block
|
251
251
|
end
|
252
252
|
end
|
253
253
|
end
|
data/lib/librevox/commands.rb
CHANGED
@@ -16,8 +16,8 @@ module Librevox
|
|
16
16
|
msg
|
17
17
|
end
|
18
18
|
|
19
|
-
def status
|
20
|
-
command "status"
|
19
|
+
def status &block
|
20
|
+
command "status", &block
|
21
21
|
end
|
22
22
|
|
23
23
|
# Access the hash table that comes with FreeSWITCH.
|
@@ -25,8 +25,8 @@ module Librevox
|
|
25
25
|
# socket.hash :insert, :realm, :key, "value"
|
26
26
|
# socket.hash :select, :realm, :key
|
27
27
|
# socket.hash :delete, :realm, :key
|
28
|
-
def hash *args
|
29
|
-
command "hash", args.join("/")
|
28
|
+
def hash *args, &block
|
29
|
+
command "hash", args.join("/"), &block
|
30
30
|
end
|
31
31
|
|
32
32
|
# Originate a new call.
|
@@ -34,7 +34,7 @@ module Librevox
|
|
34
34
|
# socket.originate 'sofia/user/coltrane', :extension => "1234"
|
35
35
|
# @example With :dialplan and :context
|
36
36
|
# @see http://wiki.freeswitch.org/wiki/Mod_commands#originate
|
37
|
-
def originate url, args={}
|
37
|
+
def originate url, args={}, &block
|
38
38
|
extension = args.delete(:extension)
|
39
39
|
dialplan = args.delete(:dialplan)
|
40
40
|
context = args.delete(:context)
|
@@ -43,35 +43,35 @@ module Librevox
|
|
43
43
|
|
44
44
|
arg_string = "{#{vars}}" +
|
45
45
|
[url, extension, dialplan, context].compact.join(" ")
|
46
|
-
command "originate", arg_string
|
46
|
+
command "originate", arg_string, &block
|
47
47
|
end
|
48
48
|
|
49
49
|
# FreeSWITCH control messages.
|
50
50
|
# @example
|
51
51
|
# socket.fsctl :hupall, :normal_clearing
|
52
52
|
# @see http://wiki.freeswitch.org/wiki/Mod_commands#fsctl
|
53
|
-
def fsctl *args
|
54
|
-
command "fsctl", args.join(" ")
|
53
|
+
def fsctl *args, &block
|
54
|
+
command "fsctl", args.join(" "), &block
|
55
55
|
end
|
56
56
|
|
57
|
-
def hupall cause=nil
|
58
|
-
command "hupall", cause
|
57
|
+
def hupall cause=nil, &block
|
58
|
+
command "hupall", cause, &block
|
59
59
|
end
|
60
60
|
|
61
61
|
# Park call.
|
62
62
|
# @example
|
63
63
|
# socket.uuid_park "592567a2-1be4-11df-a036-19bfdab2092f"
|
64
64
|
# @see http://wiki.freeswitch.org/wiki/Mod_commands#uuid_park
|
65
|
-
def uuid_park uuid
|
66
|
-
command "uuid_park", uuid
|
65
|
+
def uuid_park uuid, &block
|
66
|
+
command "uuid_park", uuid, &block
|
67
67
|
end
|
68
68
|
|
69
69
|
# Bridge two call legs together. At least one leg must be anwered.
|
70
70
|
# @example
|
71
71
|
# socket.uuid_bridge "592567a2-1be4-11df-a036-19bfdab2092f", "58b39c3a-1be4-11df-a035-19bfdab2092f"
|
72
72
|
# @see http://wiki.freeswitch.org/wiki/Mod_commands#uuid_bridge
|
73
|
-
def uuid_bridge uuid1, uuid2
|
74
|
-
command "uuid_bridge", "#{uuid1} #{uuid2}"
|
73
|
+
def uuid_bridge uuid1, uuid2, &block
|
74
|
+
command "uuid_bridge", "#{uuid1} #{uuid2}", &block
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
@@ -41,11 +41,10 @@ module Librevox
|
|
41
41
|
@command_delegate ||= CommandDelegate.new(self)
|
42
42
|
end
|
43
43
|
|
44
|
-
def command msg
|
44
|
+
def command msg, &block
|
45
45
|
send_data "#{msg}\n\n"
|
46
46
|
|
47
|
-
@command_queue
|
48
|
-
Fiber.yield
|
47
|
+
@command_queue.push(block)
|
49
48
|
end
|
50
49
|
|
51
50
|
attr_accessor :response
|
@@ -62,11 +61,11 @@ module Librevox
|
|
62
61
|
|
63
62
|
def handle_response
|
64
63
|
if response.api_response? && @command_queue.any?
|
65
|
-
@command_queue.shift.
|
64
|
+
@command_queue.shift.call(response)
|
66
65
|
end
|
67
66
|
|
68
67
|
if response.event?
|
69
|
-
|
68
|
+
on_event(response.dup)
|
70
69
|
invoke_event_hooks
|
71
70
|
end
|
72
71
|
end
|
@@ -81,9 +80,7 @@ module Librevox
|
|
81
80
|
def invoke_event_hooks
|
82
81
|
event = response.event.downcase.to_sym
|
83
82
|
self.class.hooks[event].each {|block|
|
84
|
-
|
85
|
-
instance_exec response.dup, &block
|
86
|
-
}.resume
|
83
|
+
instance_exec(response.dup, &block)
|
87
84
|
}
|
88
85
|
end
|
89
86
|
end
|
@@ -6,7 +6,7 @@ module Librevox
|
|
6
6
|
class Outbound < Base
|
7
7
|
include Librevox::Applications
|
8
8
|
|
9
|
-
def application app, args=nil, params={}
|
9
|
+
def application app, args=nil, params={}, &block
|
10
10
|
msg = "sendmsg\n"
|
11
11
|
msg << "call-command: execute\n"
|
12
12
|
msg << "execute-app-name: #{app}\n"
|
@@ -14,12 +14,12 @@ module Librevox
|
|
14
14
|
|
15
15
|
send_data "#{msg}\n"
|
16
16
|
|
17
|
-
@application_queue
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
@application_queue.push(proc {
|
18
|
+
update_session do
|
19
|
+
arg = params[:variable] ? variable(params[:variable]) : nil
|
20
|
+
block.call(arg) if block
|
21
|
+
end
|
22
|
+
})
|
23
23
|
end
|
24
24
|
|
25
25
|
# This should probably be in Application#sendmsg instead.
|
@@ -40,9 +40,9 @@ module Librevox
|
|
40
40
|
|
41
41
|
send_data "connect\n\n"
|
42
42
|
send_data "myevents\n\n"
|
43
|
-
@application_queue <<
|
43
|
+
@application_queue << proc {}
|
44
44
|
send_data "linger\n\n"
|
45
|
-
@application_queue <<
|
45
|
+
@application_queue << proc {session_initiated}
|
46
46
|
end
|
47
47
|
|
48
48
|
def handle_response
|
@@ -51,7 +51,7 @@ module Librevox
|
|
51
51
|
elsif response.event? && response.event == "CHANNEL_DATA"
|
52
52
|
@session = response.content
|
53
53
|
elsif response.command_reply? && !response.event?
|
54
|
-
@application_queue.shift.
|
54
|
+
@application_queue.shift.call(response) if @application_queue.any?
|
55
55
|
end
|
56
56
|
|
57
57
|
super
|
@@ -61,8 +61,8 @@ module Librevox
|
|
61
61
|
session[:"variable_#{name}"]
|
62
62
|
end
|
63
63
|
|
64
|
-
def update_session
|
65
|
-
api.command "uuid_dump", session[:unique_id]
|
64
|
+
def update_session &block
|
65
|
+
api.command "uuid_dump", session[:unique_id], &block
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
data/lib/librevox/response.rb
CHANGED
@@ -20,7 +20,7 @@ module Librevox
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def content= content
|
23
|
-
@content = content.match(/:/) ? headers_2_hash(content) : content
|
23
|
+
@content = content.respond_to?(:match) && content.match(/:/) ? headers_2_hash(content) : content
|
24
24
|
@content.each {|k,v| v.chomp! if v.is_a?(String)}
|
25
25
|
end
|
26
26
|
|
data/librevox.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "librevox"
|
3
|
-
s.version = "0.
|
4
|
-
s.date = "
|
3
|
+
s.version = "0.5"
|
4
|
+
s.date = "2012-06-27"
|
5
5
|
s.summary = "Ruby library for interacting with FreeSWITCH."
|
6
6
|
s.email = "harry@vangberg.name"
|
7
|
-
s.homepage = "http://github.com/
|
7
|
+
s.homepage = "http://github.com/vangberg/librevox"
|
8
8
|
s.description = "EventMachine-based Ruby library for interacting with the
|
9
9
|
open source telephony platform FreeSwitch."
|
10
10
|
s.authors = ["Harry Vangberg"]
|
@@ -34,7 +34,4 @@ open source telephony platform FreeSwitch."
|
|
34
34
|
"spec/librevox/listener/spec_outbound.rb"
|
35
35
|
]
|
36
36
|
s.add_dependency "eventmachine", "~> 0.12.10"
|
37
|
-
s.add_development_dependency "bacon", "~> 1.1"
|
38
|
-
s.add_development_dependency "rr", "~> 1"
|
39
37
|
end
|
40
|
-
|
data/spec/helper.rb
CHANGED
@@ -4,17 +4,17 @@ require 'librevox'
|
|
4
4
|
module Librevox::Test
|
5
5
|
module Matchers
|
6
6
|
def send_command command
|
7
|
-
|
7
|
+
proc {|obj|
|
8
8
|
obj.outgoing_data.shift.should == "#{command}\n\n"
|
9
9
|
}
|
10
10
|
end
|
11
11
|
|
12
12
|
def send_nothing
|
13
|
-
|
13
|
+
proc {|obj| obj.outgoing_data.shift.should == nil}
|
14
14
|
end
|
15
15
|
|
16
16
|
def send_application app, args=nil
|
17
|
-
|
17
|
+
proc {|obj|
|
18
18
|
msg = <<-EOM
|
19
19
|
sendmsg
|
20
20
|
call-command: execute
|
@@ -29,11 +29,11 @@ execute-app-name: #{app}
|
|
29
29
|
|
30
30
|
def update_session session_id=nil
|
31
31
|
if session_id
|
32
|
-
|
32
|
+
proc {|obj|
|
33
33
|
obj.outgoing_data.shift.should == "api uuid_dump #{session_id}\n\n"
|
34
34
|
}
|
35
35
|
else
|
36
|
-
|
36
|
+
proc {|obj|
|
37
37
|
obj.outgoing_data.shift.should.match /^api uuid_dump \d+/
|
38
38
|
}
|
39
39
|
end
|
data/spec/librevox/listener.rb
CHANGED
@@ -96,8 +96,8 @@ shared "events" do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
module Librevox::Commands
|
99
|
-
def sample_cmd cmd, args=""
|
100
|
-
command cmd, args
|
99
|
+
def sample_cmd cmd, args="", &block
|
100
|
+
command cmd, args, &block
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -118,9 +118,11 @@ shared "api commands" do
|
|
118
118
|
def @listener.on_event(e) end # Don't send anything, kthx.
|
119
119
|
|
120
120
|
@class.event(:api_test) {
|
121
|
-
api.sample_cmd "foo"
|
122
|
-
|
123
|
-
|
121
|
+
api.sample_cmd "foo" do
|
122
|
+
api.sample_cmd "foo", "bar baz" do |r|
|
123
|
+
command "response #{r.content}"
|
124
|
+
end
|
125
|
+
end
|
124
126
|
}
|
125
127
|
end
|
126
128
|
|
@@ -4,8 +4,8 @@ require './spec/librevox/listener'
|
|
4
4
|
require 'librevox/listener/outbound'
|
5
5
|
|
6
6
|
module Librevox::Applications
|
7
|
-
def sample_app name, *args
|
8
|
-
application name, args.join(" ")
|
7
|
+
def sample_app name, *args, &block
|
8
|
+
application name, args.join(" "), &block
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -61,8 +61,9 @@ end
|
|
61
61
|
|
62
62
|
class OutboundListenerWithNestedApps < Librevox::Listener::Outbound
|
63
63
|
def session_initiated
|
64
|
-
sample_app "foo"
|
65
|
-
|
64
|
+
sample_app "foo" do
|
65
|
+
sample_app "bar"
|
66
|
+
end
|
66
67
|
end
|
67
68
|
end
|
68
69
|
|
@@ -120,15 +121,16 @@ describe "Outbound listener with apps" do
|
|
120
121
|
end
|
121
122
|
|
122
123
|
module Librevox::Applications
|
123
|
-
def reader_app
|
124
|
-
application 'reader_app', "", {:variable => 'app_var'}
|
124
|
+
def reader_app &block
|
125
|
+
application 'reader_app', "", {:variable => 'app_var'}, &block
|
125
126
|
end
|
126
127
|
end
|
127
128
|
|
128
129
|
class OutboundListenerWithReader < Librevox::Listener::Outbound
|
129
130
|
def session_initiated
|
130
|
-
|
131
|
-
|
131
|
+
reader_app do |data|
|
132
|
+
application "send", data
|
133
|
+
end
|
132
134
|
end
|
133
135
|
end
|
134
136
|
|
@@ -183,9 +185,11 @@ end
|
|
183
185
|
class OutboundListenerWithNonNestedApps < Librevox::Listener::Outbound
|
184
186
|
attr_reader :queue
|
185
187
|
def session_initiated
|
186
|
-
sample_app "foo"
|
187
|
-
|
188
|
-
|
188
|
+
sample_app "foo" do
|
189
|
+
reader_app do |data|
|
190
|
+
application "send", "the end: #{data}"
|
191
|
+
end
|
192
|
+
end
|
189
193
|
end
|
190
194
|
end
|
191
195
|
|
@@ -221,16 +225,18 @@ describe "Outbound listener with non-nested apps" do
|
|
221
225
|
end
|
222
226
|
|
223
227
|
module Librevox::Commands
|
224
|
-
def sample_cmd cmd, *args
|
225
|
-
command cmd, *args
|
228
|
+
def sample_cmd cmd, *args, &block
|
229
|
+
command cmd, *args, &block
|
226
230
|
end
|
227
231
|
end
|
228
232
|
|
229
233
|
class OutboundListenerWithAppsAndApi < Librevox::Listener::Outbound
|
230
234
|
def session_initiated
|
231
|
-
sample_app "foo"
|
232
|
-
|
233
|
-
|
235
|
+
sample_app "foo" do
|
236
|
+
api.sample_cmd "bar" do
|
237
|
+
sample_app "baz"
|
238
|
+
end
|
239
|
+
end
|
234
240
|
end
|
235
241
|
end
|
236
242
|
|
@@ -261,8 +267,9 @@ end
|
|
261
267
|
|
262
268
|
class OutboundListenerWithUpdateSessionCallback < Librevox::Listener::Outbound
|
263
269
|
def session_initiated
|
264
|
-
update_session
|
265
|
-
|
270
|
+
update_session do
|
271
|
+
application "send", "yay, #{session[:session_var]}"
|
272
|
+
end
|
266
273
|
end
|
267
274
|
end
|
268
275
|
|
@@ -29,6 +29,12 @@ describe Response do
|
|
29
29
|
response.content.should.equal "OK."
|
30
30
|
end
|
31
31
|
|
32
|
+
should "allow setting content from a hash" do
|
33
|
+
response = Response.new
|
34
|
+
response.content = {:key => 'value'}
|
35
|
+
response.content.should.equal({:key => 'value'})
|
36
|
+
end
|
37
|
+
|
32
38
|
should "check for event" do
|
33
39
|
response = Response.new("Content-Type: command/reply", "Event-Name: Hangup")
|
34
40
|
response.event?.should.be.true
|
metadata
CHANGED
@@ -1,74 +1,35 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: librevox
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
version: "0.3"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.5'
|
5
|
+
prerelease:
|
9
6
|
platform: ruby
|
10
|
-
authors:
|
7
|
+
authors:
|
11
8
|
- Harry Vangberg
|
12
9
|
autorequire:
|
13
10
|
bindir: bin
|
14
11
|
cert_chain: []
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
dependencies:
|
19
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-06-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
20
15
|
name: eventmachine
|
21
|
-
|
22
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &22611600 !ruby/object:Gem::Requirement
|
23
17
|
none: false
|
24
|
-
requirements:
|
18
|
+
requirements:
|
25
19
|
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 12
|
30
|
-
- 10
|
20
|
+
- !ruby/object:Gem::Version
|
31
21
|
version: 0.12.10
|
32
22
|
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: bacon
|
36
|
-
prerelease: false
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
|
-
requirements:
|
40
|
-
- - ~>
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 1
|
44
|
-
- 1
|
45
|
-
version: "1.1"
|
46
|
-
type: :development
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: rr
|
50
23
|
prerelease: false
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
segments:
|
57
|
-
- 1
|
58
|
-
version: "1"
|
59
|
-
type: :development
|
60
|
-
version_requirements: *id003
|
61
|
-
description: |-
|
62
|
-
EventMachine-based Ruby library for interacting with the
|
63
|
-
open source telephony platform FreeSwitch.
|
24
|
+
version_requirements: *22611600
|
25
|
+
description: ! 'EventMachine-based Ruby library for interacting with the
|
26
|
+
|
27
|
+
open source telephony platform FreeSwitch.'
|
64
28
|
email: harry@vangberg.name
|
65
29
|
executables: []
|
66
|
-
|
67
30
|
extensions: []
|
68
|
-
|
69
31
|
extra_rdoc_files: []
|
70
|
-
|
71
|
-
files:
|
32
|
+
files:
|
72
33
|
- README.md
|
73
34
|
- LICENSE
|
74
35
|
- TODO
|
@@ -89,39 +50,31 @@ files:
|
|
89
50
|
- spec/librevox/spec_response.rb
|
90
51
|
- spec/librevox/listener/spec_inbound.rb
|
91
52
|
- spec/librevox/listener/spec_outbound.rb
|
92
|
-
|
93
|
-
homepage: http://github.com/ichverstehe/librevox
|
53
|
+
homepage: http://github.com/vangberg/librevox
|
94
54
|
licenses: []
|
95
|
-
|
96
55
|
post_install_message:
|
97
56
|
rdoc_options: []
|
98
|
-
|
99
|
-
require_paths:
|
57
|
+
require_paths:
|
100
58
|
- lib
|
101
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
60
|
none: false
|
103
|
-
requirements:
|
104
|
-
- -
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
|
107
|
-
|
108
|
-
version: "0"
|
109
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
66
|
none: false
|
111
|
-
requirements:
|
112
|
-
- -
|
113
|
-
- !ruby/object:Gem::Version
|
114
|
-
|
115
|
-
- 0
|
116
|
-
version: "0"
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
117
71
|
requirements: []
|
118
|
-
|
119
72
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.
|
73
|
+
rubygems_version: 1.8.11
|
121
74
|
signing_key:
|
122
75
|
specification_version: 3
|
123
76
|
summary: Ruby library for interacting with FreeSWITCH.
|
124
|
-
test_files:
|
77
|
+
test_files:
|
125
78
|
- spec/helper.rb
|
126
79
|
- spec/librevox/listener.rb
|
127
80
|
- spec/librevox/spec_applications.rb
|