librevox 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +21 -2
- data/lib/librevox/listener/base.rb +14 -11
- data/lib/librevox/listener/outbound.rb +8 -7
- data/lib/librevox.rb +1 -1
- data/librevox.gemspec +2 -2
- data/spec/librevox/listener/spec_outbound.rb +28 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -124,13 +124,32 @@ Multiple listeners can be started at once by passing a block to `Librevox.start`
|
|
124
124
|
run OtherListener, :port => "8080"
|
125
125
|
end
|
126
126
|
|
127
|
+
## Closing connection
|
128
|
+
|
129
|
+
After a session has finished, e.g. because the calling part hangs up, an
|
130
|
+
outbound socket still has its connection to FreeSWITCH open, so we can get post-
|
131
|
+
session events. Therefore it is important that you close the connection manually
|
132
|
+
when you are done. Otherwise you will have 'hanging' sessions, cloggering up
|
133
|
+
your system. This can safely be done with `close_connection_after_writing`,
|
134
|
+
which will wait for all outgoing data to be send before closing the connection.
|
135
|
+
It is aliased as `done` for convenience.
|
136
|
+
|
137
|
+
Unless you are doing something specific, closing the connection on CHANNEL_HANGUP
|
138
|
+
is most likely sufficient:
|
139
|
+
|
140
|
+
class MyListener < Librevox::Listener::Outbound
|
141
|
+
event :channel_hangup do
|
142
|
+
done
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
127
146
|
## Using `Librevox::CommandSocket`
|
128
147
|
|
129
148
|
Librevox also ships with a CommandSocket class, which allows you to connect
|
130
149
|
to the FreeSWITCH management console, from which you can originate calls,
|
131
150
|
restart FreeSWITCH etc.
|
132
151
|
|
133
|
-
>> require `librevox`
|
152
|
+
>> require `librevox/command_socket`
|
134
153
|
=> true
|
135
154
|
|
136
155
|
>> socket = Librevox::CommandSocket.new
|
@@ -158,7 +177,7 @@ the `Librevox::Commands` and `Librevox::Applications` modules.
|
|
158
177
|
|
159
178
|
## License
|
160
179
|
|
161
|
-
(c) 2009 Harry Vangberg <harry@vangberg.name>
|
180
|
+
(c) 2009, 2010 Harry Vangberg <harry@vangberg.name>
|
162
181
|
|
163
182
|
Librevox was inspired by and uses code from Freeswitcher, which is distributed
|
164
183
|
under the MIT license and (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel,
|
@@ -10,7 +10,7 @@ module Librevox
|
|
10
10
|
@hooks ||= []
|
11
11
|
end
|
12
12
|
|
13
|
-
def event
|
13
|
+
def event event, &block
|
14
14
|
hooks << [event, block]
|
15
15
|
end
|
16
16
|
end
|
@@ -23,20 +23,20 @@ module Librevox
|
|
23
23
|
class CommandDelegate
|
24
24
|
include Librevox::Commands
|
25
25
|
|
26
|
-
def initialize
|
26
|
+
def initialize listener
|
27
27
|
@listener = listener
|
28
28
|
end
|
29
29
|
|
30
|
-
def run_cmd
|
30
|
+
def run_cmd *args, &block
|
31
31
|
@listener.run_cmd *args, &block
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def api
|
35
|
+
def api cmd, *args, &block
|
36
36
|
@command_delegate.send(cmd, *args, &block)
|
37
37
|
end
|
38
38
|
|
39
|
-
def run_cmd
|
39
|
+
def run_cmd cmd, &block
|
40
40
|
send_data "#{cmd}\n\n"
|
41
41
|
@command_queue << (block || lambda {})
|
42
42
|
end
|
@@ -49,19 +49,22 @@ module Librevox
|
|
49
49
|
@command_queue = []
|
50
50
|
end
|
51
51
|
|
52
|
-
def receive_request
|
52
|
+
def receive_request header, content
|
53
53
|
@response = Librevox::Response.new(header, content)
|
54
|
+
handle_response
|
55
|
+
end
|
54
56
|
|
55
|
-
|
57
|
+
def handle_response
|
58
|
+
if response.api_response? && @command_queue.any?
|
59
|
+
invoke_command_queue
|
60
|
+
elsif response.event?
|
56
61
|
on_event response.dup
|
57
62
|
invoke_event_hooks
|
58
|
-
elsif response.api_response? && @command_queue.any?
|
59
|
-
invoke_command_queue
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
63
66
|
# override
|
64
|
-
def on_event
|
67
|
+
def on_event event
|
65
68
|
end
|
66
69
|
|
67
70
|
alias :done :close_connection_after_writing
|
@@ -77,7 +80,7 @@ module Librevox
|
|
77
80
|
|
78
81
|
def invoke_command_queue
|
79
82
|
block = @command_queue.shift
|
80
|
-
block.call
|
83
|
+
block.call response
|
81
84
|
end
|
82
85
|
end
|
83
86
|
end
|
@@ -6,7 +6,7 @@ module Librevox
|
|
6
6
|
class Outbound < Base
|
7
7
|
include Librevox::Applications
|
8
8
|
|
9
|
-
def execute_app
|
9
|
+
def execute_app app, args="", params={}, &block
|
10
10
|
msg = "sendmsg\n"
|
11
11
|
msg << "call-command: execute\n"
|
12
12
|
msg << "execute-app-name: #{app}\n"
|
@@ -24,7 +24,7 @@ module Librevox
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# This should probably be in Application#sendmsg instead.
|
27
|
-
def sendmsg
|
27
|
+
def sendmsg msg
|
28
28
|
send_data "sendmsg\n%s" % msg
|
29
29
|
end
|
30
30
|
|
@@ -46,9 +46,7 @@ module Librevox
|
|
46
46
|
@application_queue << lambda {}
|
47
47
|
end
|
48
48
|
|
49
|
-
def
|
50
|
-
super(*args)
|
51
|
-
|
49
|
+
def handle_response
|
52
50
|
if session.nil?
|
53
51
|
@session = response.headers
|
54
52
|
session_initiated
|
@@ -58,6 +56,8 @@ module Librevox
|
|
58
56
|
elsif response.command_reply? && !response.event?
|
59
57
|
@application_queue.shift.call if @application_queue.any?
|
60
58
|
end
|
59
|
+
|
60
|
+
super
|
61
61
|
end
|
62
62
|
|
63
63
|
def resume_with_channel_var
|
@@ -68,8 +68,9 @@ module Librevox
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
def update_session
|
72
|
-
send_data
|
71
|
+
def update_session &block
|
72
|
+
send_data "api uuid_dump #{session[:unique_id]}\n\n"
|
73
|
+
@command_queue << (block || lambda {})
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
data/lib/librevox.rb
CHANGED
data/librevox.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "librevox"
|
3
|
-
s.version = "0.2"
|
4
|
-
s.date = "2010-
|
3
|
+
s.version = "0.2.1"
|
4
|
+
s.date = "2010-02-09"
|
5
5
|
s.summary = "Ruby library for interacting with FreeSWITCH."
|
6
6
|
s.email = "harry@vangberg.name"
|
7
7
|
s.homepage = "http://github.com/ichverstehe/librevox"
|
@@ -135,7 +135,7 @@ describe "Outbound listener with app reading data" do
|
|
135
135
|
|
136
136
|
should "update session with new data" do
|
137
137
|
@listener.receive_data("Content-Type: command/reply\nContent-Length: 3\n\n+OK\n\n")
|
138
|
-
@listener.receive_data("Content-Type:
|
138
|
+
@listener.receive_data("Content-Type: api/response\nContent-Length: 44\n\nEvent-Name: CHANNEL_DATA\nSession-Var: Second\n\n")
|
139
139
|
@listener.session[:session_var].should == "Second"
|
140
140
|
end
|
141
141
|
|
@@ -219,3 +219,30 @@ describe "Outbound listener with both apps and api calls" do
|
|
219
219
|
@listener.read_data.should == "sendmsg\ncall-command: execute\nexecute-app-name: baz\n\n"
|
220
220
|
end
|
221
221
|
end
|
222
|
+
|
223
|
+
class OutboundListenerWithUpdateSessionCallback < Librevox::Listener::Outbound
|
224
|
+
def session_initiated
|
225
|
+
update_session do
|
226
|
+
send_data "yay, #{session[:session_var]}"
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "Outbound listener with update session callback" do
|
232
|
+
before do
|
233
|
+
@listener = OutboundListenerWithUpdateSessionCallback.new(nil)
|
234
|
+
@listener.receive_data("Content-Type: command/reply\nSession-Var: First\nUnique-ID: 1234\n\n")
|
235
|
+
receive_event_and_linger_replies
|
236
|
+
3.times {@listener.outgoing_data.shift}
|
237
|
+
|
238
|
+
@listener.receive_data("Content-Type: api/response\nContent-Length: 44\n\nEvent-Name: CHANNEL_DATA\nSession-Var: Second\n\n")
|
239
|
+
end
|
240
|
+
|
241
|
+
should "execute callback" do
|
242
|
+
@listener.read_data.should =~ /^yay,/
|
243
|
+
end
|
244
|
+
|
245
|
+
should "update session before calling callback" do
|
246
|
+
@listener.read_data.should == "yay, Second"
|
247
|
+
end
|
248
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: librevox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harry Vangberg
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-02-09 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
requirements: []
|
62
62
|
|
63
63
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.3.
|
64
|
+
rubygems_version: 1.3.5
|
65
65
|
signing_key:
|
66
66
|
specification_version: 3
|
67
67
|
summary: Ruby library for interacting with FreeSWITCH.
|