freeswitcher 0.0.12 → 0.0.13
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/README +6 -8
- data/examples/dtmf_test.rb +4 -6
- data/examples/oes_demo.rb +2 -2
- data/lib/fsr.rb +1 -1
- data/lib/fsr/listener/outbound.rb +59 -32
- metadata +8 -10
data/README
CHANGED
@@ -44,8 +44,8 @@ Example of creating an Outbound Eventsocket listener:
|
|
44
44
|
|
45
45
|
class OesDemo < FSR::Listener::Outbound
|
46
46
|
|
47
|
-
def session_initiated
|
48
|
-
number = session.headers[:caller_caller_id_number] # Grab the inbound caller id
|
47
|
+
def session_initiated
|
48
|
+
number = @session.headers[:caller_caller_id_number] # Grab the inbound caller id
|
49
49
|
FSR::Log.info "*** Answering incoming call from #{number}"
|
50
50
|
answer # Answer the call
|
51
51
|
set("hangup_after_bridge", "true")# Set a variable
|
@@ -71,16 +71,14 @@ Example of creating an Outbound Eventsocket listener that can read DTMF input an
|
|
71
71
|
|
72
72
|
class DtmfDemo < FSR::Listener::Outbound
|
73
73
|
|
74
|
-
def session_initiated
|
75
|
-
|
76
|
-
exten = session.headers[:channel_caller_id_number]
|
74
|
+
def session_initiated
|
75
|
+
exten = @session.headers[:caller_caller_id_number]
|
77
76
|
FSR::Log.info "*** Answering incoming call from #{exten}"
|
78
77
|
answer # Answer the call
|
79
78
|
end
|
80
79
|
|
81
80
|
def receive_reply(reply)
|
82
|
-
exten = @session.headers[:
|
83
|
-
@step += 1
|
81
|
+
exten = @session.headers[:caller_caller_id_number]
|
84
82
|
case @step
|
85
83
|
when 1
|
86
84
|
FSR::Log.info "*** Reading dtmf for #{exten}"
|
@@ -89,7 +87,7 @@ Example of creating an Outbound Eventsocket listener that can read DTMF input an
|
|
89
87
|
FSR::Log.info "*** updating session for #{exten}"
|
90
88
|
update_session
|
91
89
|
when 3
|
92
|
-
FSR::Log.info "** Success, grabbed #{
|
90
|
+
FSR::Log.info "** Success, grabbed #{@session.headers[:variable_test].strip} from #{exten}"
|
93
91
|
FSR::Log.info "*** Hanging up call"
|
94
92
|
hangup # Hangup the call
|
95
93
|
end
|
data/examples/dtmf_test.rb
CHANGED
@@ -8,16 +8,14 @@ FSR.load_all_applications
|
|
8
8
|
FSR.load_all_commands
|
9
9
|
class DtmfDemo < FSR::Listener::Outbound
|
10
10
|
|
11
|
-
def session_initiated
|
12
|
-
|
13
|
-
exten = session.headers[:channel_caller_id_number]
|
11
|
+
def session_initiated
|
12
|
+
exten = @session.headers[:caller_caller_id_number]
|
14
13
|
FSR::Log.info "*** Answering incoming call from #{exten}"
|
15
14
|
answer # Answer the call
|
16
15
|
end
|
17
16
|
|
18
17
|
def receive_reply(reply)
|
19
|
-
exten = @session.headers[:
|
20
|
-
@step += 1
|
18
|
+
exten = @session.headers[:caller_caller_id_number]
|
21
19
|
case @step
|
22
20
|
when 1
|
23
21
|
FSR::Log.info "*** Reading dtmf for #{exten}"
|
@@ -26,7 +24,7 @@ class DtmfDemo < FSR::Listener::Outbound
|
|
26
24
|
FSR::Log.info "*** updating session for #{exten}"
|
27
25
|
update_session
|
28
26
|
when 3
|
29
|
-
FSR::Log.info "** Success, grabbed #{
|
27
|
+
FSR::Log.info "** Success, grabbed #{@session.headers[:variable_test].strip} from #{exten}"
|
30
28
|
FSR::Log.info "*** Hanging up call"
|
31
29
|
hangup # Hangup the call
|
32
30
|
end
|
data/examples/oes_demo.rb
CHANGED
@@ -6,8 +6,8 @@ require "fsr/listener/outbound"
|
|
6
6
|
|
7
7
|
class OesDemo < FSR::Listener::Outbound
|
8
8
|
|
9
|
-
def session_initiated
|
10
|
-
number = session.headers[:caller_caller_id_number] # Grab the inbound caller id
|
9
|
+
def session_initiated
|
10
|
+
number = @session.headers[:caller_caller_id_number] # Grab the inbound caller id
|
11
11
|
FSR::Log.info "*** Answering incoming call from #{number}"
|
12
12
|
answer # Answer the call
|
13
13
|
log("1", "Pong from the FSR event socket!")
|
data/lib/fsr.rb
CHANGED
@@ -7,6 +7,7 @@ module FSR
|
|
7
7
|
load_all_applications
|
8
8
|
module Listener
|
9
9
|
class Outbound < EventMachine::Protocols::HeaderAndContentProtocol
|
10
|
+
attr_reader :session
|
10
11
|
|
11
12
|
# Include FSR::App to get all the applications defined as methods
|
12
13
|
include FSR::App
|
@@ -15,40 +16,23 @@ module FSR
|
|
15
16
|
SENDMSG_METHOD_DEFINITION = "def %s(*args, &block); sendmsg super; end"
|
16
17
|
APPLICATIONS.each { |app, obj| module_eval(SENDMSG_METHOD_DEFINITION % app.to_s) }
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
# session_initiated is called when a @session is first created.
|
20
|
+
# Overwrite this in your worker class with the call/channel
|
21
|
+
# handling logic you desire
|
22
|
+
def session_initiated
|
23
|
+
FSR::Log.warn "#{self.class.name}#session_initiated not overwritten"
|
24
|
+
FSR::Log.debug session_data.inspect
|
22
25
|
end
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
receive_reply(session)
|
34
|
-
else
|
35
|
-
if session.headers[:event_name].to_s.match(/CHANNEL_DATA/i)
|
36
|
-
@session = session
|
37
|
-
receive_reply(HeaderAndConentResponse.new({:headers => {:session => "update"}, :content => {}}))
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Received data dispatches the data received by the EM socket,
|
44
|
-
# Either as a Session, a continuation of a Session, or as a Session's last CommandReply
|
45
|
-
|
46
|
-
def session_initiated(session)
|
47
|
-
session
|
48
|
-
end
|
49
|
-
|
50
|
-
def receive_reply(session)
|
51
|
-
session
|
27
|
+
# receive_reply is called when a response is received.
|
28
|
+
# Overwrite this in your worker class with the call/channel
|
29
|
+
# handling logic you desire, taking @step into account for
|
30
|
+
# state management between commands
|
31
|
+
# @param reply This HeaderAndContent instance will have the channel variables
|
32
|
+
# in #content, if the session has been updated
|
33
|
+
def receive_reply(reply)
|
34
|
+
FSR::Log.warn "#{self.class.name}#receive_reply not overwritten"
|
35
|
+
FSR::Log.debug reply.inspect
|
52
36
|
end
|
53
37
|
|
54
38
|
# sendmsg sends data to the EM app socket via #send_data, or
|
@@ -69,7 +53,50 @@ module FSR
|
|
69
53
|
send_data("api uuid_dump #{@session.headers[:unique_id]}\n\n")
|
70
54
|
end
|
71
55
|
|
56
|
+
protected
|
57
|
+
def post_init
|
58
|
+
@session = nil # holds the session object
|
59
|
+
send_data("connect\n\n")
|
60
|
+
FSR::Log.debug "Accepting connections."
|
61
|
+
end
|
62
|
+
|
63
|
+
# receive_request is called each time data is received by the event machine
|
64
|
+
# it will manipulate the received data into either a new session or a reply,
|
65
|
+
# to be picked up by #session_initiated or #receive_reply.
|
66
|
+
# If your listener is listening for events, this will also renew your @session
|
67
|
+
# each time you receive a CHANNEL_DATA event.
|
68
|
+
# @param header The header of the request, as passed by HeaderAndContentProtocol
|
69
|
+
# @param content The content of the request, as passed by HeaderAndContentProtocol
|
70
|
+
#
|
71
|
+
# @returns HeaderAndContentResponse
|
72
|
+
def receive_request(header, content)
|
73
|
+
hash_header = headers_2_hash(header)
|
74
|
+
hash_content = headers_2_hash(content)
|
75
|
+
session_header_and_content = HeaderAndContentResponse.new({:headers => hash_header, :content => hash_content})
|
76
|
+
# If we're a new session, call session initiate
|
77
|
+
if @session.nil?
|
78
|
+
@session = session_header_and_content
|
79
|
+
@step = 0
|
80
|
+
session_initiated
|
81
|
+
elsif session_header_and_content.content[:event_name] # If content includes an event_name, it must be a response from an api command
|
82
|
+
if session_header_and_content.content[:event_name].to_s.match(/CHANNEL_DATA/i) # Anytime we see CHANNEL_DATA event, we want to update our @session
|
83
|
+
session_header_and_content = HeaderAndContentResponse.new({:headers => hash_header.merge(hash_content.strip_value_newlines), :content => {}})
|
84
|
+
@session = session_header_and_content
|
85
|
+
@step += 1
|
86
|
+
receive_reply(hash_header)
|
87
|
+
end
|
88
|
+
else
|
89
|
+
@step += 1
|
90
|
+
receive_reply(session_header_and_content)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
72
94
|
end
|
95
|
+
end
|
96
|
+
end
|
73
97
|
|
98
|
+
class Hash
|
99
|
+
def strip_value_newlines
|
100
|
+
Hash[self.map { |k,v| v.respond_to?(:to_s) ? [k, v.to_s.strip] : [k, v] }]
|
74
101
|
end
|
75
102
|
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.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jayson Vaughn
|
@@ -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
|
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"
|
29
29
|
email: FreeSWITCHeR@rubyists.com
|
30
30
|
executables: []
|
31
31
|
|
@@ -147,8 +147,8 @@ post_install_message: |
|
|
147
147
|
|
148
148
|
class OesDemo < FSR::Listener::Outbound
|
149
149
|
|
150
|
-
def session_initiated
|
151
|
-
number = session.headers[:caller_caller_id_number] # Grab the inbound caller id
|
150
|
+
def session_initiated
|
151
|
+
number = @session.headers[:caller_caller_id_number] # Grab the inbound caller id
|
152
152
|
FSR::Log.info "*** Answering incoming call from #{number}"
|
153
153
|
answer # Answer the call
|
154
154
|
set("hangup_after_bridge", "true")# Set a variable
|
@@ -174,16 +174,14 @@ post_install_message: |
|
|
174
174
|
|
175
175
|
class DtmfDemo < FSR::Listener::Outbound
|
176
176
|
|
177
|
-
def session_initiated
|
178
|
-
|
179
|
-
exten = session.headers[:channel_caller_id_number]
|
177
|
+
def session_initiated
|
178
|
+
exten = @session.headers[:caller_caller_id_number]
|
180
179
|
FSR::Log.info "*** Answering incoming call from #{exten}"
|
181
180
|
answer # Answer the call
|
182
181
|
end
|
183
182
|
|
184
183
|
def receive_reply(reply)
|
185
|
-
exten = @session.headers[:
|
186
|
-
@step += 1
|
184
|
+
exten = @session.headers[:caller_caller_id_number]
|
187
185
|
case @step
|
188
186
|
when 1
|
189
187
|
FSR::Log.info "*** Reading dtmf for #{exten}"
|
@@ -192,7 +190,7 @@ post_install_message: |
|
|
192
190
|
FSR::Log.info "*** updating session for #{exten}"
|
193
191
|
update_session
|
194
192
|
when 3
|
195
|
-
FSR::Log.info "** Success, grabbed #{
|
193
|
+
FSR::Log.info "** Success, grabbed #{@session.headers[:variable_test].strip} from #{exten}"
|
196
194
|
FSR::Log.info "*** Hanging up call"
|
197
195
|
hangup # Hangup the call
|
198
196
|
end
|