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/MANIFEST ADDED
@@ -0,0 +1,101 @@
1
+ .gitignore
2
+ AUTHORS
3
+ CHANGELOG
4
+ License.txt
5
+ MANIFEST
6
+ NEWS
7
+ README
8
+ Rakefile
9
+ examples/bin/cmd_demo.rb
10
+ examples/bin/dtmf_test.rb
11
+ examples/bin/ies_demo.rb
12
+ examples/bin/ies_demo_with_hook.rb
13
+ examples/bin/oes_demo.rb
14
+ examples/dtmf_test.rb
15
+ examples/ies_demo.rb
16
+ examples/ies_demo_with_hook.rb
17
+ examples/inbound_event_socket.rb
18
+ examples/inbound_socket_events.rb
19
+ examples/outbound_event_socket.rb
20
+ freeswitcher.gemspec
21
+ lib/fsr.rb
22
+ lib/fsr/app.rb
23
+ lib/fsr/app/answer.rb
24
+ lib/fsr/app/bridge.rb
25
+ lib/fsr/app/conference.rb
26
+ lib/fsr/app/fifo.rb
27
+ lib/fsr/app/fs_break.rb
28
+ lib/fsr/app/fs_sleep.rb
29
+ lib/fsr/app/hangup.rb
30
+ lib/fsr/app/limit.rb
31
+ lib/fsr/app/log.rb
32
+ lib/fsr/app/play_and_get_digits.rb
33
+ lib/fsr/app/playback.rb
34
+ lib/fsr/app/read.rb
35
+ lib/fsr/app/set.rb
36
+ lib/fsr/app/speak.rb
37
+ lib/fsr/app/transfer.rb
38
+ lib/fsr/app/uuid_dump.rb
39
+ lib/fsr/app/uuid_getvar.rb
40
+ lib/fsr/app/uuid_setvar.rb
41
+ lib/fsr/cmd.rb
42
+ lib/fsr/cmd/calls.rb
43
+ lib/fsr/cmd/fsctl.rb
44
+ lib/fsr/cmd/originate.rb
45
+ lib/fsr/cmd/sofia.rb
46
+ lib/fsr/cmd/sofia/profile.rb
47
+ lib/fsr/cmd/sofia/status.rb
48
+ lib/fsr/cmd/sofia_contact.rb
49
+ lib/fsr/cmd/status.rb
50
+ lib/fsr/command_socket.rb
51
+ lib/fsr/database.rb
52
+ lib/fsr/database/call_limit.rb
53
+ lib/fsr/database/core.rb
54
+ lib/fsr/database/sofia_reg_external.rb
55
+ lib/fsr/database/sofia_reg_internal.rb
56
+ lib/fsr/database/voicemail_default.rb
57
+ lib/fsr/event_socket.rb
58
+ lib/fsr/fake_socket.rb
59
+ lib/fsr/listener.rb
60
+ lib/fsr/listener/header_and_content_response.rb
61
+ lib/fsr/listener/inbound.rb
62
+ lib/fsr/listener/inbound/event.rb
63
+ lib/fsr/listener/outbound.rb
64
+ lib/fsr/listener/outbound.rb.orig
65
+ lib/fsr/model/call.rb
66
+ lib/fsr/version.rb
67
+ tasks/authors.rake
68
+ tasks/bacon.rake
69
+ tasks/changelog.rake
70
+ tasks/copyright.rake
71
+ tasks/gem.rake
72
+ tasks/gem_installer.rake
73
+ tasks/install_dependencies.rake
74
+ tasks/manifest.rake
75
+ tasks/rcov.rake
76
+ tasks/release.rake
77
+ tasks/reversion.rake
78
+ tasks/setup.rake
79
+ tasks/spec.rake
80
+ tasks/yard.rake
81
+ spec/helper.rb
82
+ spec/fsr/app.rb
83
+ spec/fsr/app/bridge.rb
84
+ spec/fsr/app/conference.rb
85
+ spec/fsr/app/fifo.rb
86
+ spec/fsr/app/hangup.rb
87
+ spec/fsr/app/limit.rb
88
+ spec/fsr/app/log.rb
89
+ spec/fsr/app/play_and_get_digits.rb
90
+ spec/fsr/app/playback.rb
91
+ spec/fsr/app/set.rb
92
+ spec/fsr/app/transfer.rb
93
+ spec/fsr/cmd.rb
94
+ spec/fsr/cmd/calls.rb
95
+ spec/fsr/cmd/originate.rb
96
+ spec/fsr/cmd/sofia.rb
97
+ spec/fsr/cmd/sofia/profile.rb
98
+ spec/fsr/listener.rb
99
+ spec/fsr/listener/inbound.rb
100
+ spec/fsr/listener/outbound.rb
101
+ spec/fsr/loading.rb
data/README CHANGED
@@ -4,108 +4,88 @@ Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger
4
4
  Distributed under the terms of the MIT License.
