adhearsion-asterisk 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,8 @@
1
1
  # develop
2
2
 
3
+ # v1.3.0
4
+ * Feature: Added explicit silence generation
5
+
3
6
  # v1.2.1
4
7
  * Feature: added play_tone for DTMF in-call generation
5
8
  * Bugfix: "code is an undefined method" errors on executing AMI methods directly (issue #6)
@@ -391,6 +391,53 @@ module Adhearsion
391
391
  execute "Playback", argument
392
392
  get_variable('PLAYBACKSTATUS') == PLAYBACK_SUCCESS
393
393
  end
394
+
395
+ #
396
+ # Generates silence in the background, just once until some other sound is generated, or
397
+ # continuously for the duration of a given block. Silence is normally only generated under
398
+ # specific circumstances but this method will explicitly generate it, which can be useful
399
+ # in some scenarios.
400
+ #
401
+ # Note that the Playtones command must be available and the transmit_silence option must be
402
+ # enabled in asterisk.conf. Also note that the given block is executed using instance_eval
403
+ # and that imposes one important restriction. If the silence is interrupted outside the scope
404
+ # of the block (e.g. calling play in another method) then it won't be restarted until
405
+ # execution returns to the scope. However, it is safe to call generate_silence again when
406
+ # outside the scope. Instance variables may be used as they are copied and copied back but be
407
+ # careful handling immutable objects outside the scope. If you're unsure, don't use a block.
408
+ #
409
+ def generate_silence(&block)
410
+ component = Punchblock::Component::Asterisk::AGI::Command.new :name => "EXEC Playtones", :params => ["0"]
411
+ execute_component_and_await_completion component
412
+ GenerateSilenceProxy.proxy_for(self, &block) if block_given?
413
+ end
414
+
415
+ class GenerateSilenceProxy
416
+ def self.proxy_for(target, &block)
417
+ proxy = new(target)
418
+ ivs = target.instance_variables
419
+ ivs.each { |iv| proxy.instance_variable_set iv, target.instance_variable_get(iv) }
420
+
421
+ proxy.instance_eval(&block).tap do
422
+ ivs = proxy.instance_variables - [:@_target]
423
+ ivs.each { |iv| target.instance_variable_set iv, proxy.instance_variable_get(iv) }
424
+ end
425
+ end
426
+
427
+ def initialize(target)
428
+ @_target = target
429
+ end
430
+
431
+ def method_missing(*args)
432
+ @_target.send(*args).tap do
433
+ @_target.generate_silence
434
+ end
435
+ end
436
+
437
+ def respond_to_missing?(*args)
438
+ @_target.respond_to?(*args)
439
+ end
440
+ end
394
441
  end
395
442
  end
396
443
  end
@@ -1,5 +1,5 @@
1
1
  module Adhearsion
2
2
  module Asterisk
3
- VERSION = "1.2.1"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -493,6 +493,55 @@ module Adhearsion::Asterisk
493
493
  subject.play_soundfile(audiofile).should == false
494
494
  end
495
495
  end
496
+
497
+ describe '#generate_silence' do
498
+ context 'executes Playtones with 0 as an argument if it' do
499
+ before do
500
+ command = Punchblock::Component::Asterisk::AGI::Command.new :name => "EXEC Playtones", :params => ["0"]
501
+ @expect_command = subject.expects(:execute_component_and_await_completion).with(command)
502
+ end
503
+
504
+ it 'is not given a block' do
505
+ @expect_command.once
506
+ subject.generate_silence
507
+ end
508
+
509
+ it 'is given a block, which it then yields' do
510
+ @expect_command.times(3)
511
+ expect { |b| subject.generate_silence { b.to_proc.call; run; run } }.to yield_with_no_args
512
+ end
513
+
514
+ it 'is given a block, and copies any instance variables' do
515
+ @expect_command.once
516
+
517
+ iv = nil
518
+ subject.instance_variable_set(:@foo, "bar")
519
+
520
+ subject.generate_silence do
521
+ iv = @foo.dup
522
+ @foo << "baz"
523
+ end
524
+
525
+ iv.should eq("bar")
526
+ subject.instance_variable_get(:@foo).should eq("barbaz")
527
+ end
528
+
529
+ it 'is given a block, which proxies calls to #respond_to? via #respond_to_missing?' do
530
+ @expect_command.once
531
+
532
+ run_result = nil
533
+ foobar_result = nil
534
+
535
+ subject.generate_silence do
536
+ run_result = respond_to? :run
537
+ foobar_result = respond_to? :foobar
538
+ end
539
+
540
+ run_result.should be_true
541
+ foobar_result.should be_false
542
+ end
543
+ end
544
+ end
496
545
  end
497
546
  end#main describe
498
547
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adhearsion-asterisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-06-22 00:00:00.000000000 Z
14
+ date: 2012-10-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: adhearsion
@@ -298,7 +298,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
298
  version: '0'
299
299
  segments:
300
300
  - 0
301
- hash: -489585779242727687
301
+ hash: -2314850667478609314
302
302
  required_rubygems_version: !ruby/object:Gem::Requirement
303
303
  none: false
304
304
  requirements:
@@ -307,10 +307,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
307
  version: '0'
308
308
  segments:
309
309
  - 0
310
- hash: -489585779242727687
310
+ hash: -2314850667478609314
311
311
  requirements: []
312
312
  rubyforge_project: adhearsion-asterisk
313
- rubygems_version: 1.8.21
313
+ rubygems_version: 1.8.23
314
314
  signing_key:
315
315
  specification_version: 3
316
316
  summary: Asterisk specific features for Adhearsion
@@ -328,4 +328,3 @@ test_files:
328
328
  - spec/has_agi_context.rb
329
329
  - spec/spec_helper.rb
330
330
  - spec/support/the_following_code.rb
331
- has_rdoc: