Class: RSpecRayo::RayoDriver
- Inherits:
-
Object
- Object
- RSpecRayo::RayoDriver
- Defined in:
- lib/rspec-rayo/rayo/driver.rb
Instance Attribute Summary collapse
-
#call_queue ⇒ Object
readonly
Returns the value of attribute call_queue.
-
#calls ⇒ Object
Returns the value of attribute calls.
-
#event_queue ⇒ Object
readonly
Returns the value of attribute event_queue.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Instance Method Summary collapse
- #cleanup_calls ⇒ Object
- #dial(options) ⇒ Object
- #get_call ⇒ Object
-
#initialize(options) ⇒ RayoDriver
constructor
A new instance of RayoDriver.
- #initialize_logging(options) ⇒ Object
- #initialize_rayo(options) ⇒ Object
- #read_queue(queue) ⇒ Object
- #start_event_dispatcher ⇒ Object
- #start_rayo ⇒ Object
Constructor Details
#initialize(options) ⇒ RayoDriver
Returns a new instance of RayoDriver.
6 7 8 9 10 11 12 13 14 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 6 def initialize() @calls = {} @call_queue = Queue.new @queue_timeout = [:queue_timeout] || 5 @write_timeout = [:write_timeout] || 5 @threads = [] initialize_rayo end |
Instance Attribute Details
#call_queue ⇒ Object (readonly)
Returns the value of attribute call_queue.
3 4 5 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 3 def call_queue @call_queue end |
#calls ⇒ Object
Returns the value of attribute calls.
4 5 6 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 4 def calls @calls end |
#event_queue ⇒ Object (readonly)
Returns the value of attribute event_queue.
3 4 5 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 3 def event_queue @event_queue end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
3 4 5 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 3 def threads @threads end |
Instance Method Details
#cleanup_calls ⇒ Object
20 21 22 23 24 25 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 20 def cleanup_calls @calls.each_pair do |call_id, call| call.hangup unless call.status == :finished end @calls = {} end |
#dial(options) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 27 def dial() Call.new(:client => @rayo, :queue => Queue.new, :read_timeout => @queue_timeout, :write_timeout => @write_timeout).tap do |call| dial = call.dial call.call_id = dial.call_id @calls.merge! call.call_id => call end end |
#get_call ⇒ Object
16 17 18 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 16 def get_call read_queue @call_queue end |
#initialize_logging(options) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 91 def initialize_logging() @wire_logger = [:wire_logger] @wire_logger.level = [:log_level] #@wire_logger.info "Starting up..." if @wire_logger @transport_logger = [:transport_logger] @transport_logger.level = [:log_level] #@transport_logger.info "Starting up..." if @transport_logger end |
#initialize_rayo(options) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 73 def initialize_rayo() initialize_logging # Setup our Rayo environment connection = Punchblock::Connection::XMPP.new :username => [:username], :password => [:password], :host => [:host], :port => [:port], :wire_logger => @wire_logger, :transport_logger => @transport_logger, :auto_reconnect => false @rayo = Punchblock::Client.new :connection => connection, :write_timeout => [:write_timeout] @event_queue = @rayo.event_queue start_rayo end |
#read_queue(queue) ⇒ Object
69 70 71 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 69 def read_queue(queue) Timeout::timeout(@queue_timeout) { queue.pop } end |
#start_event_dispatcher ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 35 def start_event_dispatcher @threads << Thread.new do event = nil until event == 'STOP' do event = @event_queue.pop case event when Punchblock::Event::Offer call = Call.new :call_event => event, :client => @rayo, :queue => Queue.new, :read_timeout => @queue_timeout, :write_timeout => @write_timeout @calls.merge! event.call_id => call @call_queue.push call when Punchblock::Event::Ringing call = @calls[event.call_id] call.ring_event = event if call else # Temp based on this nil returned on conference: https://github.com/tropo/punchblock/issues/27 begin if event.is_a?(Punchblock::Event::End) @calls[event.call_id].status = :finished end @calls[event.call_id].queue.push event unless event.nil? rescue => error # Event nil issue to be addressed here: https://github.com/tropo/rspec-rayo/issues/2 end end end end end |
#start_rayo ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rspec-rayo/rayo/driver.rb', line 101 def start_rayo # Launch the Rayo thread @threads << Thread.new do begin @rayo.run rescue => e puts "Exception in XMPP thread! #{e.}" puts e.backtrace.join("\t\n") end end end |