freeswitcher 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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: 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-05-04 00:00:00 -05:00
15
+ date: 2009-05-11 00:00:00 -05: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,19 +34,20 @@ 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/dtmf_test.rb
43
- - examples/ies_demo.rb
44
- - examples/ies_demo_with_hook.rb
45
- - examples/oes_demo.rb
46
- - examples/play_and_get_test.rb
47
- - lib
48
- - lib/fsr
49
- - lib/fsr/app
45
+ - examples/inbound_event_socket.rb
46
+ - examples/inbound_socket_events.rb
47
+ - examples/outbound_event_socket.rb
48
+ - freeswitcher.gemspec
49
+ - lib/fsr.rb
50
+ - lib/fsr/app.rb
50
51
  - lib/fsr/app/answer.rb
51
52
  - lib/fsr/app/bridge.rb
52
53
  - lib/fsr/app/conference.rb
@@ -65,45 +66,67 @@ files:
65
66
  - lib/fsr/app/uuid_dump.rb
66
67
  - lib/fsr/app/uuid_getvar.rb
67
68
  - lib/fsr/app/uuid_setvar.rb
68
- - lib/fsr/app.rb
69
- - lib/fsr/cmd
69
+ - lib/fsr/cmd.rb
70
70
  - lib/fsr/cmd/calls.rb
71
71
  - lib/fsr/cmd/fsctl.rb
72
72
  - lib/fsr/cmd/originate.rb
73
- - lib/fsr/cmd/sofia
73
+ - lib/fsr/cmd/sofia.rb
74
74
  - lib/fsr/cmd/sofia/profile.rb
75
75
  - lib/fsr/cmd/sofia/status.rb
76
- - lib/fsr/cmd/sofia.rb
77
76
  - lib/fsr/cmd/sofia_contact.rb
78
77
  - lib/fsr/cmd/status.rb
79
- - lib/fsr/cmd.rb
80
78
  - lib/fsr/command_socket.rb
81
- - lib/fsr/database
79
+ - lib/fsr/database.rb
82
80
  - lib/fsr/database/call_limit.rb
83
81
  - lib/fsr/database/core.rb
84
82
  - lib/fsr/database/sofia_reg_external.rb
85
83
  - lib/fsr/database/sofia_reg_internal.rb
86
84
  - lib/fsr/database/voicemail_default.rb
87
- - lib/fsr/database.rb
88
85
  - lib/fsr/event_socket.rb
89
86
  - lib/fsr/fake_socket.rb
90
- - lib/fsr/listener
87
+ - lib/fsr/listener.rb
91
88
  - lib/fsr/listener/header_and_content_response.rb
92
- - lib/fsr/listener/inbound
93
- - lib/fsr/listener/inbound/event.rb
94
89
  - lib/fsr/listener/inbound.rb
90
+ - lib/fsr/listener/inbound/event.rb
95
91
  - lib/fsr/listener/outbound.rb
96
92
  - lib/fsr/listener/outbound.rb.orig
97
- - lib/fsr/listener.rb
98
- - lib/fsr/model
99
93
  - lib/fsr/model/call.rb
100
- - lib/fsr.rb
101
- - tasks
102
- - tasks/package.rake
103
- - tasks/ride.rake
104
- - tasks/rspec.rake
94
+ - lib/fsr/version.rb
95
+ - tasks/authors.rake
96
+ - tasks/bacon.rake
97
+ - tasks/changelog.rake
98
+ - tasks/copyright.rake
99
+ - tasks/gem.rake
100
+ - tasks/gem_installer.rake
101
+ - tasks/install_dependencies.rake
102
+ - tasks/manifest.rake
103
+ - tasks/rcov.rake
104
+ - tasks/release.rake
105
+ - tasks/reversion.rake
106
+ - tasks/setup.rake
105
107
  - tasks/spec.rake
106
- - tmp
108
+ - tasks/yard.rake
109
+ - spec/helper.rb
110
+ - spec/fsr/app.rb
111
+ - spec/fsr/app/bridge.rb
112
+ - spec/fsr/app/conference.rb
113
+ - spec/fsr/app/fifo.rb
114
+ - spec/fsr/app/hangup.rb
115
+ - spec/fsr/app/limit.rb
116
+ - spec/fsr/app/log.rb
117
+ - spec/fsr/app/play_and_get_digits.rb
118
+ - spec/fsr/app/playback.rb
119
+ - spec/fsr/app/set.rb
120
+ - spec/fsr/app/transfer.rb
121
+ - spec/fsr/cmd.rb
122
+ - spec/fsr/cmd/calls.rb
123
+ - spec/fsr/cmd/originate.rb
124
+ - spec/fsr/cmd/sofia.rb
125
+ - spec/fsr/cmd/sofia/profile.rb
126
+ - spec/fsr/listener.rb
127
+ - spec/fsr/listener/inbound.rb
128
+ - spec/fsr/listener/outbound.rb
129
+ - spec/fsr/loading.rb
107
130
  has_rdoc: false
108
131
  homepage: http://code.rubyists.com/projects/fs
109
132
  post_install_message: |
