freeswitcher 0.4.10 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +69 -13
- data/Rakefile +1 -1
- data/examples/play_and_get_digits.rb +34 -0
- data/lib/fsr.rb +4 -1
- data/lib/fsr/app/play_and_get_digits.rb +8 -0
- data/lib/fsr/app/playback.rb +8 -2
- data/lib/fsr/cmd/call_center.rb +156 -0
- data/lib/fsr/cmd/calls.rb +4 -4
- data/lib/fsr/cmd/channels.rb +47 -0
- data/lib/fsr/cmd/enum.rb +40 -0
- data/lib/fsr/cmd/sofia_contact.rb +2 -1
- data/lib/fsr/file_methods.rb +14 -0
- data/lib/fsr/listener/inbound.rb +27 -3
- data/lib/fsr/model.rb +11 -0
- data/lib/fsr/model/agent.rb +18 -0
- data/lib/fsr/model/call.rb +6 -41
- data/lib/fsr/model/channel.rb +13 -0
- data/lib/fsr/model/enum.rb +26 -0
- data/lib/fsr/model/queue.rb +15 -0
- data/lib/fsr/model/tier.rb +15 -0
- data/lib/rack/middleware.rb +83 -0
- data/spec/fsr/app.rb +2 -0
- data/spec/fsr/app/play_and_get_digits.rb +15 -0
- data/spec/fsr/app/playback.rb +15 -0
- data/spec/fsr/cmd/call_center.rb +58 -0
- data/spec/fsr/cmd/calls.rb +2 -2
- data/spec/fsr/cmd/channels.rb +18 -0
- data/spec/fsr/cmd/enum.rb +19 -0
- data/spec/fsr/file_methods.rb +36 -0
- data/spec/fsr/listener/inbound.rb +6 -6
- data/spec/fsr/loading.rb +1 -1
- metadata +139 -24
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
require "fsr/cmd"
|
3
|
+
FSR::Cmd.load_command("channels")
|
4
|
+
|
5
|
+
describe "Testing FSR::Cmd::Channels" do
|
6
|
+
## Channels ##
|
7
|
+
# Interface to channels
|
8
|
+
it "FSR::Cmd::Channels should send show channels" do
|
9
|
+
sofia = FSR::Cmd::Channels.new(nil, false)
|
10
|
+
sofia.raw.should == "show channels"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "FSR::Cmd::Channels should send show channels" do
|
14
|
+
sofia = FSR::Cmd::Channels.new(nil, true)
|
15
|
+
sofia.raw.should == "show distinct_channels"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
require "fsr/cmd"
|
3
|
+
FSR::Cmd.load_command("enum")
|
4
|
+
|
5
|
+
describe "Testing FSR::Cmd::Enum" do
|
6
|
+
## Enum ##
|
7
|
+
# Interface to enum
|
8
|
+
it "FSR::Cmd::Enum should send enum <did>" do
|
9
|
+
cmd = FSR::Cmd::Enum.new(nil, "13012221111")
|
10
|
+
cmd.raw.should == "enum 13012221111"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "FSR::Cmd::Enum should return nil if response is 'No Match!'" do
|
14
|
+
cmd = FSR::Cmd::Enum.new(nil, "13012221111")
|
15
|
+
response={"Content-Type"=>"api/response", "Content-Length"=>"366", "body"=>"Offered Routes:\nOrder\tPref\tService \tRoute\n==============================================================================\n5\t10\tE2U+h323 \topal/h323:+13012221111@128.121.41.89:1720\n\nSupported Routes:\nOrder\tPref\tService \tRoute\n==============================================================================\n5\t10\tE2U+h323 \topal/h323:+13012221111@128.121.41.89:1720"}
|
16
|
+
cmd.parse(response).route == "opal/h323:+13012221111@128.121.41.89:1720"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec/helper"
|
2
|
+
require "fsr/file_methods"
|
3
|
+
|
4
|
+
describe "Basic FSR::App::FileMethods module" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@testee = Class.new do
|
8
|
+
include ::FSR::App::FileMethods
|
9
|
+
end.new
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a test_files method" do
|
14
|
+
@testee.test_files("bla").should.equal true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should only test files with an absolute path" do
|
18
|
+
lambda { @testee.test_files("/path/file") }.
|
19
|
+
should.raise(Errno::ENOENT)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should handle multiple files" do
|
23
|
+
@testee.test_files("bla.wav", "fasel.wav").should.equal true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should handle mixed absolute and relative files" do
|
27
|
+
lambda { @testee.test_files("some_file.wav", "/path/file") }.
|
28
|
+
should.raise(Errno::ENOENT)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not raise if file is present" do
|
32
|
+
file_name = File.expand_path(__FILE__)
|
33
|
+
lambda { @testee.test_files(file_name) }.
|
34
|
+
should.not.raise
|
35
|
+
end
|
36
|
+
end
|
@@ -67,24 +67,24 @@ EM.describe InboundListener do
|
|
67
67
|
end
|
68
68
|
|
69
69
|
should "be able to receive an event and call the on_event callback method" do
|
70
|
-
@listener.receive_data("Content-Length: 22\n\nEvent-Name: test_event\n\n")
|
70
|
+
@listener.receive_data("Content-Length: 22\nContent-Type: text/event-plain\n\nEvent-Name: test_event\n\n")
|
71
71
|
@listener.recvd_event.first.content[:event_name].should.equal "test_event"
|
72
72
|
done
|
73
73
|
end
|
74
74
|
|
75
75
|
should "be able to add custom event hooks on instances in the pre_session (before_session)" do
|
76
|
-
@listener.receive_data("Content-Length: 18\n\nEvent-Name: CUSTOM\n\n")
|
76
|
+
@listener.receive_data("Content-Length: 18\nContent-Type: text/event-plain\n\nEvent-Name: CUSTOM\n\n")
|
77
77
|
@listener.custom_event.should.not.be.nil
|
78
78
|
@listener.custom_event.content[:event_name].should == "CUSTOM"
|
79
79
|
@listener.custom_event.should.equal @listener.recvd_event.first
|
80
|
-
@listener2.receive_data("Content-Length: 22\n\nEvent-Name: TEST_EVENT\n\n")
|
80
|
+
@listener2.receive_data("Content-Length: 22\nContent-Type: text/event-plain\n\nEvent-Name: TEST_EVENT\n\n")
|
81
81
|
@listener2.test_event.content[:event_name].should.equal "TEST_EVENT"
|
82
82
|
done
|
83
83
|
end
|
84
84
|
|
85
85
|
should "be able to add custom event hooks with sub events" do
|
86
86
|
listener = InboundListener3.new(1234, {:auth => 'SecretPassword'})
|
87
|
-
@listener.receive_data("Content-Length: 22\n\nEvent-Name: CUSTOM\n\n")
|
87
|
+
@listener.receive_data("Content-Length: 22\nContent-Type: text/event-plain\n\nEvent-Name: CUSTOM\n\n")
|
88
88
|
@listener.custom_event.should.equal @listener.recvd_event.first
|
89
89
|
done
|
90
90
|
end
|
@@ -92,7 +92,7 @@ EM.describe InboundListener do
|
|
92
92
|
should "be able to add custom event hooks on classes, before instantiation" do
|
93
93
|
FSL::Inbound.add_event_hook(:HANGUP_EVENT) { |instance, event| instance.test_event = event }
|
94
94
|
listener = InboundListener2.new(1234, {:auth => 'SecretPassword'})
|
95
|
-
listener.receive_data("Content-Length: 24\n\nEvent-Name: HANGUP_EVENT\n\n")
|
95
|
+
listener.receive_data("Content-Length: 24\nContent-Type: text/event-plain\n\nEvent-Name: HANGUP_EVENT\n\n")
|
96
96
|
listener.test_event.content[:event_name].should.equal "HANGUP_EVENT"
|
97
97
|
done
|
98
98
|
end
|
@@ -100,7 +100,7 @@ EM.describe InboundListener do
|
|
100
100
|
should "be able to add custom event hooks on classes, after instantiation" do
|
101
101
|
listener = InboundListener2.new(1234, {:auth => 'SecretPassword'})
|
102
102
|
FSL::Inbound.add_event_hook(:HANGUP_EVENT) { |instance, event| instance.test_event = event }
|
103
|
-
listener.receive_data("Content-Length: 24\n\nEvent-Name: HANGUP_EVENT\n\n")
|
103
|
+
listener.receive_data("Content-Length: 24\nContent-Type: text/event-plain\n\nEvent-Name: HANGUP_EVENT\n\n")
|
104
104
|
listener.test_event.content[:event_name].should.equal "HANGUP_EVENT"
|
105
105
|
done
|
106
106
|
end
|
data/spec/fsr/loading.rb
CHANGED
@@ -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 = [:uuid_dump, :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, :call_center, :channels, :enum] # 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|
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freeswitcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jayson Vaughn
|
@@ -12,20 +17,23 @@ autorequire:
|
|
12
17
|
bindir: bin
|
13
18
|
cert_chain: []
|
14
19
|
|
15
|
-
date: 2010-
|
20
|
+
date: 2010-11-20 00:00:00 -06:00
|
16
21
|
default_executable:
|
17
22
|
dependencies:
|
18
23
|
- !ruby/object:Gem::Dependency
|
19
24
|
name: eventmachine
|
20
|
-
|
21
|
-
|
22
|
-
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
23
28
|
requirements:
|
24
29
|
- - ">="
|
25
30
|
- !ruby/object:Gem::Version
|
31
|
+
segments:
|
32
|
+
- 0
|
26
33
|
version: "0"
|
27
|
-
|
28
|
-
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: &id002 |
|
29
37
|
=========================================================
|
30
38
|
FreeSWITCHeR
|
31
39
|
Copyright (c) 2009 The Rubyists (Jayson Vaughn, Tj Vanderpoel, Michael Fellinger, Kevin Berry)
|
@@ -84,27 +92,83 @@ description: &id001 |
|
|
84
92
|
--------------------------------------------------------------------------
|
85
93
|
|
86
94
|
#!/usr/bin/ruby
|
87
|
-
require 'pp'
|
88
95
|
require 'fsr'
|
89
96
|
require "fsr/listener/inbound"
|
90
97
|
|
91
|
-
|
92
|
-
|
93
|
-
|
98
|
+
class MyEventListener < FSR::Listener::Inbound
|
99
|
+
def before_session
|
100
|
+
# 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
|
101
|
+
add_event(:CHANNEL_CREATE) { |e| p e }
|
94
102
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
103
|
+
# This adds a hook on CHANNEL_HANGUP events with a callback method.
|
104
|
+
add_event(:CHANNEL_HANGUP) { |e| channel_hangup(e) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def channel_hangup(event)
|
108
|
+
p event
|
109
|
+
end
|
101
110
|
|
102
|
-
|
103
|
-
|
111
|
+
def on_event(event)
|
112
|
+
# This gets called for _every_ event that's subscribed (through add_event)
|
113
|
+
p event
|
114
|
+
end
|
115
|
+
end
|
104
116
|
|
105
117
|
|
106
118
|
# Start FSR Inbound Listener
|
107
|
-
FSR.start_ies!(
|
119
|
+
FSR.start_ies!(MyEventListener, :host => "localhost", :port => 8021)
|
120
|
+
|
121
|
+
A More Advanced Example, Publishing Events To A Web Socket:
|
122
|
+
-----------------------------------------------------------
|
123
|
+
|
124
|
+
class MyWebSocketClient < Struct.new(:reporter, :socket, :channel_id)
|
125
|
+
Channel = EM::Channel.new
|
126
|
+
|
127
|
+
def initialize(reporter, socket)
|
128
|
+
self.reporter, self.socket = reporter, socket
|
129
|
+
socket.onopen(&method(:on_open))
|
130
|
+
socket.onmessage(&method(:on_message))
|
131
|
+
socket.onclose(&method(:on_close))
|
132
|
+
end
|
133
|
+
|
134
|
+
def on_message(json)
|
135
|
+
msg = JSON.parse(json)
|
136
|
+
FSR::Log.info "Websocket got #{msg}"
|
137
|
+
end
|
138
|
+
|
139
|
+
def send(msg)
|
140
|
+
socket.send(msg.to_json)
|
141
|
+
end
|
142
|
+
|
143
|
+
def on_open
|
144
|
+
FSR::Log.info("Subscribed listener")
|
145
|
+
self.channel_id = Channel.subscribe { |message| send(message) }
|
146
|
+
end
|
147
|
+
|
148
|
+
def on_close
|
149
|
+
Channel.unsubscribe(channel_id)
|
150
|
+
FSR::Log.info("Unsubscribed listener")
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Add the Channel to your event listener
|
155
|
+
class MyEventListener
|
156
|
+
def on_event(event)
|
157
|
+
MyWebSocketClient::Channel << event.content
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
# Start Listener within and EM.run
|
162
|
+
EM.epoll
|
163
|
+
EM.run do
|
164
|
+
server, port = '127.0.0.1', 8021
|
165
|
+
EventMachine.connect(server, port, MyEventListener, auth: 'MyPassword') do |listener|
|
166
|
+
FSR::Log.info "MyEventListener connected to #{server} on #{port}"
|
167
|
+
EventMachine.start_server('0.0.0.0'), 8080, EventSocket::WebSocket::Connection, {}) do |websocket|
|
168
|
+
MyWebSocketClient.new(reporter, websocket)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
108
172
|
|
109
173
|
|
110
174
|
An Inbound Event Socket Listener example using the on_event callback method instead of hooks:
|
@@ -169,6 +233,7 @@ files:
|
|
169
233
|
- examples/inbound_event_socket.rb
|
170
234
|
- examples/inbound_socket_events.rb
|
171
235
|
- examples/outbound_event_socket.rb
|
236
|
+
- examples/play_and_get_digits.rb
|
172
237
|
- freeswitcher.gemspec
|
173
238
|
- lib/fsr.rb
|
174
239
|
- lib/fsr/app.rb
|
@@ -193,7 +258,10 @@ files:
|
|
193
258
|
- lib/fsr/app/uuid_getvar.rb
|
194
259
|
- lib/fsr/app/uuid_setvar.rb
|
195
260
|
- lib/fsr/cmd.rb
|
261
|
+
- lib/fsr/cmd/call_center.rb
|
196
262
|
- lib/fsr/cmd/calls.rb
|
263
|
+
- lib/fsr/cmd/channels.rb
|
264
|
+
- lib/fsr/cmd/enum.rb
|
197
265
|
- lib/fsr/cmd/fsctl.rb
|
198
266
|
- lib/fsr/cmd/originate.rb
|
199
267
|
- lib/fsr/cmd/sofia.rb
|
@@ -211,14 +279,22 @@ files:
|
|
211
279
|
- lib/fsr/database/voicemail_default.rb
|
212
280
|
- lib/fsr/event_socket.rb
|
213
281
|
- lib/fsr/fake_socket.rb
|
282
|
+
- lib/fsr/file_methods.rb
|
214
283
|
- lib/fsr/listener.rb
|
215
284
|
- lib/fsr/listener/header_and_content_response.rb
|
216
285
|
- lib/fsr/listener/inbound.rb
|
217
286
|
- lib/fsr/listener/inbound/event.rb
|
218
287
|
- lib/fsr/listener/mock.rb
|
219
288
|
- lib/fsr/listener/outbound.rb
|
289
|
+
- lib/fsr/model.rb
|
290
|
+
- lib/fsr/model/agent.rb
|
220
291
|
- lib/fsr/model/call.rb
|
292
|
+
- lib/fsr/model/channel.rb
|
293
|
+
- lib/fsr/model/enum.rb
|
294
|
+
- lib/fsr/model/queue.rb
|
295
|
+
- lib/fsr/model/tier.rb
|
221
296
|
- lib/fsr/version.rb
|
297
|
+
- lib/rack/middleware.rb
|
222
298
|
- tasks/authors.rake
|
223
299
|
- tasks/bacon.rake
|
224
300
|
- tasks/changelog.rake
|
@@ -233,31 +309,66 @@ files:
|
|
233
309
|
- tasks/yard.rake
|
234
310
|
- spec/helper.rb
|
235
311
|
- spec/fsr_listener_helper.rb
|
312
|
+
- spec/fsr/app.rb
|
313
|
+
- spec/fsr/app/answer.rb
|
314
|
+
- spec/fsr/app/bind_meta_app.rb
|
315
|
+
- spec/fsr/app/bridge.rb
|
316
|
+
- spec/fsr/app/conference.rb
|
317
|
+
- spec/fsr/app/execute_app.rb
|
318
|
+
- spec/fsr/app/fifo.rb
|
319
|
+
- spec/fsr/app/fs_break.rb
|
320
|
+
- spec/fsr/app/fs_sleep.rb
|
321
|
+
- spec/fsr/app/hangup.rb
|
322
|
+
- spec/fsr/app/limit.rb
|
323
|
+
- spec/fsr/app/log.rb
|
324
|
+
- spec/fsr/app/play_and_get_digits.rb
|
325
|
+
- spec/fsr/app/playback.rb
|
326
|
+
- spec/fsr/app/set.rb
|
327
|
+
- spec/fsr/app/transfer.rb
|
328
|
+
- spec/fsr/cmd.rb
|
329
|
+
- spec/fsr/cmd/call_center.rb
|
330
|
+
- spec/fsr/cmd/calls.rb
|
331
|
+
- spec/fsr/cmd/channels.rb
|
332
|
+
- spec/fsr/cmd/enum.rb
|
333
|
+
- spec/fsr/cmd/originate.rb
|
334
|
+
- spec/fsr/cmd/sofia.rb
|
335
|
+
- spec/fsr/cmd/sofia/profile.rb
|
336
|
+
- spec/fsr/cmd/uuid_dump.rb
|
337
|
+
- spec/fsr/file_methods.rb
|
338
|
+
- spec/fsr/listener.rb
|
339
|
+
- spec/fsr/listener/header_and_content_response.rb
|
340
|
+
- spec/fsr/listener/inbound.rb
|
341
|
+
- spec/fsr/listener/outbound.rb
|
342
|
+
- spec/fsr/loading.rb
|
236
343
|
has_rdoc: true
|
237
344
|
homepage: http://code.rubyists.com/projects/fs
|
238
345
|
licenses: []
|
239
346
|
|
240
|
-
post_install_message: *
|
347
|
+
post_install_message: *id002
|
241
348
|
rdoc_options: []
|
242
349
|
|
243
350
|
require_paths:
|
244
351
|
- lib
|
245
352
|
required_ruby_version: !ruby/object:Gem::Requirement
|
353
|
+
none: false
|
246
354
|
requirements:
|
247
355
|
- - ">="
|
248
356
|
- !ruby/object:Gem::Version
|
357
|
+
segments:
|
358
|
+
- 0
|
249
359
|
version: "0"
|
250
|
-
version:
|
251
360
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
361
|
+
none: false
|
252
362
|
requirements:
|
253
363
|
- - ">="
|
254
364
|
- !ruby/object:Gem::Version
|
365
|
+
segments:
|
366
|
+
- 0
|
255
367
|
version: "0"
|
256
|
-
version:
|
257
368
|
requirements: []
|
258
369
|
|
259
370
|
rubyforge_project: freeswitcher
|
260
|
-
rubygems_version: 1.3.
|
371
|
+
rubygems_version: 1.3.7
|
261
372
|
signing_key:
|
262
373
|
specification_version: 3
|
263
374
|
summary: A library for interacting with the "FreeSWITCH":http://freeswitch.org telephony platform
|
@@ -279,11 +390,15 @@ test_files:
|
|
279
390
|
- spec/fsr/app/set.rb
|
280
391
|
- spec/fsr/app/transfer.rb
|
281
392
|
- spec/fsr/cmd.rb
|
393
|
+
- spec/fsr/cmd/call_center.rb
|
282
394
|
- spec/fsr/cmd/calls.rb
|
395
|
+
- spec/fsr/cmd/channels.rb
|
396
|
+
- spec/fsr/cmd/enum.rb
|
283
397
|
- spec/fsr/cmd/originate.rb
|
284
398
|
- spec/fsr/cmd/sofia.rb
|
285
399
|
- spec/fsr/cmd/sofia/profile.rb
|
286
400
|
- spec/fsr/cmd/uuid_dump.rb
|
401
|
+
- spec/fsr/file_methods.rb
|
287
402
|
- spec/fsr/listener.rb
|
288
403
|
- spec/fsr/listener/header_and_content_response.rb
|
289
404
|
- spec/fsr/listener/inbound.rb
|