bougyman-freeswitcher 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/tasks/gem.rake ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake/gempackagetask'
2
+
3
+ desc "make a gemspec"
4
+ task :gemspec => [:manifest, :changelog, :authors] do
5
+ gemspec_file = "#{GEMSPEC.name}.gemspec"
6
+ File.open(gemspec_file, 'w+'){|gs| gs.puts(GEMSPEC.to_ruby) }
7
+ end
8
+
9
+ desc "package and install from gemspec"
10
+ task :install => [:gemspec] do
11
+ sh "gem build #{GEMSPEC.name}.gemspec"
12
+ sh "gem install #{GEMSPEC.name}-#{GEMSPEC.version}.gem"
13
+ end
14
+
15
+ desc "uninstall the gem"
16
+ task :uninstall => [:clean] do
17
+ sh %{gem uninstall -x #{GEMSPEC.name}}
18
+ end
19
+
20
+ Rake::GemPackageTask.new(GEMSPEC) do |p|
21
+ p.need_tar = true
22
+ p.need_zip = true
23
+ end
@@ -0,0 +1,76 @@
1
+ task :gem_installer do
2
+ class GemInstaller
3
+ def initialize(options = {}, &block)
4
+ @gems = []
5
+ @options = options
6
+
7
+ run(&block)
8
+ end
9
+
10
+ def run(&block)
11
+ instance_eval(&block) if block_given?
12
+ end
13
+
14
+ def gem(name, version = nil, options = {})
15
+ if version.respond_to?(:merge!)
16
+ options = version
17
+ else
18
+ options[:version] = version
19
+ end
20
+
21
+ @gems << [name, options]
22
+ end
23
+
24
+ def setup_gemspec(gemspec)
25
+ gemspec.dependencies.each do |dependency|
26
+ dependency.version_requirements.as_list.each do |version|
27
+ gem(dependency.name, version)
28
+ end
29
+ end
30
+
31
+ setup
32
+ end
33
+
34
+ def setup
35
+ require 'rubygems'
36
+ require 'rubygems/dependency_installer'
37
+
38
+ @gems.each do |name, options|
39
+ setup_gem(name, options)
40
+ end
41
+ end
42
+
43
+ def setup_gem(name, options, try_install = true)
44
+ print "activating #{name} ... "
45
+ Gem.activate(name, *[options[:version]].compact)
46
+ require(options[:lib] || name)
47
+ puts "success."
48
+ rescue LoadError => error
49
+ puts error
50
+ install_gem(name, options) if try_install
51
+ setup_gem(name, options, try_install = false)
52
+ end
53
+
54
+ def install_gem(name, options)
55
+ installer = Gem::DependencyInstaller.new(options)
56
+
57
+ temp_argv(options[:extconf]) do
58
+ print "Installing #{name} ... "
59
+ installer.install(name, options[:version])
60
+ puts "done."
61
+ end
62
+ end
63
+
64
+ def temp_argv(extconf)
65
+ if extconf ||= @options[:extconf]
66
+ old_argv = ARGV.clone
67
+ ARGV.replace(extconf.split(' '))
68
+ end
69
+
70
+ yield
71
+
72
+ ensure
73
+ ARGV.replace(old_argv) if extconf
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,6 @@
1
+ desc 'install dependencies'
2
+ task :install_dependencies => [:gem_installer] do
3
+ GemInstaller.new do
4
+ # setup_gemspec(GEMSPEC)
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ desc 'update manifest'
2
+ task :manifest do
3
+ File.open('MANIFEST', 'w+'){|io| io.puts(*GEMSPEC.files) }
4
+ end
data/tasks/rcov.rake ADDED
@@ -0,0 +1,23 @@
1
+ desc 'code coverage'
2
+ task :rcov => :clean do
3
+ specs = PROJECT_SPECS
4
+
5
+ ignore = %w[ gem rack bacon ]
6
+
7
+ if RUBY_VERSION >= '1.8.7'
8
+ ignore << 'begin_with' << 'end_with'
9
+ end
10
+ if RUBY_VERSION < '1.9'
11
+ ignore << 'fiber'
12
+ end
13
+
14
+ ignored = ignore.join(',')
15
+
16
+ cmd = "rcov --aggregate coverage.data --sort coverage -t --%s -x '#{ignored}' %s"
17
+
18
+ while spec = specs.shift
19
+ puts '', "Gather coverage for #{spec} ..."
20
+ html = specs.empty? ? 'html' : 'no-html'
21
+ sh(cmd % [html, spec])
22
+ end
23
+ end
@@ -0,0 +1,52 @@
1
+ namespace :release do
2
+ task :all => [:release_github, :release_rubyforge]
3
+
4
+ desc 'Display instructions to release on github'
5
+ task :github => [:reversion, :gemspec] do
6
+ name, version = GEMSPEC.name, GEMSPEC.version
7
+
8
+ puts <<INSTRUCTIONS
9
+ First add the relevant files:
10
+
11
+ git add AUTHORS MANIFEST CHANGELOG #{name}.gemspec lib/#{name}/version.rb
12
+
13
+ Then commit them, tag the commit, and push:
14
+
15
+ git commit -m 'Version #{version}'
16
+ git tag -a -m '#{version}' '#{version}'
17
+ git push
18
+
19
+ INSTRUCTIONS
20
+
21
+ end
22
+
23
+ # TODO: Not tested
24
+ desc 'Display instructions to release on rubyforge'
25
+ task :rubyforge => [:reversion, :gemspec, :package] do
26
+ name, version = GEMSPEC.name, GEMSPEC.version
27
+
28
+ puts <<INSTRUCTIONS
29
+ To publish to rubyforge do following:
30
+
31
+ rubyforge login
32
+ rubyforge add_release #{name} #{name} '#{version}' pkg/#{name}-#{version}.gem
33
+
34
+ After you have done these steps, see:
35
+
36
+ rake release:rubyforge_archives
37
+
38
+ INSTRUCTIONS
39
+ end
40
+
41
+ desc 'Display instructions to add archives after release:rubyforge'
42
+ task :rubyforge_archives do
43
+ name, version = GEMSPEC.name, GEMSPEC.version
44
+ puts "Adding archives for distro packagers is:", ""
45
+
46
+ Dir["pkg/#{name}-#{version}.{tgz,zip}"].each do |file|
47
+ puts "rubyforge add_file #{name} #{name} '#{version}' '#{file}'"
48
+ end
49
+
50
+ puts
51
+ end
52
+ end
@@ -0,0 +1,8 @@
1
+ desc "update version.rb"
2
+ task :reversion do
3
+ File.open("lib/fsr/version.rb", 'w+') do |file|
4
+ file.puts("module FSR")
5
+ file.puts(' VERSION = %p' % GEMSPEC.version.to_s)
6
+ file.puts('end')
7
+ end
8
+ end
data/tasks/setup.rake ADDED
@@ -0,0 +1,16 @@
1
+ desc 'install all possible dependencies'
2
+ task :setup => :gem_installer do
3
+ GemInstaller.new do
4
+ # core
5
+ gem 'eventmachine'
6
+
7
+ # spec
8
+ gem 'bacon'
9
+ gem 'rcov'
10
+
11
+ # doc
12
+ gem 'yard'
13
+
14
+ setup
15
+ end
16
+ end
data/tasks/spec.rake CHANGED
@@ -1,59 +0,0 @@
1
- # Copyright (c) 2009 Michael Fellinger m.fellinger@gmail.com
2
- # All files in this distribution are subject to the terms of the Ruby license.
3
-
4
- require 'rake'
5
-
6
- desc 'Run all specs'
7
- task :spec => :setup do
8
- require 'open3'
9
-
10
- specs = Dir['spec/fsr/**/*.rb']
11
- # specs.delete_if{|f| f =~ /cache\/common\.rb/ }
12
-
13
- some_failed = false
14
- total = specs.size
15
- len = specs.sort.last.size
16
- left_format = "%4d/%d: %-#{len + 12}s"
17
- red, green = "\e[31m%s\e[0m", "\e[32m%s\e[0m"
18
- matcher = /(\d+) specifications \((\d+) requirements\), (\d+) failures, (\d+) errors/
19
- tt = ta = tf = te = 0
20
-
21
- specs.each_with_index do |spec, idx|
22
- print(left_format % [idx + 1, total, spec])
23
- unless RUBY_PLATFORM.include?("mswin32")
24
- Open3.popen3("#{RUBY} -rubygems #{spec}") do |sin, sout, serr|
25
- out = sout.read
26
- err = serr.read
27
-
28
- all = out.match(matcher).captures.map{|c| c.to_i }
29
- tests, assertions, failures, errors = all
30
- tt += tests; ta += assertions; tf += failures; te += errors
31
-
32
- if tests == 0 || failures + errors > 0
33
- some_failed = true
34
- puts((red % "%5d tests, %d assertions, %d failures, %d errors") % all)
35
- puts "", out, err, ""
36
- else
37
- puts((green % "%5d passed") % tests)
38
- end
39
- end
40
- else
41
- out = %x{#{RUBY} -rubygems #{spec}}
42
- error = ""
43
- all = out.match(matcher).captures.map{|c| c.to_i }
44
- tests, assertions, failures, errors = all
45
- tt += tests; ta += assertions; tf += failures; te += errors
46
-
47
- if tests == 0 || failures + errors > 0
48
- some_failed = true
49
- puts((red % "%5d tests, %d assertions, %d failures, %d errors") % all)
50
- puts "", out, err, ""
51
- else
52
- puts((green % "%5d passed") % tests)
53
- end
54
- end
55
- end
56
-
57
- puts "#{tt} specifications, (#{ta} requirements), #{tf} failures, #{te} errors"
58
- exit 1 if some_failed
59
- end
data/tasks/yard.rake ADDED
@@ -0,0 +1,4 @@
1
+ desc 'Generate YARD documentation'
2
+ task :yard => :clean do
3
+ sh("yardoc -o ydoc --protected -r #{PROJECT_README}")
4
+ 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.1.3
4
+ version: 0.1.4
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-04-08 00:00:00 -07:00
15
+ date: 2009-05-11 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 ----- *** STILL UNDER HEAVY DEVELOPMENT *** A ruby library for interacting with the \"FreeSWITCH\" (http://www.freeswitch.org) opensource telephony platform *** STILL UNDER HEAVY DEVELOPMENT *** Requirements ------------ - ruby (>= 1.8) - eventmachine (If you wish to use Outbound and Inbound listener) Usage ----- Example of originating a new call in 'irb' using FSR::CommandSocket#originate: 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\"} Example of creating an Outbound Eventsocket listener: #!/usr/bin/env ruby require 'fsr' require \"fsr/listener/outbound\" class OesDemo < FSR::Listener::Outbound def session_initiated number = @session.headers[:caller_caller_id_number] # Grab the inbound caller id FSR::Log.info \"*** Answering incoming call from #{number}\" answer # Answer the call set(\"hangup_after_bridge\", \"true\")# Set a variable speak 'Hello, This is your phone switch. Have a great day' # use mod_flite to speak hangup # Hangup the call end end FSR.start_oes!(OesDemo, :port => 1888, :host => \"localhost\") Example of creating an Outbound Eventsocket listener that can read DTMF input and keep state: #!/usr/bin/env ruby require 'fsr' require 'fsr/listener/outbound' FSR.load_all_applications FSR.load_all_commands class DtmfDemo < FSR::Listener::Outbound def session_initiated exten = @session.headers[:caller_caller_id_number] FSR::Log.info \"*** Answering incoming call from #{exten}\" answer # Answer the call end def receive_reply(reply) exten = @session.headers[:caller_caller_id_number] case @step when 1 FSR::Log.info \"*** Reading dtmf for #{exten}\" read \"/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav\",4,10,\"test\",15000 # read test when 2 FSR::Log.info \"*** updating session for #{exten}\" update_session when 3 FSR::Log.info \"** Success, grabbed #{@session.headers[:variable_test].strip} from #{exten}\" FSR::Log.info \"*** Hanging up call\" hangup # Hangup the call end end end FSR.start_oes! DtmfDemo, :port => 8084, :host => \"127.0.0.1\" Example of creating an Inbound Eventsocket listener: #!/usr/bin/env ruby require 'fsr' require 'fsr/listener/inbound' require 'pp' 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) Support ------- Home page at http://code.rubyists.com/projects/fs #rubyists on FreeNode"
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. * NOTE: 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\" 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 FSR::Log.info \"*** Updating session for #{exten}\" update_session do FSR::Log.info \"***Success, grabbed #{@session.headers[:variable_input].strip} from #{exten}\" hangup #Hangup the call end 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: -------------------------------------------------------------------------- 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: --------------------------------------------------------------------------------------------- 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
 
@@ -34,12 +34,14 @@ extensions: []
34
34
  extra_rdoc_files: []
35
35
 
36
36
  files:
37
+ - .gitignore
38
+ - AUTHORS
39
+ - CHANGELOG
37
40
  - License.txt
41
+ - MANIFEST
38
42
  - NEWS
39
43
  - README
40
44
  - Rakefile
41
- - examples
42
- - examples/bin
43
45
  - examples/bin/cmd_demo.rb
44
46
  - examples/bin/dtmf_test.rb
45
47
  - examples/bin/ies_demo.rb
@@ -48,11 +50,12 @@ files:
48
50
  - examples/dtmf_test.rb
49
51
  - examples/ies_demo.rb
50
52
  - examples/ies_demo_with_hook.rb
51
- - examples/oes_demo.rb
52
- - examples/play_and_get_test.rb
53
- - lib
54
- - lib/fsr
55
- - lib/fsr/app
53
+ - examples/inbound_event_socket.rb
54
+ - examples/inbound_socket_events.rb
55
+ - examples/outbound_event_socket.rb
56
+ - freeswitcher.gemspec
57
+ - lib/fsr.rb
58
+ - lib/fsr/app.rb
56
59
  - lib/fsr/app/answer.rb
57
60
  - lib/fsr/app/bridge.rb
58
61
  - lib/fsr/app/conference.rb
@@ -71,42 +74,67 @@ files:
71
74
  - lib/fsr/app/uuid_dump.rb
72
75
  - lib/fsr/app/uuid_getvar.rb
73
76
  - lib/fsr/app/uuid_setvar.rb
74
- - lib/fsr/app.rb
75
- - lib/fsr/cmd
77
+ - lib/fsr/cmd.rb
76
78
  - lib/fsr/cmd/calls.rb
77
79
  - lib/fsr/cmd/fsctl.rb
78
80
  - lib/fsr/cmd/originate.rb
79
- - lib/fsr/cmd/sofia
81
+ - lib/fsr/cmd/sofia.rb
80
82
  - lib/fsr/cmd/sofia/profile.rb
81
83
  - lib/fsr/cmd/sofia/status.rb
82
- - lib/fsr/cmd/sofia.rb
83
84
  - lib/fsr/cmd/sofia_contact.rb
84
85
  - lib/fsr/cmd/status.rb
85
- - lib/fsr/cmd.rb
86
86
  - lib/fsr/command_socket.rb
87
- - lib/fsr/database
87
+ - lib/fsr/database.rb
88
88
  - lib/fsr/database/call_limit.rb
89
89
  - lib/fsr/database/core.rb
90
90
  - lib/fsr/database/sofia_reg_external.rb
91
91
  - lib/fsr/database/sofia_reg_internal.rb
92
92
  - lib/fsr/database/voicemail_default.rb
93
- - lib/fsr/database.rb
94
93
  - lib/fsr/event_socket.rb
95
94
  - lib/fsr/fake_socket.rb
96
- - lib/fsr/listener
95
+ - lib/fsr/listener.rb
97
96
  - lib/fsr/listener/header_and_content_response.rb
98
- - lib/fsr/listener/inbound
99
- - lib/fsr/listener/inbound/event.rb
100
97
  - lib/fsr/listener/inbound.rb
98
+ - lib/fsr/listener/inbound/event.rb
101
99
  - lib/fsr/listener/outbound.rb
102
100
  - lib/fsr/listener/outbound.rb.orig
103
- - lib/fsr/listener.rb
104
- - lib/fsr/model
105
101
  - lib/fsr/model/call.rb
106
- - lib/fsr.rb
107
- - tasks
108
- - tasks/package.rake
102
+ - lib/fsr/version.rb
103
+ - tasks/authors.rake
104
+ - tasks/bacon.rake
105
+ - tasks/changelog.rake
106
+ - tasks/copyright.rake
107
+ - tasks/gem.rake
108
+ - tasks/gem_installer.rake
109
+ - tasks/install_dependencies.rake
110
+ - tasks/manifest.rake
111
+ - tasks/rcov.rake
112
+ - tasks/release.rake
113
+ - tasks/reversion.rake
114
+ - tasks/setup.rake
109
115
  - tasks/spec.rake
116
+ - tasks/yard.rake
117
+ - spec/helper.rb
118
+ - spec/fsr/app.rb
119
+ - spec/fsr/app/bridge.rb
120
+ - spec/fsr/app/conference.rb
121
+ - spec/fsr/app/fifo.rb
122
+ - spec/fsr/app/hangup.rb
123
+ - spec/fsr/app/limit.rb
124
+ - spec/fsr/app/log.rb
125
+ - spec/fsr/app/play_and_get_digits.rb
126
+ - spec/fsr/app/playback.rb
127
+ - spec/fsr/app/set.rb
128
+ - spec/fsr/app/transfer.rb
129
+ - spec/fsr/cmd.rb
130
+ - spec/fsr/cmd/calls.rb
131
+ - spec/fsr/cmd/originate.rb
132
+ - spec/fsr/cmd/sofia.rb
133
+ - spec/fsr/cmd/sofia/profile.rb
134
+ - spec/fsr/listener.rb
135
+ - spec/fsr/listener/inbound.rb
136
+ - spec/fsr/listener/outbound.rb
137
+ - spec/fsr/loading.rb
110
138
  has_rdoc: false
111
139
  homepage: http://code.rubyists.com/projects/fs
112
140
  post_install_message: |
@@ -116,108 +144,88 @@ post_install_message: |
116
144
  Distributed under the terms of the MIT License.
117
145
  ==========================================================
118
146
 
119
- About
147
+ ABOUT
120
148
  -----
121
- *** STILL UNDER HEAVY DEVELOPMENT ***
122
-
123
149
  A ruby library for interacting with the "FreeSWITCH" (http://www.freeswitch.org) opensource telephony platform
124
150
 
125
- *** STILL UNDER HEAVY DEVELOPMENT ***
126
-
127
- Requirements
151
+ REQUIREMENTS
128
152
  ------------
129
153
  - ruby (>= 1.8)
130
154
  - eventmachine (If you wish to use Outbound and Inbound listener)
131
155
 
132
- Usage
156
+ USAGE
133
157
  -----
134
158
 
135
- Example of originating a new call in 'irb' using FSR::CommandSocket#originate:
136
-
137
- irb(main):001:0> require 'fsr'
138
- => true
139
-
140
- irb(main):002:0> FSR.load_all_commands
141
- => [:sofia, :originate]
142
-
143
- irb(main):003:0> sock = FSR::CommandSocket.new
144
- => #<FSR::CommandSocket:0xb7a89104 @server="127.0.0.1", @socket=#<TCPSocket:0xb7a8908c>, @port="8021", @auth="ClueCon">
159
+ An Outbound Event Listener Example that reads and returns DTMF input:
160
+ --------------------------------------------------------------------
145
161
 
146
- irb(main):007:0> sock.originate(:target => 'sofia/gateway/carlos/8179395222', :endpoint => FSR::App::Bridge.new("user/bougyman")).run
147
- => {"Job-UUID"=>"732075a4-7dd5-4258-b124-6284a82a5ae7", "body"=>"", "Content-Type"=>"command/reply", "Reply-Text"=>"+OK Job-UUID: 732075a4-7dd5-4258-b124-6284a82a5ae7"}
162
+ Simply just create a subclass of FSR::Listner::Outbound and all
163
+ new calls/sessions will invoke the "session_initiated" callback method.
148
164
 
149
-
150
- Example of creating an Outbound Eventsocket listener:
151
-
152
- #!/usr/bin/env ruby
165
+ * NOTE: FSR uses blocks within the 'session_inititated' method to ensure
166
+ that the next "freeswich command" is not executed until the previous
167
+ "Freeswitch command" has finished. This is kicked off by "answer do"
153
168
 
154
169
  require 'fsr'
155
- require "fsr/listener/outbound"
170
+ require 'fsr/listener/outbound'
156
171
 
157
- class OesDemo < FSR::Listener::Outbound
172
+ class OutboundDemo < FSR::Listener::Outbound
158
173
 
159
174
  def session_initiated
160
- number = @session.headers[:caller_caller_id_number] # Grab the inbound caller id
161
- FSR::Log.info "*** Answering incoming call from #{number}"
162
- answer # Answer the call
163
- set("hangup_after_bridge", "true")# Set a variable
164
- speak 'Hello, This is your phone switch. Have a great day' # use mod_flite to speak
165
- hangup # Hangup the call
166
- end
175
+ exten = @session.headers[:caller_caller_id_number]
176
+ FSR::Log.info "*** Answering incoming call from #{exten}"
167
177
 
168
- end
178
+ answer do
179
+ FSR::Log.info "***Reading DTMF from #{exten}"
180
+ read("/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav", 4, 10, "input", 7000) do
181
+ FSR::Log.info "*** Updating session for #{exten}"
182
+ update_session do
183
+ FSR::Log.info "***Success, grabbed #{@session.headers[:variable_input].strip} from #{exten}"
184
+ hangup #Hangup the call
185
+ end
186
+ end
187
+ end
169
188
 
170
- FSR.start_oes!(OesDemo, :port => 1888, :host => "localhost")
189
+ end
171
190
 
191
+ end
172
192
 
193
+ FSR.start_oes! OutboundDemo, :port => 8084, :host => "127.0.0.1"
173
194
 
174
- Example of creating an Outbound Eventsocket listener that can read DTMF input and keep state:
175
195
 
176
- #!/usr/bin/env ruby
196
+ An Inbound Event Socket Listener example using FreeSWITCHeR's hook system:
197
+ --------------------------------------------------------------------------
177
198
 
199
+ require 'pp'
178
200
  require 'fsr'
179
- require 'fsr/listener/outbound'
180
-
181
- FSR.load_all_applications
182
- FSR.load_all_commands
183
-
184
- class DtmfDemo < FSR::Listener::Outbound
185
-
186
- def session_initiated
187
- exten = @session.headers[:caller_caller_id_number]
188
- FSR::Log.info "*** Answering incoming call from #{exten}"
189
- answer # Answer the call
190
- end
201
+ require "fsr/listener/inbound"
191
202
 
192
- def receive_reply(reply)
193
- exten = @session.headers[:caller_caller_id_number]
194
- case @step
195
- when 1
196
- FSR::Log.info "*** Reading dtmf for #{exten}"
197
- read "/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav",4,10,"test",15000 # read test
198
- when 2
199
- FSR::Log.info "*** updating session for #{exten}"
200
- update_session
201
- when 3
202
- FSR::Log.info "** Success, grabbed #{@session.headers[:variable_test].strip} from #{exten}"
203
- FSR::Log.info "*** Hanging up call"
204
- hangup # Hangup the call
205
- end
206
- end
203
+ # EXAMPLE 1
204
+ # 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
205
+ FSL::Inbound.add_event_hook(:CHANNEL_CREATE) {|event| FSR::Log.info "*** [#{event.content[:unique_id]}] Channel created - greetings from the hook!" }
207
206
 
207
+ # EXAMPLE 2
208
+ # Define a method to handle CHANNEL_HANGUP events.
209
+ def custom_channel_hangup_handler(event)
210
+ FSR::Log.info "*** [#{event.content[:unique_id]}] Channel hangup. The event:"
211
+ pp event
208
212
  end
209
213
 
210
- FSR.start_oes! DtmfDemo, :port => 8084, :host => "127.0.0.1"
214
+ # This adds a hook for EXAMPLE 2
215
+ FSL::Inbound.add_event_hook(:CHANNEL_HANGUP) {|event| custom_channel_hangup_handler(event) }
211
216
 
212
217
 
218
+ # Start FSR Inbound Listener
219
+ FSR.start_ies!(FSL::Inbound, :host => "localhost", :port => 8021)
213
220
 
214
- Example of creating an Inbound Eventsocket listener:
215
221
 
216
- #!/usr/bin/env ruby
222
+ An Inbound Event Socket Listener example using the on_event callback method instead of hooks:
223
+ ---------------------------------------------------------------------------------------------
217
224
 
218
- require 'fsr'
219
- require 'fsr/listener/inbound'
220
225
  require 'pp'
226
+ require 'fsr'
227
+ require "fsr/listener/inbound"
228
+
221
229
 
222
230
  class IesDemo < FSR::Listener::Inbound
223
231
 
@@ -231,8 +239,24 @@ post_install_message: |
231
239
  FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
232
240
 
233
241
 
242
+ An example of using FSR::CommandSocket to originate a new call in irb:
243
+ ----------------------------------------------------------------------
244
+
245
+ irb(main):001:0> require 'fsr'
246
+ => true
247
+
248
+ irb(main):002:0> FSR.load_all_commands
249
+ => [:sofia, :originate]
250
+
251
+ irb(main):003:0> sock = FSR::CommandSocket.new
252
+ => #<FSR::CommandSocket:0xb7a89104 @server="127.0.0.1", @socket=#<TCPSocket:0xb7a8908c>, @port="8021", @auth="ClueCon">
253
+
254
+ irb(main):007:0> sock.originate(:target => 'sofia/gateway/carlos/8179395222', :endpoint => FSR::App::Bridge.new("user/bougyman")).run
255
+ => {"Job-UUID"=>"732075a4-7dd5-4258-b124-6284a82a5ae7", "body"=>"", "Content-Type"=>"command/reply", "Reply-Text"=>"+OK Job-UUID: 732075a4-7dd5-4258-b124-6284a82a5ae7"}
256
+
234
257
 
235
- Support
258
+
259
+ SUPPORT
236
260
  -------
237
261
  Home page at http://code.rubyists.com/projects/fs
238
262
  #rubyists on FreeNode
@@ -255,15 +279,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
255
279
  version:
256
280
  requirements: []
257
281
 
258
- rubyforge_project:
282
+ rubyforge_project: freeswitcher
259
283
  rubygems_version: 1.2.0
260
284
  signing_key:
261
285
  specification_version: 2
262
286
  summary: A library for interacting with the "FreeSWITCH":http://freeswitch.org telephony platform
263
287
  test_files:
264
- - spec
265
- - spec/fsr
266
- - spec/fsr/app
288
+ - spec/fsr/app.rb
267
289
  - spec/fsr/app/bridge.rb
268
290
  - spec/fsr/app/conference.rb
269
291
  - spec/fsr/app/fifo.rb
@@ -274,17 +296,12 @@ test_files:
274
296
  - spec/fsr/app/playback.rb
275
297
  - spec/fsr/app/set.rb
276
298
  - spec/fsr/app/transfer.rb
277
- - spec/fsr/app.rb
278
- - spec/fsr/cmd
299
+ - spec/fsr/cmd.rb
279
300
  - spec/fsr/cmd/calls.rb
280
301
  - spec/fsr/cmd/originate.rb
281
- - spec/fsr/cmd/sofia
282
- - spec/fsr/cmd/sofia/profile.rb
283
302
  - spec/fsr/cmd/sofia.rb
284
- - spec/fsr/cmd.rb
285
- - spec/fsr/listener
303
+ - spec/fsr/cmd/sofia/profile.rb
304
+ - spec/fsr/listener.rb
286
305
  - spec/fsr/listener/inbound.rb
287
306
  - spec/fsr/listener/outbound.rb
288
- - spec/fsr/listener.rb
289
307
  - spec/fsr/loading.rb
290
- - spec/helper.rb