@@ -113,108 +136,88 @@ post_install_message: |
113
136
  Distributed under the terms of the MIT License.
114
137
  ==========================================================
115
138
 
116
- About
139
+ ABOUT
117
140
  -----
118
- *** STILL UNDER HEAVY DEVELOPMENT ***
119
-
120
141
  A ruby library for interacting with the "FreeSWITCH" (http://www.freeswitch.org) opensource telephony platform
121
142
 
122
- *** STILL UNDER HEAVY DEVELOPMENT ***
123
-
124
- Requirements
143
+ REQUIREMENTS
125
144
  ------------
126
145
  - ruby (>= 1.8)
127
146
  - eventmachine (If you wish to use Outbound and Inbound listener)
128
147
 
129
- Usage
148
+ USAGE
130
149
  -----
131
150
 
132
- Example of originating a new call in 'irb' using FSR::CommandSocket#originate:
133
-
134
- irb(main):001:0> require 'fsr'
135
- => true
136
-
137
- irb(main):002:0> FSR.load_all_commands
138
- => [:sofia, :originate]
139
-
140
- irb(main):003:0> sock = FSR::CommandSocket.new
141
- => #<FSR::CommandSocket:0xb7a89104 @server="127.0.0.1", @socket=#<TCPSocket:0xb7a8908c>, @port="8021", @auth="ClueCon">
151
+ An Outbound Event Listener Example that reads and returns DTMF input:
152
+ --------------------------------------------------------------------
142
153
 
143
- irb(main):007:0> sock.originate(:target => 'sofia/gateway/carlos/8179395222', :endpoint => FSR::App::Bridge.new("user/bougyman")).run
144
- => {"Job-UUID"=>"732075a4-7dd5-4258-b124-6284a82a5ae7", "body"=>"", "Content-Type"=>"command/reply", "Reply-Text"=>"+OK Job-UUID: 732075a4-7dd5-4258-b124-6284a82a5ae7"}
145
-
146
-
147
- Example of creating an Outbound Eventsocket listener:
148
-
149
- #!/usr/bin/env ruby
154
+ Simply just create a subclass of FSR::Listner::Outbound and all
155
+ new calls/sessions will invoke the "session_initiated" callback method.
156
+
157
+ * NOTE: FSR uses blocks within the 'session_inititated' method to ensure
158
+ that the next "freeswich command" is not executed until the previous
159
+ "Freeswitch command" has finished. This is kicked off by "answer do"
150
160
 
151
161
  require 'fsr'
152
- require "fsr/listener/outbound"
162
+ require 'fsr/listener/outbound'
153
163
 
154
- class OesDemo < FSR::Listener::Outbound
164
+ class OutboundDemo < FSR::Listener::Outbound
155
165
 
156
166
  def session_initiated
157
- number = @session.headers[:caller_caller_id_number] # Grab the inbound caller id
158
- FSR::Log.info "*** Answering incoming call from #{number}"
159
- answer # Answer the call
160
- set("hangup_after_bridge", "true")# Set a variable
161
- speak 'Hello, This is your phone switch. Have a great day' # use mod_flite to speak
162
- hangup # Hangup the call
167
+ exten = @session.headers[:caller_caller_id_number]
168
+ FSR::Log.info "*** Answering incoming call from #{exten}"
169
+
170
+ answer do
171
+ FSR::Log.info "***Reading DTMF from #{exten}"
172
+ read("/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav", 4, 10, "input", 7000) do
173
+ FSR::Log.info "*** Updating session for #{exten}"
174
+ update_session do
175
+ FSR::Log.info "***Success, grabbed #{@session.headers[:variable_input].strip} from #{exten}"
176
+ hangup #Hangup the call
177
+ end
178
+ end
179
+ end
180
+
163
181
  end
164
182
 
165
183
  end
166
184
 
167
- FSR.start_oes!(OesDemo, :port => 1888, :host => "localhost")
168
-
185
+ FSR.start_oes! OutboundDemo, :port => 8084, :host => "127.0.0.1"
169
186
 
170
187
 
171
- Example of creating an Outbound Eventsocket listener that can read DTMF input and keep state:
188
+ An Inbound Event Socket Listener example using FreeSWITCHeR's hook system:
189
+ --------------------------------------------------------------------------
172
190
 
173
- #!/usr/bin/env ruby
174
-
191
+ require 'pp'
175
192
  require 'fsr'
176
- require 'fsr/listener/outbound'
177
-
178
- FSR.load_all_applications
179
- FSR.load_all_commands
180
-
181
- class DtmfDemo < FSR::Listener::Outbound
182
-
183
- def session_initiated
184
- exten = @session.headers[:caller_caller_id_number]
185
- FSR::Log.info "*** Answering incoming call from #{exten}"
186
- answer # Answer the call
187
- end
193
+ require "fsr/listener/inbound"
188
194
 
189
- def receive_reply(reply)
190
- exten = @session.headers[:caller_caller_id_number]
191
- case @step
192
- when 1
193
- FSR::Log.info "*** Reading dtmf for #{exten}"
194
- read "/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav",4,10,"test",15000 # read test
195
- when 2
196
- FSR::Log.info "*** updating session for #{exten}"
197
- update_session
198
- when 3
199
- FSR::Log.info "** Success, grabbed #{@session.headers[:variable_test].strip} from #{exten}"
200
- FSR::Log.info "*** Hanging up call"
201
- hangup # Hangup the call
202
- end
203
- end
195
+ # EXAMPLE 1
196
+ # 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
197
+ FSL::Inbound.add_event_hook(:CHANNEL_CREATE) {|event| FSR::Log.info "*** [#{event.content[:unique_id]}] Channel created - greetings from the hook!" }
204
198
 
199
+ # EXAMPLE 2
200
+ # Define a method to handle CHANNEL_HANGUP events.
201
+ def custom_channel_hangup_handler(event)
202
+ FSR::Log.info "*** [#{event.content[:unique_id]}] Channel hangup. The event:"
203
+ pp event
205
204
  end
206
205
 
207
- FSR.start_oes! DtmfDemo, :port => 8084, :host => "127.0.0.1"
206
+ # This adds a hook for EXAMPLE 2
207
+ FSL::Inbound.add_event_hook(:CHANNEL_HANGUP) {|event| custom_channel_hangup_handler(event) }
208
208
 
209
209
 
210
+ # Start FSR Inbound Listener
211
+ FSR.start_ies!(FSL::Inbound, :host => "localhost", :port => 8021)
210
212
 
211
- Example of creating an Inbound Eventsocket listener:
212
213
 
213
- #!/usr/bin/env ruby
214
+ An Inbound Event Socket Listener example using the on_event callback method instead of hooks:
215
+ ---------------------------------------------------------------------------------------------
214
216
 
215
- require 'fsr'
216
- require 'fsr/listener/inbound'
217
217
  require 'pp'
218
+ require 'fsr'
219
+ require "fsr/listener/inbound"
220
+
218
221
 
219
222
  class IesDemo < FSR::Listener::Inbound
220
223
 
@@ -228,8 +231,24 @@ post_install_message: |
228
231
  FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
229
232
 
230
233
 
234
+ An example of using FSR::CommandSocket to originate a new call in irb:
235
+ ----------------------------------------------------------------------
236
+
237
+ irb(main):001:0> require 'fsr'
238
+ => true
239
+
240
+ irb(main):002:0> FSR.load_all_commands
241
+ => [:sofia, :originate]
242
+
243
+ irb(main):003:0> sock = FSR::CommandSocket.new
244
+ => #<FSR::CommandSocket:0xb7a89104 @server="127.0.0.1", @socket=#<TCPSocket:0xb7a8908c>, @port="8021", @auth="ClueCon">
245
+
246
+ irb(main):007:0> sock.originate(:target => 'sofia/gateway/carlos/8179395222', :endpoint => FSR::App::Bridge.new("user/bougyman")).run
247
+ => {"Job-UUID"=>"732075a4-7dd5-4258-b124-6284a82a5ae7", "body"=>"", "Content-Type"=>"command/reply", "Reply-Text"=>"+OK Job-UUID: 732075a4-7dd5-4258-b124-6284a82a5ae7"}
248
+
231
249
 
232
- Support
250
+
251
+ SUPPORT
233
252
  -------
234
253
  Home page at http://code.rubyists.com/projects/fs
235
254
  #rubyists on FreeNode
@@ -252,15 +271,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
271
  version:
253
272
  requirements: []
254
273
 
255
- rubyforge_project:
274
+ rubyforge_project: freeswitcher
256
275
  rubygems_version: 1.3.1
257
276
  signing_key:
258
277
  specification_version: 2
259
278
  summary: A library for interacting with the "FreeSWITCH":http://freeswitch.org telephony platform
260
279
  test_files:
261
- - spec
262
- - spec/fsr
263
- - spec/fsr/app
280
+ - spec/fsr/app.rb
264
281
  - spec/fsr/app/bridge.rb
265
282
  - spec/fsr/app/conference.rb
266
283
  - spec/fsr/app/fifo.rb
@@ -271,17 +288,12 @@ test_files:
271
288
  - spec/fsr/app/playback.rb
272
289
  - spec/fsr/app/set.rb
273
290
  - spec/fsr/app/transfer.rb
274
- - spec/fsr/app.rb
275
- - spec/fsr/cmd
291
+ - spec/fsr/cmd.rb
276
292
  - spec/fsr/cmd/calls.rb
277
293
  - spec/fsr/cmd/originate.rb
278
- - spec/fsr/cmd/sofia
279
- - spec/fsr/cmd/sofia/profile.rb
280
294
  - spec/fsr/cmd/sofia.rb
281
- - spec/fsr/cmd.rb
282
- - spec/fsr/listener
295
+ - spec/fsr/cmd/sofia/profile.rb
296
+ - spec/fsr/listener.rb
283
297
  - spec/fsr/listener/inbound.rb
284
298
  - spec/fsr/listener/outbound.rb
285
- - spec/fsr/listener.rb
286
299
  - spec/fsr/loading.rb
287
- - spec/helper.rb