freeswitcher 0.4.1 → 0.4.2

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.
data/MANIFEST CHANGED
@@ -39,6 +39,7 @@ lib/fsr/cmd/sofia/profile.rb
39
39
  lib/fsr/cmd/sofia/status.rb
40
40
  lib/fsr/cmd/sofia_contact.rb
41
41
  lib/fsr/cmd/status.rb
42
+ lib/fsr/cmd/uuid_dump.rb
42
43
  lib/fsr/command_socket.rb
43
44
  lib/fsr/database.rb
44
45
  lib/fsr/database/call_limit.rb
@@ -52,6 +53,7 @@ lib/fsr/listener.rb
52
53
  lib/fsr/listener/header_and_content_response.rb
53
54
  lib/fsr/listener/inbound.rb
54
55
  lib/fsr/listener/inbound/event.rb
56
+ lib/fsr/listener/mock.rb
55
57
  lib/fsr/listener/outbound.rb
56
58
  lib/fsr/model/call.rb
57
59
  lib/fsr/version.rb
@@ -63,13 +65,13 @@ tasks/gem.rake
63
65
  tasks/gem_installer.rake
64
66
  tasks/install_dependencies.rake
65
67
  tasks/manifest.rake
66
- tasks/rcov.rake
67
68
  tasks/release.rake
68
69
  tasks/reversion.rake
69
70
  tasks/setup.rake
70
71
  tasks/spec.rake
71
72
  tasks/yard.rake
72
73
  spec/helper.rb
74
+ spec/fsr_listener_helper.rb
73
75
  spec/fsr/app.rb
74
76
  spec/fsr/app/answer.rb
75
77
  spec/fsr/app/bridge.rb
@@ -89,6 +91,7 @@ spec/fsr/cmd/calls.rb
89
91
  spec/fsr/cmd/originate.rb
90
92
  spec/fsr/cmd/sofia.rb
91
93
  spec/fsr/cmd/sofia/profile.rb
94
+ spec/fsr/cmd/uuid_dump.rb
92
95
  spec/fsr/listener.rb
93
96
  spec/fsr/listener/header_and_content_response.rb
94
97
  spec/fsr/listener/inbound.rb
data/README CHANGED
@@ -97,7 +97,7 @@ An Inbound Event Socket Listener example using the on_event callback method inst
97
97
 
98
98
  end
99
99
 
100
- FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
100
+ FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021, :auth => "ClueCon")
101
101
 
102
102
 
103
103
  An example of using FSR::CommandSocket to originate a new call in irb:
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ RELEASE_FILES = PROJECT_FILES.reject { |f| f.match(/^(?:contrib)(?:\/|$)/) }
10
10
  GEM_FILES = RELEASE_FILES.reject { |f| f.match(/^(?:spec)(?:\/|$)/) }
11
11
  PROJECT_SPECS = (RELEASE_FILES - GEM_FILES).reject { |d| d.match(/(?:helper.rb)$/) }
12
12
  GEM_FILES << "spec/helper.rb" if Pathname("spec/helper.rb").file?
13
+ GEM_FILES << "spec/fsr_listener_helper.rb" if Pathname("spec/helper.rb").file?
13
14
 
14
15
 
15
16
  GEMSPEC = Gem::Specification.new do |spec|
@@ -15,4 +15,4 @@ class IesDemo < FSR::Listener::Inbound
15
15
 
16
16
  end
17
17
 
18
- FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
18
+ FSR.start_ies!(IesDemo, :host => "pip", :port => 8021, :auth => "ClueCon")
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{freeswitcher}
5
- s.version = "0.4.1"
5
+ s.version = "0.4.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jayson Vaughn", "Michael Fellinger", "Kevin Berry", "TJ Vanderpoel"]
9
- s.date = %q{2009-06-03}
9
+ s.date = %q{2009-07-03}
10
10
  s.description = %q{=========================================================
11
11
  FreeSWITCHeR
12
12
  Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger, Kevin Berry)
@@ -106,7 +106,7 @@ An Inbound Event Socket Listener example using the on_event callback method inst
106
106
 
107
107
  end
108
108
 
