Sha256: a3ad73b473b46d588c3f9ebc17a777dd109f8724f062e38629527d2c75a1bda6

Contents?: true

Size: 1.26 KB

Versions: 23

Compression:

Stored size: 1.26 KB

Contents

# encoding: utf-8

require 'ruby_fs'

module Punchblock
  module Connection
    class Freeswitch < GenericConnection
      attr_reader :translator, :stream
      attr_accessor :event_handler

      def initialize(options = {})
        @translator = Translator::Freeswitch.new self
        @stream_options = options.values_at(:host, :port, :password)
        @stream = new_fs_stream
        super()
      end

      def run
        pb_logger.debug "Starting the RubyFS stream"
        start_stream
        raise DisconnectedError
      end

      def stop
        stream.shutdown
        translator.terminate
      end

      def write(command, options)
        translator.async.execute_command command, options
      end

      def handle_event(event)
        event_handler.call event if event_handler.respond_to?(:call)
      end

      private

      def new_fs_stream
        RubyFS::Stream.new(*@stream_options, lambda { |e| translator.async.handle_es_event e }, event_mask)
      end

      def event_mask
        %w{CHANNEL_PARK CHANNEL_ANSWER CHANNEL_STATE CHANNEL_HANGUP CHANNEL_BRIDGE CHANNEL_UNBRIDGE CHANNEL_EXECUTE_COMPLETE DTMF RECORD_STOP}
      end

      def start_stream
        @stream = new_fs_stream unless @stream.alive?
        @stream.run
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
punchblock-2.7.5 lib/punchblock/connection/freeswitch.rb
punchblock-2.7.3 lib/punchblock/connection/freeswitch.rb
punchblock-2.7.2 lib/punchblock/connection/freeswitch.rb
punchblock-2.7.1 lib/punchblock/connection/freeswitch.rb
punchblock-2.7.0 lib/punchblock/connection/freeswitch.rb
punchblock-2.6.0 lib/punchblock/connection/freeswitch.rb
punchblock-2.5.3 lib/punchblock/connection/freeswitch.rb
punchblock-2.5.2 lib/punchblock/connection/freeswitch.rb
punchblock-2.5.1 lib/punchblock/connection/freeswitch.rb
punchblock-2.5.0 lib/punchblock/connection/freeswitch.rb
punchblock-2.4.2 lib/punchblock/connection/freeswitch.rb
punchblock-2.4.0 lib/punchblock/connection/freeswitch.rb
punchblock-2.3.1 lib/punchblock/connection/freeswitch.rb
punchblock-2.3.0 lib/punchblock/connection/freeswitch.rb
punchblock-2.2.2 lib/punchblock/connection/freeswitch.rb
punchblock-2.2.1 lib/punchblock/connection/freeswitch.rb
punchblock-2.2.0 lib/punchblock/connection/freeswitch.rb
punchblock-2.1.1 lib/punchblock/connection/freeswitch.rb
punchblock-2.1.0 lib/punchblock/connection/freeswitch.rb
punchblock-2.0.2 lib/punchblock/connection/freeswitch.rb