bougyman-freeswitcher 0.1.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +0 -10
- data/CHANGELOG +123 -0
- data/MANIFEST +3 -9
- data/README +57 -60
- data/Rakefile +4 -4
- data/examples/outbound_event_socket.rb +2 -5
- data/freeswitcher.gemspec +62 -65
- data/lib/fsr/app.rb +1 -3
- data/lib/fsr/app/answer.rb +2 -0
- data/lib/fsr/app/play_and_get_digits.rb +11 -1
- data/lib/fsr/app/read.rb +12 -2
- data/lib/fsr/app/uuid_getvar.rb +13 -2
- data/lib/fsr/app/uuid_setvar.rb +11 -1
- data/lib/fsr/cmd.rb +22 -4
- data/lib/fsr/cmd/originate.rb +23 -6
- data/lib/fsr/command_socket.rb +1 -1
- data/lib/fsr/listener/inbound.rb +19 -10
- data/lib/fsr/listener/outbound.rb +75 -18
- data/lib/fsr/version.rb +1 -1
- data/spec/fsr/app/answer.rb +12 -0
- data/spec/fsr/app/fs_break.rb +12 -0
- data/spec/fsr/app/fs_sleep.rb +12 -0
- data/spec/fsr/cmd/originate.rb +32 -0
- metadata +62 -68
- data/examples/bin/cmd_demo.rb +0 -19
- data/examples/bin/dtmf_test.rb +0 -38
- data/examples/bin/ies_demo.rb +0 -19
- data/examples/bin/ies_demo_with_hook.rb +0 -25
- data/examples/bin/oes_demo.rb +0 -22
- data/examples/dtmf_test.rb +0 -35
- data/examples/ies_demo.rb +0 -19
- data/examples/ies_demo_with_hook.rb +0 -25
- data/lib/fsr/listener/outbound.rb.orig +0 -131
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
require "fsr/app"
|
3
|
+
FSR::App.load_application("fs_break")
|
4
|
+
|
5
|
+
describe "Testing FSR::App::FsBreak" do
|
6
|
+
|
7
|
+
it "should break a connection" do
|
8
|
+
fs_break = FSR::App::FSBreak.new
|
9
|
+
fs_break.sendmsg.should == "call-command: execute\nexecute-app-name: break\n\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
require "fsr/app"
|
3
|
+
FSR::App.load_application("fs_sleep")
|
4
|
+
|
5
|
+
describe "Testing FSR::App::FsSleep" do
|
6
|
+
|
7
|
+
it "should put FreeSWITCH leg to sleep for 7000 miliseconds" do
|
8
|
+
fs_sleep = FSR::App::FSSleep.new(7000)
|
9
|
+
fs_sleep.sendmsg.should == "call-command: execute\nexecute-app-name: sleep\nexecute-app-arg: 7000\n\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
data/spec/fsr/cmd/originate.rb
CHANGED
@@ -3,10 +3,42 @@ require "fsr/cmd"
|
|
3
3
|
FSR::Cmd.load_command("originate")
|
4
4
|
|
5
5
|
describe "Testing FSR::Cmd::Originate" do
|
6
|
+
# Invalid originates
|
7
|
+
it "Must be passed an argument hash" do
|
8
|
+
lambda { FSR::Cmd::Originate.new(nil, :endpoint) }.should.raise(ArgumentError).
|
9
|
+
message.should.match(/args \(Passed: <<<.*?>>>\) must be a hash/)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "Should require args[:target_options] to be a hash" do
|
13
|
+
lambda { FSR::Cmd::Originate.new(nil, :endpoint => "4000", :target => "user/bougyman", :target_options => 1) }.should.raise(ArgumentError).
|
14
|
+
message.should.match(/args\[:target_options\] \(Passed: <<<.*?>>>\) must be a hash/)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "Can not originate without a target" do
|
18
|
+
lambda { FSR::Cmd::Originate.new(nil, :endpoint => "4000") }.should.raise(ArgumentError).
|
19
|
+
message.should.match(/Cannot originate without a :target set/)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Can not originate without an endpoint" do
|
23
|
+
lambda { FSR::Cmd::Originate.new(nil, :target => "4000") }.should.raise(ArgumentError).
|
24
|
+
message.should.match(/Cannot originate without an :endpoint set/)
|
25
|
+
end
|
26
|
+
|
6
27
|
# Originate to an extension
|
7
28
|
it "Originates calls to extensions" do
|
8
29
|
originate = FSR::Cmd::Originate.new(nil, :target => "user/bougyman", :endpoint => "4000")
|
9
30
|
originate.raw.should == "originate {ignore_early_media=true,originate_timeout=30,origination_caller_id_name=FSR,origination_caller_id_number=8675309}user/bougyman 4000"
|
10
31
|
end
|
11
32
|
|
33
|
+
# Different options choices
|
34
|
+
it "Honors timeout in :timeout option" do
|
35
|
+
originate = FSR::Cmd::Originate.new(nil, :target => "user/bougyman", :timeout => 10, :endpoint => "4000")
|
36
|
+
originate.raw.should == "originate {ignore_early_media=true,originate_timeout=10,origination_caller_id_name=FSR,origination_caller_id_number=8675309}user/bougyman 4000"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "Honors timeout in :target_options[timeout] option" do
|
40
|
+
originate = FSR::Cmd::Originate.new(nil, :target => "user/bougyman", :target_options => {:timeout => 10}, :endpoint => "4000")
|
41
|
+
originate.raw.should == "originate {ignore_early_media=true,originate_timeout=10,origination_caller_id_name=FSR,origination_caller_id_number=8675309}user/bougyman 4000"
|
42
|
+
end
|
43
|
+
|
12
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bougyman-freeswitcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jayson Vaughn
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-05-
|
15
|
+
date: 2009-05-18 00:00:00 -07:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: "0"
|
27
27
|
version:
|
28
|
-
description: "========================================================= FreeSWITCHeR Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger, Kevin Berry) Distributed under the terms of the MIT License. ========================================================== ABOUT ----- A ruby library for interacting with the \"FreeSWITCH\" (http://www.freeswitch.org) opensource telephony platform REQUIREMENTS ------------
|
28
|
+
description: "========================================================= FreeSWITCHeR Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger, Kevin Berry) Distributed under the terms of the MIT License. ========================================================== ABOUT ----- A ruby library for interacting with the \"FreeSWITCH\" (http://www.freeswitch.org) opensource telephony platform REQUIREMENTS ------------ * ruby (>= 1.8) * eventmachine (If you wish to use Outbound and Inbound listener) USAGE ----- An Outbound Event Listener Example that reads and returns DTMF input: -------------------------------------------------------------------- Simply just create a subclass of FSR::Listner::Outbound and all new calls/sessions will invoke the \"session_initiated\" callback method. <b>NOTE</b>: FSR uses blocks within the 'session_inititated' method to ensure that the next \"freeswich command\" is not executed until the previous \"Freeswitch command\" has finished. This is kicked off by \"answer do\" #!/usr/bin/ruby require 'fsr' require 'fsr/listener/outbound' class OutboundDemo < FSR::Listener::Outbound def session_initiated exten = @session.headers[:caller_caller_id_number] FSR::Log.info \"*** Answering incoming call from #{exten}\" answer do FSR::Log.info \"***Reading DTMF from #{exten}\" read(\"/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav\", 4, 10, \"input\", 7000) do |read_var| FSR::Log.info \"***Success, grabbed #{read_var.strip} from #{exten}\" hangup #Hangup the call end end end end FSR.start_oes! OutboundDemo, :port => 8084, :host => \"127.0.0.1\" An Inbound Event Socket Listener example using FreeSWITCHeR's hook system: -------------------------------------------------------------------------- #!/usr/bin/ruby require 'pp' require 'fsr' require \"fsr/listener/inbound\" # EXAMPLE 1 # This adds a hook on CHANNEL_CREATE events. You can also create a method to handle the event you're after. See the next example FSL::Inbound.add_event_hook(:CHANNEL_CREATE) {|event| FSR::Log.info \"*** [#{event.content[:unique_id]}] Channel created - greetings from the hook!\" } # EXAMPLE 2 # Define a method to handle CHANNEL_HANGUP events. def custom_channel_hangup_handler(event) FSR::Log.info \"*** [#{event.content[:unique_id]}] Channel hangup. The event:\" pp event end # This adds a hook for EXAMPLE 2 FSL::Inbound.add_event_hook(:CHANNEL_HANGUP) {|event| custom_channel_hangup_handler(event) } # Start FSR Inbound Listener FSR.start_ies!(FSL::Inbound, :host => \"localhost\", :port => 8021) An Inbound Event Socket Listener example using the on_event callback method instead of hooks: --------------------------------------------------------------------------------------------- #!/usr/bin/ruby require 'pp' require 'fsr' require \"fsr/listener/inbound\" class IesDemo < FSR::Listener::Inbound def on_event(event) pp event.headers pp event.content[:event_name] end end FSR.start_ies!(IesDemo, :host => \"localhost\", :port => 8021) An example of using FSR::CommandSocket to originate a new call in irb: ---------------------------------------------------------------------- irb(main):001:0> require 'fsr' => true irb(main):002:0> FSR.load_all_commands => [:sofia, :originate] irb(main):003:0> sock = FSR::CommandSocket.new => #<FSR::CommandSocket:0xb7a89104 @server=\"127.0.0.1\", @socket=#<TCPSocket:0xb7a8908c>, @port=\"8021\", @auth=\"ClueCon\"> irb(main):007:0> sock.originate(:target => 'sofia/gateway/carlos/8179395222', :endpoint => FSR::App::Bridge.new(\"user/bougyman\")).run => {\"Job-UUID\"=>\"732075a4-7dd5-4258-b124-6284a82a5ae7\", \"body\"=>\"\", \"Content-Type\"=>\"command/reply\", \"Reply-Text\"=>\"+OK Job-UUID: 732075a4-7dd5-4258-b124-6284a82a5ae7\"} SUPPORT ------- Home page at http://code.rubyists.com/projects/fs #rubyists on FreeNode"
|
29
29
|
email: FreeSWITCHeR@rubyists.com
|
30
30
|
executables: []
|
31
31
|
|
@@ -42,14 +42,6 @@ files:
|
|
42
42
|
- NEWS
|
43
43
|
- README
|
44
44
|
- Rakefile
|
45
|
-
- examples/bin/cmd_demo.rb
|
46
|
-
- examples/bin/dtmf_test.rb
|
47
|
-
- examples/bin/ies_demo.rb
|
48
|
-
- examples/bin/ies_demo_with_hook.rb
|
49
|
-
- examples/bin/oes_demo.rb
|
50
|
-
- examples/dtmf_test.rb
|
51
|
-
- examples/ies_demo.rb
|
52
|
-
- examples/ies_demo_with_hook.rb
|
53
45
|
- examples/inbound_event_socket.rb
|
54
46
|
- examples/inbound_socket_events.rb
|
55
47
|
- examples/outbound_event_socket.rb
|
@@ -97,7 +89,6 @@ files:
|
|
97
89
|
- lib/fsr/listener/inbound.rb
|
98
90
|
- lib/fsr/listener/inbound/event.rb
|
99
91
|
- lib/fsr/listener/outbound.rb
|
100
|
-
- lib/fsr/listener/outbound.rb.orig
|
101
92
|
- lib/fsr/model/call.rb
|
102
93
|
- lib/fsr/version.rb
|
103
94
|
- tasks/authors.rake
|
@@ -116,9 +107,12 @@ files:
|
|
116
107
|
- tasks/yard.rake
|
117
108
|
- spec/helper.rb
|
118
109
|
- spec/fsr/app.rb
|
110
|
+
- spec/fsr/app/answer.rb
|
119
111
|
- spec/fsr/app/bridge.rb
|
120
112
|
- spec/fsr/app/conference.rb
|
121
113
|
- spec/fsr/app/fifo.rb
|
114
|
+
- spec/fsr/app/fs_break.rb
|
115
|
+
- spec/fsr/app/fs_sleep.rb
|
122
116
|
- spec/fsr/app/hangup.rb
|
123
117
|
- spec/fsr/app/limit.rb
|
124
118
|
- spec/fsr/app/log.rb
|
@@ -150,8 +144,8 @@ post_install_message: |
|
|
150
144
|
|
151
145
|
REQUIREMENTS
|
152
146
|
------------
|
153
|
-
|
154
|
-
|
147
|
+
* ruby (>= 1.8)
|
148
|
+
* eventmachine (If you wish to use Outbound and Inbound listener)
|
155
149
|
|
156
150
|
USAGE
|
157
151
|
-----
|
@@ -162,97 +156,94 @@ post_install_message: |
|
|
162
156
|
Simply just create a subclass of FSR::Listner::Outbound and all
|
163
157
|
new calls/sessions will invoke the "session_initiated" callback method.
|
164
158
|
|
165
|
-
|
166
|
-
that the next "freeswich command" is not executed until the previous
|
167
|
-
"Freeswitch command" has finished. This is kicked off by "answer do"
|
159
|
+
<b>NOTE</b>: FSR uses blocks within the 'session_inititated' method to ensure that the next "freeswich command" is not executed until the previous "Freeswitch command" has finished. This is kicked off by "answer do"
|
168
160
|
|
169
|
-
|
170
|
-
|
161
|
+
#!/usr/bin/ruby
|
162
|
+
require 'fsr'
|
163
|
+
require 'fsr/listener/outbound'
|
171
164
|
|
172
|
-
|
165
|
+
class OutboundDemo < FSR::Listener::Outbound
|
173
166
|
|
174
|
-
|
175
|
-
|
176
|
-
|
167
|
+
def session_initiated
|
168
|
+
exten = @session.headers[:caller_caller_id_number]
|
169
|
+
FSR::Log.info "*** Answering incoming call from #{exten}"
|
177
170
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
FSR::Log.info "***
|
182
|
-
|
183
|
-
FSR::Log.info "***Success, grabbed #{@session.headers[:variable_input].strip} from #{exten}"
|
184
|
-
hangup #Hangup the call
|
185
|
-
end
|
186
|
-
end
|
171
|
+
answer do
|
172
|
+
FSR::Log.info "***Reading DTMF from #{exten}"
|
173
|
+
read("/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav", 4, 10, "input", 7000) do |read_var|
|
174
|
+
FSR::Log.info "***Success, grabbed #{read_var.strip} from #{exten}"
|
175
|
+
hangup #Hangup the call
|
187
176
|
end
|
188
|
-
|
189
177
|
end
|
190
178
|
|
191
179
|
end
|
192
180
|
|
193
|
-
|
181
|
+
end
|
194
182
|
|
183
|
+
FSR.start_oes! OutboundDemo, :port => 8084, :host => "127.0.0.1"
|
195
184
|
|
196
185
|
An Inbound Event Socket Listener example using FreeSWITCHeR's hook system:
|
197
186
|
--------------------------------------------------------------------------
|
198
187
|
|
199
|
-
|
200
|
-
|
201
|
-
|
188
|
+
#!/usr/bin/ruby
|
189
|
+
require 'pp'
|
190
|
+
require 'fsr'
|
191
|
+
require "fsr/listener/inbound"
|
202
192
|
|
203
|
-
|
204
|
-
|
205
|
-
|
193
|
+
# EXAMPLE 1
|
194
|
+
# This adds a hook on CHANNEL_CREATE events. You can also create a method to handle the event you're after. See the next example
|
195
|
+
FSL::Inbound.add_event_hook(:CHANNEL_CREATE) {|event| FSR::Log.info "*** [#{event.content[:unique_id]}] Channel created - greetings from the hook!" }
|
206
196
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
197
|
+
# EXAMPLE 2
|
198
|
+
# Define a method to handle CHANNEL_HANGUP events.
|
199
|
+
def custom_channel_hangup_handler(event)
|
200
|
+
FSR::Log.info "*** [#{event.content[:unique_id]}] Channel hangup. The event:"
|
201
|
+
pp event
|
202
|
+
end
|
213
203
|
|
214
|
-
|
215
|
-
|
204
|
+
# This adds a hook for EXAMPLE 2
|
205
|
+
FSL::Inbound.add_event_hook(:CHANNEL_HANGUP) {|event| custom_channel_hangup_handler(event) }
|
216
206
|
|
217
207
|
|
218
|
-
|
219
|
-
|
208
|
+
# Start FSR Inbound Listener
|
209
|
+
FSR.start_ies!(FSL::Inbound, :host => "localhost", :port => 8021)
|
220
210
|
|
221
211
|
|
222
212
|
An Inbound Event Socket Listener example using the on_event callback method instead of hooks:
|
223
213
|
---------------------------------------------------------------------------------------------
|
224
214
|
|
225
|
-
|
226
|
-
|
227
|
-
|
215
|
+
#!/usr/bin/ruby
|
216
|
+
require 'pp'
|
217
|
+
require 'fsr'
|
218
|
+
require "fsr/listener/inbound"
|
228
219
|
|
229
220
|
|
230
|
-
|
231
|
-
|
232
|
-
def on_event(event)
|
233
|
-
pp event.headers
|
234
|
-
pp event.content[:event_name]
|
235
|
-
end
|
221
|
+
class IesDemo < FSR::Listener::Inbound
|
236
222
|
|
223
|
+
def on_event(event)
|
224
|
+
pp event.headers
|
225
|
+
pp event.content[:event_name]
|
237
226
|
end
|
238
227
|
|
239
|
-
|
228
|
+
end
|
229
|
+
|
230
|
+
FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
|
240
231
|
|
241
232
|
|
242
233
|
An example of using FSR::CommandSocket to originate a new call in irb:
|
243
234
|
----------------------------------------------------------------------
|
244
235
|
|
245
|
-
|
246
|
-
|
236
|
+
irb(main):001:0> require 'fsr'
|
237
|
+
=> true
|
247
238
|
|
248
|
-
|
249
|
-
|
239
|
+
irb(main):002:0> FSR.load_all_commands
|
240
|
+
=> [:sofia, :originate]
|
250
241
|
|
251
|
-
|
252
|
-
|
242
|
+
irb(main):003:0> sock = FSR::CommandSocket.new
|
243
|
+
=> #<FSR::CommandSocket:0xb7a89104 @server="127.0.0.1", @socket=#<TCPSocket:0xb7a8908c>, @port="8021", @auth="ClueCon">
|
253
244
|
|
254
|
-
|
255
|
-
|
245
|
+
irb(main):007:0> sock.originate(:target => 'sofia/gateway/carlos/8179395222', :endpoint => FSR::App::Bridge.new("user/bougyman")).run
|
246
|
+
=> {"Job-UUID"=>"732075a4-7dd5-4258-b124-6284a82a5ae7", "body"=>"", "Content-Type"=>"command/reply", "Reply-Text"=>"+OK Job-UUID: 732075a4-7dd5-4258-b124-6284a82a5ae7"}
|
256
247
|
|
257
248
|
|
258
249
|
|
@@ -286,9 +277,12 @@ specification_version: 2
|
|
286
277
|
summary: A library for interacting with the "FreeSWITCH":http://freeswitch.org telephony platform
|
287
278
|
test_files:
|
288
279
|
- spec/fsr/app.rb
|
280
|
+
- spec/fsr/app/answer.rb
|
289
281
|
- spec/fsr/app/bridge.rb
|
290
282
|
- spec/fsr/app/conference.rb
|
291
283
|
- spec/fsr/app/fifo.rb
|
284
|
+
- spec/fsr/app/fs_break.rb
|
285
|
+
- spec/fsr/app/fs_sleep.rb
|
292
286
|
- spec/fsr/app/hangup.rb
|
293
287
|
- spec/fsr/app/limit.rb
|
294
288
|
- spec/fsr/app/log.rb
|
data/examples/bin/cmd_demo.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'pp'
|
4
|
-
require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
|
5
|
-
require "fsr/cmd"
|
6
|
-
|
7
|
-
FSR.load_all_commands
|
8
|
-
sock = FSR::CommandSocket.new
|
9
|
-
|
10
|
-
# Check the status of our server
|
11
|
-
pp sock.status.run
|
12
|
-
|
13
|
-
# Check max sessions
|
14
|
-
pp sock.fsctl.max_sessions
|
15
|
-
# Set max sessions
|
16
|
-
pp sock.fsctl.max_sessions = 3000
|
17
|
-
|
18
|
-
# Check up a sofia user
|
19
|
-
pp sock.sofia_contact(:contact => "internal/user@domain.com").run
|
data/examples/bin/dtmf_test.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require File.join(File.dirname(__FILE__), "..", 'start_common')
|
3
|
-
require 'eventmachine'
|
4
|
-
require "fsr/listener/outbound"
|
5
|
-
require 'pp'
|
6
|
-
$stdout.flush
|
7
|
-
FSR.load_all_applications
|
8
|
-
FSR.load_all_commands
|
9
|
-
class ConsumerLogin < FSR::Listener::Outbound
|
10
|
-
|
11
|
-
def session_initiated(session, step = 0)
|
12
|
-
@step ||= step
|
13
|
-
exten = session.headers[:channel_caller_id_number]
|
14
|
-
pp session.headers
|
15
|
-
FSR::Log.info "*** Answering incoming call from #{exten}"
|
16
|
-
answer # Answer the call
|
17
|
-
end
|
18
|
-
|
19
|
-
def receive_reply(reply)
|
20
|
-
exten = @session.headers[:channel_caller_id_number]
|
21
|
-
@step += 1
|
22
|
-
case @step
|
23
|
-
when 1
|
24
|
-
FSR::Log.info "*** Reading dtmf for #{exten}"
|
25
|
-
read "/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav",4,10,"test",15000 # read test
|
26
|
-
when 2
|
27
|
-
FSR::Log.info "*** updating session for #{exten}"
|
28
|
-
update_session
|
29
|
-
when 3
|
30
|
-
FSR::Log.info "** Success, grabbed #{reply.content[:variable_test].strip} from #{exten}"
|
31
|
-
FSR::Log.info "*** Hanging up call"
|
32
|
-
hangup # Hangup the call
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
FSR.start_oes! ConsumerLogin, :port => 8084, :host => "127.0.0.1"
|
data/examples/bin/ies_demo.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'pp'
|
4
|
-
require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
|
5
|
-
puts $LOAD_PATH.inspect
|
6
|
-
$stdout.flush
|
7
|
-
require "fsr/listener/inbound"
|
8
|
-
|
9
|
-
|
10
|
-
class IesDemo < FSR::Listener::Inbound
|
11
|
-
|
12
|
-
def on_event(event)
|
13
|
-
pp event.headers
|
14
|
-
pp event.content[:event_name]
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
|
@@ -1,25 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'pp'
|
4
|
-
require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
|
5
|
-
puts $LOAD_PATH.inspect
|
6
|
-
$stdout.flush
|
7
|
-
require "fsr/listener/inbound"
|
8
|
-
|
9
|
-
# EXAMPLE 1
|
10
|
-
# This adds a hook on CHANNEL_CREATE events. You can also create a method to handle the event you're after. See the next example
|
11
|
-
FSL::Inbound.add_event_hook(:CHANNEL_CREATE) {|event| FSR::Log.info "*** [#{event.content[:unique_id]}] Channel created - greetings from the hook!" }
|
12
|
-
|
13
|
-
# EXAMPLE 2
|
14
|
-
# Define a method to handle CHANNEL_HANGUP events.
|
15
|
-
def custom_channel_hangup_handler(event)
|
16
|
-
FSR::Log.info "*** [#{event.content[:unique_id]}] Channel hangup. The event:"
|
17
|
-
pp event
|
18
|
-
end
|
19
|
-
# This adds a hook for EXAMPLE 2
|
20
|
-
FSL::Inbound.add_event_hook(:CHANNEL_HANGUP) {|event| custom_channel_hangup_handler(event) }
|
21
|
-
|
22
|
-
|
23
|
-
# Start FSR Inbound Listener
|
24
|
-
FSR.start_ies!(FSL::Inbound, :host => "localhost", :port => 8021)
|
25
|
-
|
data/examples/bin/oes_demo.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
|
4
|
-
puts $LOAD_PATH.inspect
|
5
|
-
$stdout.flush
|
6
|
-
require "fsr/listener/outbound"
|
7
|
-
|
8
|
-
class OesDemo < FSR::Listener::Outbound
|
9
|
-
|
10
|
-
def session_initiated(session)
|
11
|
-
number = session.headers[:caller_caller_id_number] # Grab the inbound caller id
|
12
|
-
FSR::Log.info "*** Answering incoming call from #{number}"
|
13
|
-
answer # Answer the call
|
14
|
-
log("1", "Pong from the FSR event socket!")
|
15
|
-
set("hangup_after_bridge", "true") # Set a variable
|
16
|
-
speak 'Hello, This is your phone switch. Have a great day' # use mod_flite to speak
|
17
|
-
hangup # Hangup the call
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
FSR.start_oes!(OesDemo, :port => 1888, :host => "localhost")
|
data/examples/dtmf_test.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
|
4
|
-
require "fsr/listener/outbound"
|
5
|
-
$stdout.flush
|
6
|
-
|
7
|
-
FSR.load_all_applications
|
8
|
-
FSR.load_all_commands
|
9
|
-
class DtmfDemo < FSR::Listener::Outbound
|
10
|
-
|
11
|
-
def session_initiated
|
12
|
-
exten = @session.headers[:caller_caller_id_number]
|
13
|
-
FSR::Log.info "*** Answering incoming call from #{exten}"
|
14
|
-
answer # Answer the call
|
15
|
-
end
|
16
|
-
|
17
|
-
def receive_reply(reply)
|
18
|
-
exten = @session.headers[:caller_caller_id_number]
|
19
|
-
case @step
|
20
|
-
when 1
|
21
|
-
FSR::Log.info "*** Reading dtmf for #{exten}"
|
22
|
-
read "/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav",4,10,"test",15000 # read test
|
23
|
-
when 2
|
24
|
-
FSR::Log.info "*** updating session for #{exten}"
|
25
|
-
update_session
|
26
|
-
when 3
|
27
|
-
FSR::Log.info "** Success, grabbed #{@session.headers[:variable_test].strip} from #{exten}"
|
28
|
-
FSR::Log.info "*** Hanging up call"
|
29
|
-
hangup # Hangup the call
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
FSR.start_oes! DtmfDemo, :port => 8084, :host => "127.0.0.1"
|