109
- FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
109
+ FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021, :auth => "ClueCon")
110
110
 
111
111
 
112
112
  An example of using FSR::CommandSocket to originate a new call in irb:
@@ -132,7 +132,7 @@ Home page at http://code.rubyists.com/projects/fs
132
132
  #rubyists on FreeNode
133
133
  }
134
134
  s.email = %q{FreeSWITCHeR@rubyists.com}
135
- s.files = [".gitignore", "AUTHORS", "CHANGELOG", "License.txt", "MANIFEST", "NEWS", "README", "Rakefile", "examples/inbound_event_socket.rb", "examples/inbound_socket_events.rb", "examples/outbound_event_socket.rb", "freeswitcher.gemspec", "lib/fsr.rb", "lib/fsr/app.rb", "lib/fsr/app/answer.rb", "lib/fsr/app/bridge.rb", "lib/fsr/app/conference.rb", "lib/fsr/app/fifo.rb", "lib/fsr/app/fs_break.rb", "lib/fsr/app/fs_sleep.rb", "lib/fsr/app/hangup.rb", "lib/fsr/app/limit.rb", "lib/fsr/app/log.rb", "lib/fsr/app/play_and_get_digits.rb", "lib/fsr/app/playback.rb", "lib/fsr/app/read.rb", "lib/fsr/app/set.rb", "lib/fsr/app/speak.rb", "lib/fsr/app/transfer.rb", "lib/fsr/app/uuid_dump.rb", "lib/fsr/app/uuid_getvar.rb", "lib/fsr/app/uuid_setvar.rb", "lib/fsr/cmd.rb", "lib/fsr/cmd/calls.rb", "lib/fsr/cmd/fsctl.rb", "lib/fsr/cmd/originate.rb", "lib/fsr/cmd/sofia.rb", "lib/fsr/cmd/sofia/profile.rb", "lib/fsr/cmd/sofia/status.rb", "lib/fsr/cmd/sofia_contact.rb", "lib/fsr/cmd/status.rb", "lib/fsr/command_socket.rb", "lib/fsr/database.rb", "lib/fsr/database/call_limit.rb", "lib/fsr/database/core.rb", "lib/fsr/database/sofia_reg_external.rb", "lib/fsr/database/sofia_reg_internal.rb", "lib/fsr/database/voicemail_default.rb", "lib/fsr/event_socket.rb", "lib/fsr/fake_socket.rb", "lib/fsr/listener.rb", "lib/fsr/listener/header_and_content_response.rb", "lib/fsr/listener/inbound.rb", "lib/fsr/listener/inbound/event.rb", "lib/fsr/listener/outbound.rb", "lib/fsr/model/call.rb", "lib/fsr/version.rb", "tasks/authors.rake", "tasks/bacon.rake", "tasks/changelog.rake", "tasks/copyright.rake", "tasks/gem.rake", "tasks/gem_installer.rake", "tasks/install_dependencies.rake", "tasks/manifest.rake", "tasks/rcov.rake", "tasks/release.rake", "tasks/reversion.rake", "tasks/setup.rake", "tasks/spec.rake", "tasks/yard.rake", "spec/helper.rb", "spec/fsr/app.rb", "spec/fsr/app/answer.rb", "spec/fsr/app/bridge.rb", "spec/fsr/app/conference.rb", "spec/fsr/app/fifo.rb", "spec/fsr/app/fs_break.rb", "spec/fsr/app/fs_sleep.rb", "spec/fsr/app/hangup.rb", "spec/fsr/app/limit.rb", "spec/fsr/app/log.rb", "spec/fsr/app/play_and_get_digits.rb", "spec/fsr/app/playback.rb", "spec/fsr/app/set.rb", "spec/fsr/app/transfer.rb", "spec/fsr/cmd.rb", "spec/fsr/cmd/calls.rb", "spec/fsr/cmd/originate.rb", "spec/fsr/cmd/sofia.rb", "spec/fsr/cmd/sofia/profile.rb", "spec/fsr/listener.rb", "spec/fsr/listener/header_and_content_response.rb", "spec/fsr/listener/inbound.rb", "spec/fsr/listener/outbound.rb", "spec/fsr/loading.rb"]
135
+ s.files = [".gitignore", "AUTHORS", "CHANGELOG", "License.txt", "MANIFEST", "NEWS", "README", "Rakefile", "examples/inbound_event_socket.rb", "examples/inbound_socket_events.rb", "examples/outbound_event_socket.rb", "freeswitcher.gemspec", "lib/fsr.rb", "lib/fsr/app.rb", "lib/fsr/app/answer.rb", "lib/fsr/app/bridge.rb", "lib/fsr/app/conference.rb", "lib/fsr/app/fifo.rb", "lib/fsr/app/fs_break.rb", "lib/fsr/app/fs_sleep.rb", "lib/fsr/app/hangup.rb", "lib/fsr/app/limit.rb", "lib/fsr/app/log.rb", "lib/fsr/app/play_and_get_digits.rb", "lib/fsr/app/playback.rb", "lib/fsr/app/read.rb", "lib/fsr/app/set.rb", "lib/fsr/app/speak.rb", "lib/fsr/app/transfer.rb", "lib/fsr/app/uuid_dump.rb", "lib/fsr/app/uuid_getvar.rb", "lib/fsr/app/uuid_setvar.rb", "lib/fsr/cmd.rb", "lib/fsr/cmd/calls.rb", "lib/fsr/cmd/fsctl.rb", "lib/fsr/cmd/originate.rb", "lib/fsr/cmd/sofia.rb", "lib/fsr/cmd/sofia/profile.rb", "lib/fsr/cmd/sofia/status.rb", "lib/fsr/cmd/sofia_contact.rb", "lib/fsr/cmd/status.rb", "lib/fsr/cmd/uuid_dump.rb", "lib/fsr/command_socket.rb", "lib/fsr/database.rb", "lib/fsr/database/call_limit.rb", "lib/fsr/database/core.rb", "lib/fsr/database/sofia_reg_external.rb", "lib/fsr/database/sofia_reg_internal.rb", "lib/fsr/database/voicemail_default.rb", "lib/fsr/event_socket.rb", "lib/fsr/fake_socket.rb", "lib/fsr/listener.rb", "lib/fsr/listener/header_and_content_response.rb", "lib/fsr/listener/inbound.rb", "lib/fsr/listener/inbound/event.rb", "lib/fsr/listener/mock.rb", "lib/fsr/listener/outbound.rb", "lib/fsr/model/call.rb", "lib/fsr/version.rb", "tasks/authors.rake", "tasks/bacon.rake", "tasks/changelog.rake", "tasks/copyright.rake", "tasks/gem.rake", "tasks/gem_installer.rake", "tasks/install_dependencies.rake", "tasks/manifest.rake", "tasks/release.rake", "tasks/reversion.rake", "tasks/setup.rake", "tasks/spec.rake", "tasks/yard.rake", "spec/helper.rb", "spec/fsr_listener_helper.rb", "spec/fsr/app.rb", "spec/fsr/app/answer.rb", "spec/fsr/app/bridge.rb", "spec/fsr/app/conference.rb", "spec/fsr/app/fifo.rb", "spec/fsr/app/fs_break.rb", "spec/fsr/app/fs_sleep.rb", "spec/fsr/app/hangup.rb", "spec/fsr/app/limit.rb", "spec/fsr/app/log.rb", "spec/fsr/app/play_and_get_digits.rb", "spec/fsr/app/playback.rb", "spec/fsr/app/set.rb", "spec/fsr/app/transfer.rb", "spec/fsr/cmd.rb", "spec/fsr/cmd/calls.rb", "spec/fsr/cmd/originate.rb", "spec/fsr/cmd/sofia.rb", "spec/fsr/cmd/sofia/profile.rb", "spec/fsr/cmd/uuid_dump.rb", "spec/fsr/listener.rb", "spec/fsr/listener/header_and_content_response.rb", "spec/fsr/listener/inbound.rb", "spec/fsr/listener/outbound.rb", "spec/fsr/loading.rb"]
136
136
  s.homepage = %q{http://code.rubyists.com/projects/fs}
137
137
  s.post_install_message = %q{=========================================================
138
138
  FreeSWITCHeR
@@ -233,7 +233,7 @@ An Inbound Event Socket Listener example using the on_event callback method inst
233
233
 
234
234
  end
235
235
 
236
- FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021)
236
+ FSR.start_ies!(IesDemo, :host => "localhost", :port => 8021, :auth => "ClueCon")
237
237
 
238
238
 
239
239
  An example of using FSR::CommandSocket to originate a new call in irb:
@@ -260,9 +260,9 @@ Home page at http://code.rubyists.com/projects/fs
260
260
  }
