Sha256: 19220b340fcb8ad18c65e3e6772e42522e86552f9bc3b47b84057f188174e6f0

Contents?: true

Size: 1020 Bytes

Versions: 14

Compression:

Stored size: 1020 Bytes

Contents

module Adhearsion
  module VoIP
    module FreeSwitch

      class BasicConnectionManager

        def initialize(io)
          @io = io
        end

        # The send-command operator
        def <<(str)
          @io.write str + "\n\n"
        end

        def get_header
          separate_pairs get_raw_header
        end

        def get_raw_header
          ([].tap do |lines|
            until line = @io.gets and line.chomp.empty?
              lines << line.chomp
            end
          end) * "\n"
        end

        def next_event
          header = get_raw_header
          length = header.first[/\d+$/].to_i
          # puts "Reading an event of #{length} bytes"
          separate_pairs @io.read(length)
        end

        def separate_pairs(lines)
          lines.split("\n").inject({}) do |h,line|
            h.tap do |hash|
              k,v = line.split(/\s*:\s*/)
              hash[k] = URI.unescape(v).strip if k && v
            end
          end
        end

      end

    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
adhearsion-1.2.6 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.2.5 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.2.4 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.2.3 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.2.1 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.2.0 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.1.1 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.1.0 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.0.3 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.0.2 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-cw-1.0.2.3 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-cw-1.0.2.2 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-cw-1.0.2.1 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
adhearsion-1.0.1 lib/adhearsion/voip/freeswitch/basic_connection_manager.rb