lib/larynx.rb in larynx-0.1.2 vs lib/larynx.rb in larynx-0.1.3

- old
+ new

@@ -6,10 +6,11 @@ require 'larynx/version' require 'larynx/logger' require 'larynx/observable' require 'larynx/callbacks' +require 'larynx/callbacks_with_async' require 'larynx/session' require 'larynx/response' require 'larynx/command' require 'larynx/commands' require 'larynx/prompt' @@ -27,17 +28,17 @@ def parse_options(args=ARGV) @options = { :ip => "0.0.0.0", :port => 8084, - :pid_file => './larynx.pid', - :log_file => './larynx.log' + :pid_file => "./larynx.pid", + :log_file => "./larynx.log" } opts = OptionParser.new opts.banner = "Usage: larynx [options]" opts.separator '' - opts.separator "Larynx is a tool to develop FreeSWITCH IVR applications in Ruby." + opts.separator "Larynx is a framework to develop FreeSWITCH IVR applications in Ruby." opts.on('-i', '--ip IP', 'Listen for connections on this IP') {|ip| @options[:ip] = ip } opts.on('-p', '--port PORT', 'Listen on this port', Integer) {|port| @options[:port] = port } opts.on('-d', '--daemonize', 'Run as daemon') { @options[:daemonize] = true } opts.on('-l', '--log-file FILE', 'Defaults to /app/root/larynx.log') {|log| @options[:log_file] = log } opts.on( '--pid-file FILE', 'Defaults to /app/root/larynx.pid') {|pid| @options[:pid_file] = pid } @@ -51,11 +52,14 @@ logger.level = Logger::INFO Object.const_set "LARYNX_LOGGER", logger end def graceful_exit - LARYNX_LOGGER.info "Shutting down Larynx" + msg = "Shutting down Larynx" + $stderr.puts msg unless @options[:daemon] + LARYNX_LOGGER.info msg + EM.stop_server @em_signature @em_signature = nil remove_pid_file if @options[:daemonize] exit 130 end @@ -83,11 +87,14 @@ Object.const_set "LARYNX_ROOT", File.expand_path(File.dirname(ARGV[0])) require File.expand_path(ARGV[0]) end def start_server - LARYNX_LOGGER.info "Larynx starting up on #{@options[:ip]}:#{@options[:port]}" + msg = "Larynx starting up on #{@options[:ip]}:#{@options[:port]}" + $stderr.puts msg unless @options[:daemon] + LARYNX_LOGGER.info msg + EM::run { @em_signature = EM::start_server @options[:ip], @options[:port], Larynx::CallHandler } end @@ -102,8 +109,11 @@ def running? !@em_signature.nil? end end + + # Default connect callback is to answer call + connect {|call| call.answer } end Larynx.run unless defined?(TEST)