261
261
  s.require_paths = ["lib"]
262
262
  s.rubyforge_project = %q{freeswitcher}
263
- s.rubygems_version = %q{1.3.3}
263
+ s.rubygems_version = %q{1.3.4}
264
264
  s.summary = %q{A library for interacting with the "FreeSWITCH":http://freeswitch.org telephony platform}
265
- s.test_files = ["spec/fsr/app.rb", "spec/fsr/app/answer.rb", "spec/fsr/app/bridge.rb", "spec/fsr/app/conference.rb", "spec/fsr/app/fifo.rb", "spec/fsr/app/fs_break.rb", "spec/fsr/app/fs_sleep.rb", "spec/fsr/app/hangup.rb", "spec/fsr/app/limit.rb", "spec/fsr/app/log.rb", "spec/fsr/app/play_and_get_digits.rb", "spec/fsr/app/playback.rb", "spec/fsr/app/set.rb", "spec/fsr/app/transfer.rb", "spec/fsr/cmd.rb", "spec/fsr/cmd/calls.rb", "spec/fsr/cmd/originate.rb", "spec/fsr/cmd/sofia.rb", "spec/fsr/cmd/sofia/profile.rb", "spec/fsr/listener.rb", "spec/fsr/listener/header_and_content_response.rb", "spec/fsr/listener/inbound.rb", "spec/fsr/listener/outbound.rb", "spec/fsr/loading.rb"]
265
+ s.test_files = ["spec/fsr/app.rb", "spec/fsr/app/answer.rb", "spec/fsr/app/bridge.rb", "spec/fsr/app/conference.rb", "spec/fsr/app/fifo.rb", "spec/fsr/app/fs_break.rb", "spec/fsr/app/fs_sleep.rb", "spec/fsr/app/hangup.rb", "spec/fsr/app/limit.rb", "spec/fsr/app/log.rb", "spec/fsr/app/play_and_get_digits.rb", "spec/fsr/app/playback.rb", "spec/fsr/app/set.rb", "spec/fsr/app/transfer.rb", "spec/fsr/cmd.rb", "spec/fsr/cmd/calls.rb", "spec/fsr/cmd/originate.rb", "spec/fsr/cmd/sofia.rb", "spec/fsr/cmd/sofia/profile.rb", "spec/fsr/cmd/uuid_dump.rb", "spec/fsr/listener.rb", "spec/fsr/listener/header_and_content_response.rb", "spec/fsr/listener/inbound.rb", "spec/fsr/listener/outbound.rb", "spec/fsr/loading.rb"]
266
266
 
267
267
  if s.respond_to? :specification_version then
268
268
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
data/lib/fsr.rb CHANGED
@@ -8,6 +8,11 @@ require 'pp'
8
8
 
9
9
  ## This module declares the namespace under which the freeswitcher framework
10
10
  ## Any constants will be defined here, as well as methods for loading commands and applications
11
+ class Pathname
12
+ def /(other)
13
+ join(other.to_s)
14
+ end
15
+ end
11
16
  module FSR
12
17
  # Global configuration options
13
18
  FS_INSTALL_PATHS = ["/usr/local/freeswitch", "/opt/freeswitch", "/usr/freeswitch", "/home/freeswitch/freeswitch"]
@@ -46,10 +51,10 @@ module FSR
46
51
 
47
52
  # Method to start EM for Outbound Event Socket
48
53
  def self.start_oes!(klass, args = {})
49
- port = args[:port] || "8084"
50
- host = args[:host] || "localhost"
54
+ port = args.delete(:port) || "8084"
55
+ host = args.delete(:host) || "localhost"
51
56
  EM.run do
52
- EventMachine::start_server(host, port, klass)
57
+ EventMachine::start_server(host, port, klass, args)
53
58
  FSR::Log.info "*** FreeSWITCHer Outbound EventSocket Listener on #{host}:#{port} ***"
54
59
  FSR::Log.info "*** http://code.rubyists.com/projects/fs"
55
60
  end
@@ -62,10 +67,10 @@ module FSR
62
67
  # <tt>:host [String]</tt> The host/ip to bind to (Default: "localhost")
63
68
  # <tt>:port [Integer]</tt> the port to listen on (Default: 8021)
64
69
  def self.start_ies!(klass, args = {})
65
- port = args[:port] || 8021
66
- host = args[:host] || "localhost"
70
+ port = args.delete(:port) || "8084"
71
+ host = args.delete(:host) || "localhost"
67
72
  EM.run do
68
- EventMachine::connect(host, port, klass)
73
+ EventMachine::connect(host, port, klass, args)
69
74
  FSR::Log.info "*** FreeSWITCHer Inbound EventSocket Listener connected to #{host}:#{port} ***"
70
75
  FSR::Log.info "*** http://code.rubyists.com/projects/fs"
71
76
  end
@@ -0,0 +1,27 @@
1
+ require "fsr/app"
2
+ module FSR
3
+ module Cmd
4
+ class UuidDump < Command
5
+ attr_reader :uuid
6
+
7
+ def initialize(fs_socket = nil, unique_id = nil)
8
+ @fs_socket = fs_socket # FSR::CommandSocket obj
9
+ @uuid = unique_id # Freeswitch Unique ID to dump
10
+ end
11
+
12
+ # Send the command to the event socket, using bgapi by default.
13
+ def run(api_method = :api)
14
+ orig_command = "%s %s" % [api_method, raw]
15
+ Log.debug "saying #{orig_command}"
16
+ @fs_socket.say(orig_command)
17
+ end
18
+
19
+ # This method builds the API command to send to the freeswitch event socket
20
+ def raw
21
+ orig_command = "uuid_dump #{uuid}"
22
+ end
23
+ end
24
+
25
+ register(:uuid_dump, UuidDump)
26
+ end
27
+ end
@@ -6,6 +6,8 @@ require 'fsr/listener/header_and_content_response.rb'
6
6
  module FSR
7
7
  module Listener
8
8
  class Inbound < EventMachine::Protocols::HeaderAndContentProtocol
9
+ attr_reader :auth
10
+
9
11
  HOOKS = {}
10
12
 
11
13
  def initialize(args = {})
@@ -0,0 +1,23 @@
1
+ module FSR
2
+ module Listener
3
+ # This module is intended to be used with em-spec
4
+ module Mock
5
+
6
+ def send_data(data)
7
+ sent_data << data
8
+ end
9
+
10
+ def sent_data
11
+ @sent_data ||= []
12
+ end
13
+
14
+ def receive_reply(reply)
15
+ replies << reply
16
+ end
17
+
18
+ def replies
19
+ @recvd_reply ||= []
20
+ end
21
+ end
22
+ end
23
+ end
@@ -53,7 +53,6 @@ module FSR
53
53
 
54
54
  def sendmsg(message)
55
55
  text = message.respond_to?(:sendmsg) ? message.sendmsg : message.to_s
56
- FSR::Log.debug "sending #{text}"
57
56
  message = "sendmsg\n%s\n" % text
58
57
  self.respond_to?(:send_data) ? send_data(message) : message
59
58
  end
@@ -1,3 +1,3 @@
1
1
  module FSR
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -0,0 +1,13 @@
1
+ require 'spec/helper'
2
+ require "fsr/cmd"
3
+ FSR::Cmd.load_command("uuid_dump")
4
+
5
+ describe "Testing FSR::Cmd::UuidDump" do
6
+ ## Calls ##
7
+ # Interface to calls
8
+ it "FSR::Cmd::UuidDump should send uuid_dump <uid>" do
9
+ cmd = FSR::Cmd::UuidDump.new(nil, "abcd-1234-efgh-5678")
10
+ cmd.raw.should == "uuid_dump abcd-1234-efgh-5678"
11
+ end
12
+
13
+ end
@@ -1,13 +1,26 @@
1
1
  require 'spec/helper'
2
+ require "fsr/listener"
2
3
  require "fsr/listener/inbound"
4
+ gem "tmm1-em-spec"
5
+ require "em/spec"
3
6
 
4
7
  # Bare class to use for testing
5
- class MyListener < FSR::Listener::Inbound
6
- end
8
+ class InboundListener < FSR::Listener::Inbound
9
+ attr_accessor :test_event
10
+
11
+ def initialize(*args)
12
+ super(*args)
13
+ @test_event = nil
14
+ end
15
+
16
+ def on_event(event)
17
+ recvd_event << event
18
+ end
19
+
20
+ def recvd_event
21
+ @recvd_event ||= []
22
+ end
7
23
 
8
- # helper to instantiate a new MyListener
9
- def my_listener
10
- MyListener.new
11
24
  end
12
25
 
13
26
  describe "Testing FSR::Listener::Inbound" do
@@ -24,3 +37,30 @@ describe "Testing FSR::Listener::Inbound" do
24
37
  end
25
38
 
26
39
  end
40
+
41
+ EM.describe InboundListener do
42
+
43
+ before do
44
+ @listener = InboundListener.new("test", {:auth => 'SecretPassword'})
45
+ end
46
+
47
+ should "be able to receive an event and call the on_event callback method" do
48
+ @listener.receive_data("Content-Length: 22\n\nEvent-Name: test_event\n\n")
49
+ @listener.recvd_event.first.content[:event_name].should.equal "test_event"
50
+ done
51
+ end
52
+
53
+ should "be able to add custom event hooks" do
54
+ FSL::Inbound.add_event_hook(:HANGUP_EVENT) {|event| @listener.test_event = event}
55
+ @listener.test_event.should.equal nil
56
+ @listener.receive_data("Content-Length: 24\n\nEvent-Name: HANGUP_EVENT\n\n")
57
+ @listener.test_event.content[:event_name].should.equal "HANGUP_EVENT"
58
+ done
59
+ end
60
+
61
+ should "be able to change Freeswitch auth" do
62
+ @listener.auth.should.equal 'SecretPassword'
63
+ done
64
+ end
65
+
66
+ end
@@ -1,19 +1,119 @@
1
- require 'spec/helper'
2
- require "fsr/listener/outbound"
1
+ require "lib/fsr"
2
+ require FSR::ROOT/".."/:spec/:helper
3
+ require FSR::ROOT/:fsr/:listener/:outbound
4
+ gem "tmm1-em-spec"
5
+ require "em/spec"
3
6
 
4
7
  # Bare class to use for testing
5
8
  class MyListener < FSR::Listener::Outbound
6
- end
9
+ attr_accessor :recvd_reply, :state_machine_test
10
+
11
+ def session_initiated
12
+ end
13
+
14
+ def send_data(data)
15
+ sent_data << data
16
+ end
17
+
18
+ def sent_data
19
+ @sent_data ||= ''
20
+ end
21
+
22
+ def receive_reply(reply)
23
+ recvd_reply << reply
24
+ end
25
+
26
+ def recvd_reply
27
+ @recvd_reply ||= []
28
+ end
29
+
30
+ def do_something(&block)
31
+ @queue.unshift block if block_given?
32
+ end
33
+
34
+ def test_state_machine
35
+ @state_machine_test = nil
36
+ do_something do
37
+ @state_machine_test = "one"
38
+
39
+ do_something do
40
+ @state_machine_test = "two"
41
+
42
+ do_something do
43
+ @state_machine_test = "three"
44
+ end
45
+ end
46
+ end
47
+ end
7
48
 
8
- # helper to instantiate a new MyListener
9
- def my_listener
10
- MyListener.new
11
49
  end
12
50
 
13
- describe "Testing FSR::Listener::Outbound" do
51
+ # Begin testing MyListener
52
+ EM.describe MyListener do
53
+
54
+ before do
55
+ @listener = MyListener.new(nil)
56
+ end
57
+
58
+ should "send connect to freeswitch upon a new connection" do
59
+ @listener.receive_data("Content-Length: 0\nCaller-Caller-ID-Number: 8675309\n\n")
60
+ @listener.sent_data.should.equal "connect\n\n"
61
+ done
62
+ end
63
+
64
+ should "be able to receive a connection and establish a session " do
65
+ @listener.receive_data("Content-Length: 0\nTest: Testing\n\n")
66
+ @listener.session.class.should.equal FSR::Listener::HeaderAndContentResponse
67
+ done
68
+ end
69
+
70
+ should "be able to read FreeSWITCH channel variables through session" do
71
+ @listener.receive_data("Content-Length: 0\nCaller-Caller-ID-Number: 8675309\n\n")
72
+ @listener.session.headers[:caller_caller_id_number].should.equal "8675309"
73
+ done
74
+ end
75
+
76
+ should "be able to receive and process a response if not sent in one transmission" do
77
+ @listener.receive_data("Content-Length: ")
78
+ @listener.receive_data("0\nCaller-Caller-")
79
+ @listener.receive_data("ID-Number: 8675309\n\n")
80
+ @listener.session.headers[:caller_caller_id_number].should.equal "8675309"
81
+ done
82
+ end
83
+
84
+ should "be able to dispatch our receive_reply callback method after a session is already established" do
85
+ # This should establish the session
86
+ @listener.receive_data("Content-Length: 0\nTest-Data: foo\n\n")
87
+
88
+ # This should be a response, not a session
89
+ @listener.receive_data("Content-Length: 0\nTest-Reply: bar\n\n")
90
+
91
+ @listener.session.headers[:test_data].should.equal 'foo'
92
+ @listener.recvd_reply.first.headers[:test_reply].should.equal 'bar'
93
+ done
94
+ end
95
+
96
+ should "use procs to 'fake' I/O blocking and wait for a response before calling the next proc" do
97
+ @listener.receive_data("Content-Length: 0\nEstablished-Session: session\n\n")
98
+ @listener.test_state_machine
99
+ @listener.state_machine_test.should.equal nil
100
+ @listener.receive_data("Content-Length: 3\n\nOk\n\n")
101
+ @listener.state_machine_test.should.equal "one"
102
+ @listener.receive_data("Content-Length: 3\n\nOk\n\n")
103
+ @listener.state_machine_test.should.equal "two"
104
+ @listener.receive_data("Content-Length: 3\n\nOk\n\n")
105
+ @listener.state_machine_test.should.equal "three"
106
+ done
107
+ end
14
108
 
15
- it "defines #post_init" do
16
- FSR::Listener::Outbound.method_defined?(:post_init).should == true
109
+ should "be able to update an existing session" do
110
+ @listener.receive_data("Content-Length: 0\nUnique-ID: abcd-1234-efgh-5678\n\n")
111
+ @listener.session.headers[:unique_id].should.equal "abcd-1234-efgh-5678"
112
+ @listener.session.headers[:test_var].should.equal nil
113
+ @listener.update_session
114
+ @listener.receive_data("Content-Length: 74\n\nEvent-Name: CHANNEL_DATA\nUnique-ID: abcd-1234-efgh-5678\nTest-Var: foobar\n\n")
115
+ @listener.session.headers[:test_var].should.equal "foobar"
116
+ done
17
117
  end
18
118
 
19
119
  end
@@ -16,7 +16,7 @@ describe "Testing FSR module loading methods" do
16
16
 
17
17
  # When you add commands you must modify the expected cmds_loaded behavior
18
18
  it "Loads all commands" do
19
- all_commands = [:originate, :sofia, :fsctl, :sofia_contact, :status, :calls] # If you add a command add it to this set
19
+ all_commands = [:uuid_dump, :originate, :sofia, :fsctl, :sofia_contact, :status, :calls] # If you add a command add it to this set
20
20
  cmds_loaded = FSR.load_all_commands
21
21
  cmds_loaded.kind_of?(Array).should == true
22
22
  all_commands.each do |cmd|