5
5
  ==========================================================
6
6
 
7
- About
7
+ ABOUT
8
8
  -----
9
- *** STILL UNDER HEAVY DEVELOPMENT ***
10
-
11
9
  A ruby library for interacting with the "FreeSWITCH" (http://www.freeswitch.org) opensource telephony platform
12
10
 
13
- *** STILL UNDER HEAVY DEVELOPMENT ***
14
-
15
- Requirements
11
+ REQUIREMENTS
16
12
  ------------
17
13
  - ruby (>= 1.8)
18
14
  - eventmachine (If you wish to use Outbound and Inbound listener)
19
15
 
20
- Usage
16
+ USAGE
21
17
  -----
22
18
 
23
- Example of originating a new call in 'irb' using FSR::CommandSocket#originate:
24
-
25
- irb(main):001:0> require 'fsr'
26
- => true
27
-
28
- irb(main):002:0> FSR.load_all_commands
29
- => [:sofia, :originate]
30
-
31
- irb(main):003:0> sock = FSR::CommandSocket.new
32
- => #<FSR::CommandSocket:0xb7a89104 @server="127.0.0.1", @socket=#<TCPSocket:0xb7a8908c>, @port="8021", @auth="ClueCon">
19
+ An Outbound Event Listener Example that reads and returns DTMF input:
20
+ --------------------------------------------------------------------
33
21
 
34
- irb(main):007:0> sock.originate(:target => 'sofia/gateway/carlos/8179395222', :endpoint => FSR::App::Bridge.new("user/bougyman")).run
35
- => {"Job-UUID"=>"732075a4-7dd5-4258-b124-6284a82a5ae7", "body"=>"", "Content-Type"=>"command/reply", "Reply-Text"=>"+OK Job-UUID: 732075a4-7dd5-4258-b124-6284a82a5ae7"}
36
-
37
-
38
- Example of creating an Outbound Eventsocket listener:
39
-
40
- #!/usr/bin/env ruby
22
+ Simply just create a subclass of FSR::Listner::Outbound and all
23
+ new calls/sessions will invoke the "session_initiated" callback method.
24
+
25
+ * NOTE: FSR uses blocks within the 'session_inititated' method to ensure
26
+ that the next "freeswich command" is not executed until the previous
27
+ "Freeswitch command" has finished. This is kicked off by "answer do"
41
28
 
42
29
  require 'fsr'
43
- require "fsr/listener/outbound"
30
+ require 'fsr/listener/outbound'
44
31
 
45
- class OesDemo < FSR::Listener::Outbound
32
+ class OutboundDemo < FSR::Listener::Outbound
46
33
 
47
34
  def session_initiated
48
- number = @session.headers[:caller_caller_id_number] # Grab the inbound caller id
49
- FSR::Log.info "*** Answering incoming call from #{number}"
50
- answer # Answer the call
51
- set("hangup_after_bridge", "true")# Set a variable
52
- speak 'Hello, This is your phone switch. Have a great day' # use mod_flite to speak
53
- hangup # Hangup the call
35
+ exten = @session.headers[:caller_caller_id_number]
36
+ FSR::Log.info "*** Answering incoming call from #{exten}"
37
+
38
+ answer do
39
+ FSR::Log.info "***Reading DTMF from #{exten}"
40
+ read("/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav", 4, 10, "input", 7000) do
41
+ FSR::Log.info "*** Updating session for #{exten}"
42
+ update_session do
43
+ FSR::Log.info "***Success, grabbed #{@session.headers[:variable_input].strip} from #{exten}"
44
+ hangup #Hangup the call
45
+ end
46
+ end
47
+ end
48
+
54
49
  end
55
50
 
56
51
  end
57
52
 
58
- FSR.start_oes!(OesDemo, :port => 1888, :host => "localhost")
53
+ FSR.start_oes! OutboundDemo, :port => 8084, :host => "127.0.0.1"
59
54
 
60
55
 
56
+ An Inbound Event Socket Listener example using FreeSWITCHeR's hook system:
57
+ --------------------------------------------------------------------------
61
58
 
62
- Example of creating an Outbound Eventsocket listener that can read DTMF input and keep state:
63
-
64
- #!/usr/bin/env ruby
65
-
59
+ require 'pp'
66
60
  require 'fsr'
67
- require 'fsr/listener/outbound'
68
-
69
- FSR.load_all_applications
70
- FSR.load_all_commands
61
+ require "fsr/listener/inbound"
71
62
 
72
- class DtmfDemo < FSR::Listener::Outbound
73
-
74
- def session_initiated
75
- exten = @session.headers[:caller_caller_id_number]
76
- FSR::Log.info "*** Answering incoming call from #{exten}"
77
- answer # Answer the call
78
- end
79
-
80
- def receive_reply(reply)
81
- exten = @session.headers[:caller_caller_id_number]
82
- case @step
83
- when 1
84
- FSR::Log.info "*** Reading dtmf for #{exten}"
85
- read "/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav",4,10,"test",15000 # read test
86
- when 2
87
- FSR::Log.info "*** updating session for #{exten}"
88
- update_session
89
- when 3
90
- FSR::Log.info "** Success, grabbed #{@session.headers[:variable_test].strip} from #{exten}"
91
- FSR::Log.info "*** Hanging up call"
92
- hangup # Hangup the call
93
- end
94
- end
63
+ # EXAMPLE 1
64
+ # 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
65
+ FSL::Inbound.add_event_hook(:CHANNEL_CREATE) {|event| FSR::Log.info "*** [#{event.content[:unique_id]}] Channel created - greetings from the hook!" }
95
66
 
67
+ # EXAMPLE 2
68
+ # Define a method to handle CHANNEL_HANGUP events.
69
+ def custom_channel_hangup_handler(event)
70
+ FSR::Log.info "*** [#{event.content[:unique_id]}] Channel hangup. The event:"
71
+ pp event
96
72
  end
97
73
 
98
- FSR.start_oes! DtmfDemo, :port => 8084, :host => "127.0.0.1"
74
+ # This adds a hook for EXAMPLE 2
75
+ FSL::Inbound.add_event_hook(:CHANNEL_HANGUP) {|event| custom_channel_hangup_handler(event) }
99
76
 
100
77
 
78
+ # Start FSR Inbound Listener
79
+ FSR.start_ies!(FSL::Inbound, :host => "localhost", :port => 8021)
101
80
 
102
- Example of creating an Inbound Eventsocket listener:
103
81
 
104
- #!/usr/bin/env ruby
82
+ An Inbound Event Socket Listener example using the on_event callback method instead of hooks:
83
+ ---------------------------------------------------------------------------------------------
105
84
 
106
- require 'fsr'
107
- require 'fsr/listener/inbound'
108
85
  require 'pp'
86
+ require 'fsr'
87
+ require "fsr/listener/inbound"
88
+
109
89
 
110
90
  class IesDemo < FSR::Listener::Inbound
111
91
 
@@ -119,8 +99,24 @@ Example of creating an Inbound Eventsocket listener:
119
99
  FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
120
100
 
121
101
 
102
+ An example of using FSR::CommandSocket to originate a new call in irb:
103
+ ----------------------------------------------------------------------
104
+
105
+ irb(main):001:0> require 'fsr'
106
+ => true
107
+
108
+ irb(main):002:0> FSR.load_all_commands
109
+ => [:sofia, :originate]
110
+
111
+ irb(main):003:0> sock = FSR::CommandSocket.new
112
+ => #<FSR::CommandSocket:0xb7a89104 @server="127.0.0.1", @socket=#<TCPSocket:0xb7a8908c>, @port="8021", @auth="ClueCon">
113
+
114
+ irb(main):007:0> sock.originate(:target => 'sofia/gateway/carlos/8179395222', :endpoint => FSR::App::Bridge.new("user/bougyman")).run
115
+ => {"Job-UUID"=>"732075a4-7dd5-4258-b124-6284a82a5ae7", "body"=>"", "Content-Type"=>"command/reply", "Reply-Text"=>"+OK Job-UUID: 732075a4-7dd5-4258-b124-6284a82a5ae7"}
116
+
117
+
122
118
 
123
- Support
119
+ SUPPORT
124
120
  -------
125
121
  Home page at http://code.rubyists.com/projects/fs
126
122
  #rubyists on FreeNode
data/Rakefile CHANGED
@@ -1,82 +1,36 @@
1
1
  require 'rake/clean'
2
2
  require "rubygems"
3
-
4
- import(*Dir['tasks/*rake'])
5
-
6
- task :default => :spec
7
-
8
- desc 'install dependencies'
9
- task :setup do
10
- GemSetup.new do
11
- github = 'http://gems.github.com'
12
- Gem.sources << github
13
-
14
- gem('bacon')
15
- setup
16
- end
3
+ require "lib/fsr"
4
+ require "pathname"
5
+
6
+ PROJECT_COPYRIGHT = File.read(Pathname.new(__FILE__).dirname.join("License.txt"))
7
+ PROJECT_README = Pathname.new(__FILE__).dirname.join("README").expand_path.to_s
8
+ PROJECT_FILES = %x{git ls-files}.split
9
+ RELEASE_FILES = PROJECT_FILES.reject { |f| f.match(/^(?:contrib)(?:\/|$)/) }
10
+ GEM_FILES = RELEASE_FILES.reject { |f| f.match(/^(?:spec)(?:\/|$)/) }
11
+ PROJECT_SPECS = (RELEASE_FILES - GEM_FILES).reject { |d| d.match(/(?:helper.rb)$/) }
12
+ GEM_FILES << "spec/helper.rb" if Pathname.new("spec/helper.rb").file?
13
+
14
+
15
+ GEMSPEC = Gem::Specification.new do |spec|
16
+ spec.name = "freeswitcher"
17
+ spec.version = ENV["FSR_VERSION"] || FSR::VERSION
18
+ spec.summary = 'A library for interacting with the "FreeSWITCH":http://freeswitch.org telephony platform'
19
+ spec.authors = ["Jayson Vaughn", "Michael Fellinger", "Kevin Berry", "TJ Vanderpoel"]
20
+ spec.email = "FreeSWITCHeR@rubyists.com"
21
+ spec.homepage = "http://code.rubyists.com/projects/fs"
22
+ spec.add_dependency "eventmachine"
23
+
24
+ spec.files = GEM_FILES
25
+ spec.test_files = PROJECT_SPECS
26
+ spec.require_path = "lib"
27
+
28
+ description = File.read(PROJECT_README)
29
+ spec.description = description
30
+ spec.rubyforge_project = "freeswitcher"
31
+ spec.post_install_message = description
17
32
  end
18
33
 
19
- class GemSetup
20
- def initialize(options = {}, &block)
21
- @gems = []
22
- @options = options
23
-
24
- run(&block)
25
- end
26
-
27
- def run(&block)
28
- instance_eval(&block) if block_given?
29
- end
30
-
31
- def gem(name, version = nil, options = {})
32
- if version.respond_to?(:merge!)
33
- options = version
34
- else
35
- options[:version] = version
36
- end
37
-
38
- @gems << [name, options]
39
- end
40
-
41
- def setup
42
- require 'rubygems'
43
- require 'rubygems/dependency_installer'
44
-
45
- @gems.each do |name, options|
46
- setup_gem(name, options)
47
- end
48
- end
49
-
50
- def setup_gem(name, options, try_install = true)
51
- print "activating #{name} ... "
52
- Gem.activate(name, *[options[:version]].compact)
53
- require(options[:lib] || name)
54
- puts "success."
55
- rescue LoadError => error
56
- puts error
57
- install_gem(name, options) if try_install
58
- setup_gem(name, options, try_install = false)
59
- end
60
-
61
- def install_gem(name, options)
62
- installer = Gem::DependencyInstaller.new(options)
63
-
64
- temp_argv(options[:extconf]) do
65
- print "Installing #{name} ... "
66
- installer.install(name, options[:version])
67
- puts "done."
68
- end
69
- end
70
-
71
- def temp_argv(extconf)
72
- if extconf ||= @options[:extconf]
73
- old_argv = ARGV.clone
74
- ARGV.replace(extconf.split(' '))
75
- end
76
-
77
- yield
34
+ import(*Dir['tasks/*rake'])
78
35
 
79
- ensure
80
- ARGV.replace(old_argv) if extconf
81
- end
82
- end
36
+ task :default => :bacon
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pp'
4
+ require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
5
+ $stdout.flush
6
+ require "fsr/listener/inbound"
7
+
8
+
9
+ class IesDemo < FSR::Listener::Inbound
10
+
11
+ def on_event(event)
12
+ pp event.headers
13
+ pp event.content[:event_name]
14
+ end
15
+
16
+ end
17
+
18
+ FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pp'
4
+ require File.join(File.dirname(__FILE__), "..", 'lib', 'fsr')
5
+ $stdout.flush
6
+ require "fsr/listener/inbound"
7
+
8
+ # EXAMPLE 1
9
+ # 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
10
+ FSL::Inbound.add_event_hook(:CHANNEL_CREATE) {|event| FSR::Log.info "*** [#{event.content[:unique_id]}] Channel created - greetings from the hook!" }
11
+
12
+ # EXAMPLE 2
13
+ # Define a method to handle CHANNEL_HANGUP events.
14
+ def custom_channel_hangup_handler(event)
15
+ FSR::Log.info "*** [#{event.content[:unique_id]}] Channel hangup. The event:"
16
+ pp event
17
+ end
18
+
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
+
@@ -0,0 +1,28 @@
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
+ class OutboundDemo < FSR::Listener::Outbound
8
+
9
+ def session_initiated
10
+ exten = @session.headers[:caller_caller_id_number]
11
+ FSR::Log.info "*** Answering incoming call from #{exten}"
12
+
13
+ answer do
14
+ FSR::Log.info "***Reading DTMF from #{exten}"
15
+ read("/home/freeswitch/freeswitch/sounds/music/8000/sweet.wav", 4, 10, "input", 7000) do
16
+ FSR::Log.info "*** Updating session for #{exten}"
17
+ update_session do
18
+ FSR::Log.info "***Success, grabbed #{@session.headers[:variable_input].strip} from #{exten}"
19
+ hangup #Hangup the call
20
+ end
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+ FSR.start_oes! OutboundDemo, :port => 8084, :host => "127.0.0.1"