diff --git a/CHANGELOG.md b/CHANGELOG.md index a343ec8ca..150d7491e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,7 +48,6 @@ * Change: Permit application environment to be set only by AHN_ENV. The config system depends on the environment, and the previous dependency was circular. * Change: Define configuration per-environment for any environment name and without colliding with plugin names. See [#442](https://github.com/adhearsion/adhearsion/issues/442). Syntax is now `config.env(:development).foo = :bar` instead of `config.development.foo = :bar`. * Feature: Add i18n support via `CallController#t` - * Feature: Integrate a Rack-based HTTP server from the Virginia plugin * Feature: Permit timing out when calling `Call#wait_for_end` * Upgrade to Celluloid 0.16 * Move events system to Celluloid and do away with GirlFriday diff --git a/Gemfile b/Gemfile index 7411fcb3d..729917bd1 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,6 @@ source 'https://rubygems.org' gemspec -gem 'sinatra', require: nil - group :test do # TODO: some expectations started failing in 3.8.3 # The be_a_kind_of matcher requires that the actual object responds to either diff --git a/adhearsion.gemspec b/adhearsion.gemspec index 474a32509..cc68c6522 100644 --- a/adhearsion.gemspec +++ b/adhearsion.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'activesupport', [">= 3.0.0"] s.add_runtime_dependency 'adhearsion-loquacious', ["~> 1.9"] s.add_runtime_dependency 'blather', ["~> 2.0"] - s.add_runtime_dependency 'celluloid', ["~> 0.16.0"] + s.add_runtime_dependency 'celluloid', ["~> 0.17.4"] s.add_runtime_dependency 'countdownlatch' s.add_runtime_dependency 'deep_merge' s.add_runtime_dependency 'ffi', ["~> 1.0"] @@ -32,12 +32,9 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'has-guarded-handlers', ["~> 1.6", ">= 1.6.3"] s.add_runtime_dependency 'i18n', [">= 0.6"] s.add_runtime_dependency 'logging', ["~> 2.0", "< 2.3"] # See https://github.com/TwP/logging/issues/235 - s.add_runtime_dependency 'nokogiri', ["~> 1.8", ">= 1.8.3", "< 1.11"] # Versions > 1.10 broken under JRuby + s.add_runtime_dependency 'nokogiri', ["~> 1.8", ">= 1.8.3"] # Versions > 1.10 broken under JRuby s.add_runtime_dependency 'pry' s.add_runtime_dependency 'rake' - s.add_runtime_dependency 'reel', ["~> 0.6.0"] - s.add_runtime_dependency 'http_parser.rb', ["~> 0.6.0"] # Dependency of Reel, verions > 0.6.0 broken under JRuby - s.add_runtime_dependency 'reel-rack', ["~> 0.2.0"] s.add_runtime_dependency 'ruby_ami', ["~> 2.2"] s.add_runtime_dependency 'ruby_jid', ["~> 1.0"] s.add_runtime_dependency 'ruby_speech', ["~> 3.0"] diff --git a/features/cli_create.feature b/features/cli_create.feature index 58949f3dd..f5da646f1 100644 --- a/features/cli_create.feature +++ b/features/cli_create.feature @@ -29,7 +29,6 @@ Feature: Adhearsion Ahn CLI (Create) | config/events.rb | | config/routes.rb | | config/locales/en.yml | - | config.ru | | Gemfile | | script/ahn | | spec/spec_helper.rb | @@ -56,10 +55,6 @@ Feature: Adhearsion Ahn CLI (Create) """ Adhearsion.router """ - And the file "config.ru" should contain each of these content parts: - """ - run Sinatra::Application - """ And the file "README.md" should contain each of these content parts: """ Start your new app with @@ -97,7 +92,6 @@ Feature: Adhearsion Ahn CLI (Create) | config/environment.rb | | config/events.rb | | config/routes.rb | - | config.ru | | Gemfile | | script/ahn | | spec/spec_helper.rb | diff --git a/lib/adhearsion.rb b/lib/adhearsion.rb index 343d12429..47f481c3c 100644 --- a/lib/adhearsion.rb +++ b/lib/adhearsion.rb @@ -5,6 +5,7 @@ %w( adhearsion/rayo celluloid + celluloid/autostart active_support/inflector ).each { |r| require r } diff --git a/lib/adhearsion/call.rb b/lib/adhearsion/call.rb index 0bdb548bd..e03c499e1 100644 --- a/lib/adhearsion/call.rb +++ b/lib/adhearsion/call.rb @@ -17,7 +17,7 @@ class Call ExpiredError = Class.new Celluloid::DeadActorError # @private - class ActorProxy < Celluloid::CellProxy + class ActorProxy < Celluloid::Proxy::Cell def method_missing(meth, *args, &block) super(meth, *args, &block) rescue ::Celluloid::DeadActorError @@ -254,7 +254,7 @@ def register_initial_handlers end on_end do |event| - logger.info "Call #{from} -> #{to} ended due to #{event.reason}#{" (code #{event.platform_code})" if event.platform_code}" + logger.info "Call ended due to #{event.reason}#{" (code #{event.platform_code})" if event.platform_code}" @end_time = event.timestamp.to_time @duration = @end_time.to_i - @start_time.to_i if @start_time clear_from_active_calls diff --git a/lib/adhearsion/call_controller.rb b/lib/adhearsion/call_controller.rb index bfdabb139..dfc04fbc6 100644 --- a/lib/adhearsion/call_controller.rb +++ b/lib/adhearsion/call_controller.rb @@ -50,12 +50,12 @@ def mixin(mod) include mod end - def before_call(*args, &block) + ruby2_keywords def before_call(*args, &block) Adhearsion.deprecated :before before(*args, &block) end - def after_call(*args, &block) + ruby2_keywords def after_call(*args, &block) Adhearsion.deprecated :after after(*args, &block) end @@ -333,7 +333,7 @@ def resume! # @private def inspect - "#<#{self.class} call=#{call.alive? ? call.id : ''}, metadata=#{metadata.inspect}>" + "#<#{self.class} call=#{call.alive? ? call.id : ''}>" end def eql?(other) diff --git a/lib/adhearsion/configuration.rb b/lib/adhearsion/configuration.rb index efa097cff..df055f17c 100644 --- a/lib/adhearsion/configuration.rb +++ b/lib/adhearsion/configuration.rb @@ -108,13 +108,6 @@ def initialize(env = :development, &block) __ } - desc "HTTP server" - http do - enable true, desc: "Enable or disable the HTTP server" - host "0.0.0.0", desc: "IP to bind the HTTP listener to" - port "8080", desc: "Port to bind the HTTP listener to" - rackup 'config.ru', desc: 'Path to Rack configuration file (relative to Adhearsion application root)' - end end Loquacious::Configuration.for :core, &block if block_given? diff --git a/lib/adhearsion/generators/app/app_generator.rb b/lib/adhearsion/generators/app/app_generator.rb index e63257bca..f25bd7919 100644 --- a/lib/adhearsion/generators/app/app_generator.rb +++ b/lib/adhearsion/generators/app/app_generator.rb @@ -18,7 +18,6 @@ def setup_project template "adhearsion.erb", "config/adhearsion.rb" template "events.erb", "config/events.rb" template "routes.erb", "config/routes.rb" - copy_file "config.ru", "config.ru" copy_file "gitignore", ".gitignore" copy_file "rspec", ".rspec" copy_file "Procfile" diff --git a/lib/adhearsion/generators/app/templates/Gemfile.erb b/lib/adhearsion/generators/app/templates/Gemfile.erb index 0fbef73cd..1450fa397 100644 --- a/lib/adhearsion/generators/app/templates/Gemfile.erb +++ b/lib/adhearsion/generators/app/templates/Gemfile.erb @@ -7,8 +7,6 @@ gem 'adhearsion', '~> <%= Adhearsion::VERSION.split('.')[0,2].join('.') %>' # To use them, simply add them here and run `bundle install`. # -gem 'sinatra' - group :development, :test do gem 'rspec' end diff --git a/lib/adhearsion/generators/app/templates/config.ru b/lib/adhearsion/generators/app/templates/config.ru deleted file mode 100644 index 37ee3b6aa..000000000 --- a/lib/adhearsion/generators/app/templates/config.ru +++ /dev/null @@ -1,9 +0,0 @@ -require 'sinatra' - -set :root, Adhearsion.root - -get '/' do - 'Hello world!' -end - -run Sinatra::Application diff --git a/lib/adhearsion/generators/generator.rb b/lib/adhearsion/generators/generator.rb index b1062e7f0..4eb563453 100644 --- a/lib/adhearsion/generators/generator.rb +++ b/lib/adhearsion/generators/generator.rb @@ -55,7 +55,7 @@ def self.namespace(name = nil) def self.default_source_root return unless generator_name path = File.expand_path File.join(generator_name, 'templates'), base_root - path if File.exists?(path) + path if File.exist?(path) end # Returns the base root for a common set of generators. This is used to dynamically diff --git a/lib/adhearsion/http_server.rb b/lib/adhearsion/http_server.rb deleted file mode 100644 index 5933ab3b0..000000000 --- a/lib/adhearsion/http_server.rb +++ /dev/null @@ -1,37 +0,0 @@ -# encoding: utf-8 - -require 'reel' -require 'reel/rack' - -module Adhearsion - # @private - class HTTPServer - def self.start - config = Adhearsion.config.core.http - - return unless config.enable - - rackup = File.join(Adhearsion.root, config.rackup) - unless File.exists?(rackup) - logger.error "Cannot start HTTP server because the Rack configuration does not exist at #{rackup}" - return - end - - app, options = ::Rack::Builder.parse_file rackup - options = { - Host: config.host, - Port: config.port, - }.merge(options) - - app = Rack::CommonLogger.new(app, logger) - - logger.info "Starting HTTP server listening on #{config.host}:#{config.port}" - - supervisor = ::Reel::Rack::Server.supervise_as(:ahn_http_server, app, options) - - Adhearsion::Events.register_callback :shutdown do - supervisor.terminate - end - end - end -end diff --git a/lib/adhearsion/i18n.rb b/lib/adhearsion/i18n.rb index 6bda6f12e..01c960b65 100644 --- a/lib/adhearsion/i18n.rb +++ b/lib/adhearsion/i18n.rb @@ -6,12 +6,12 @@ module I18n def self.t(key, options = {}) this_locale = options[:locale] || locale options = {default: '', locale: locale}.merge(options) - prompt = ::I18n.t "#{key}.audio", options - text = ::I18n.t "#{key}.text", options + prompt = ::I18n.t "#{key}.audio", **options + text = ::I18n.t "#{key}.text", **options if prompt.empty? && text.empty? # Look for a translation key that doesn't follow the Adhearsion-I18n structure - text = ::I18n.t key, options + text = ::I18n.t key, **options end unless prompt.empty? diff --git a/lib/adhearsion/initializer.rb b/lib/adhearsion/initializer.rb index 09a46dc31..384dab1d6 100644 --- a/lib/adhearsion/initializer.rb +++ b/lib/adhearsion/initializer.rb @@ -3,7 +3,6 @@ require 'adhearsion/application' require 'adhearsion/linux_proc_name' require 'adhearsion/rayo/initializer' -require 'adhearsion/http_server' require 'rbconfig' module Adhearsion @@ -43,7 +42,6 @@ def start initialize_exception_logger setup_i18n_load_path Rayo::Initializer.init - HTTPServer.start init_plugins Rayo::Initializer.run @@ -145,7 +143,7 @@ def load_lib_folder def load_app_file path = "#{Adhearsion.config.root}/config/app.rb" - load path if File.exists?(path) + load path if File.exist?(path) end def load_config_file @@ -155,12 +153,12 @@ def load_config_file def load_events_file Adhearsion::Events.init path = "#{Adhearsion.config.root}/config/events.rb" - load path if File.exists?(path) + load path if File.exist?(path) end def load_routes_file path = "#{Adhearsion.config.root}/config/routes.rb" - load path if File.exists?(path) + load path if File.exist?(path) end def configure_plugins diff --git a/lib/adhearsion/outbound_call.rb b/lib/adhearsion/outbound_call.rb index bce32cb1c..85750d465 100644 --- a/lib/adhearsion/outbound_call.rb +++ b/lib/adhearsion/outbound_call.rb @@ -94,7 +94,12 @@ def dial(to, options = {}) Adhearsion.active_calls << current_actor write_and_await_response(@dial_command, wait_timeout, true).tap do |dial_command| - @start_time = dial_command.timestamp.to_time + if dial_command.respond_to?(:timestamp) + @start_time = dial_command.timestamp.to_time + else + logger.warn "dial_command #{dial_command.inspect} did not respond to timestamp. @dial_command #{@dial_command.inspect}" + end + if @dial_command.uri != self.uri logger.warn "Requested call URI (#{uri}) was not respected. Tracking by new URI #{self.uri}. This might cause a race in event handling, please upgrade your Rayo server." Adhearsion.active_calls << current_actor diff --git a/lib/adhearsion/process.rb b/lib/adhearsion/process.rb index f562155a8..f857aa6af 100644 --- a/lib/adhearsion/process.rb +++ b/lib/adhearsion/process.rb @@ -107,7 +107,7 @@ def die_now! end def fqdn - Socket.gethostbyname(Socket.gethostname).first + Addrinfo.getaddrinfo(Socket.gethostname, nil).first.getnameinfo.first end def self.method_missing(method_name, *args, &block) diff --git a/lib/adhearsion/script_ahn_loader.rb b/lib/adhearsion/script_ahn_loader.rb index 4aadc424f..a98598ba4 100644 --- a/lib/adhearsion/script_ahn_loader.rb +++ b/lib/adhearsion/script_ahn_loader.rb @@ -22,11 +22,11 @@ def self.exec_script_ahn!(args = ARGV) end def self.in_ahn_application?(path = '.') - Dir.chdir(path) { File.exists? SCRIPT_AHN } + Dir.chdir(path) { File.exist? SCRIPT_AHN } end def self.in_ahn_application_subdirectory?(path = Pathname.new(Dir.pwd)) - File.exists?(File.join(path, SCRIPT_AHN)) || !path.root? && in_ahn_application_subdirectory?(path.parent) + File.exist?(File.join(path, SCRIPT_AHN)) || !path.root? && in_ahn_application_subdirectory?(path.parent) end end end diff --git a/lib/adhearsion/translator/asterisk.rb b/lib/adhearsion/translator/asterisk.rb index 5d1ec1684..044dcdd18 100644 --- a/lib/adhearsion/translator/asterisk.rb +++ b/lib/adhearsion/translator/asterisk.rb @@ -172,7 +172,7 @@ def run_at_fully_booted end def check_recording_directory - logger.warn "Recordings directory #{Component::Record::RECORDING_BASE_PATH} does not exist. Recording might not work. This warning can be ignored if Adhearsion is running on a separate machine than Asterisk. See http://adhearsion.com/docs/call-controllers#recording" unless File.exists?(Component::Record::RECORDING_BASE_PATH) + logger.warn "Recordings directory #{Component::Record::RECORDING_BASE_PATH} does not exist. Recording might not work. This warning can be ignored if Adhearsion is running on a separate machine than Asterisk. See http://adhearsion.com/docs/call-controllers#recording" unless File.exist?(Component::Record::RECORDING_BASE_PATH) end def actor_died(actor, reason)