Using DRb
DRb stands for "Distributed Ruby" and comes with the Ruby standard library. It is a synchronous TCP protocol, recognized only by Ruby, which allows one Ruby process to instantly execute a method in another, separate process.
You may want to use DRb so your Ruby on Rails (or Sinatra, or Merb, etc) applications can instantly access some state of the telephony system or instantly execute a method you've exposed.
Enabling DRb
In your config/startup.rb file, find the line that reads like the following and uncomment it:
config.enable_drb
If you would like to start the DRb with an access control list, you may do this:
config.enable_drb :host => "0.0.0.0", :deny => "0.0.0.0", :allow => ["127.0.0.1", "65.192.53.25"]
Exposing features via DRb
We're going to create a new Adhearsion component named drb_rocks and expose a single method we can execute in a separate process.
With a terminal in the directory of your Adhearsion application, type the following:
ahn create component drb_rocks
methods_for :rpc do def active_call_count ahn_log.drb_rocks "Sending #{Adhearsion.active_calls.size} back via DRb" Adhearsion.active_calls.size end end
After you've enabled DRb in startup.rb and added the component code, go ahead and start your Adhearsion application:
ahn start /path/to/your/app
Connecting into Adhearsion
Now let's create a separate .rb file with just the following code:
require 'drb'
Adhearsion = DRbObject.new_with_uri "druby://localhost:9050"
puts Adhearsion.active_call_count
Some Methods Available via DRb by Default
Class: Adhearsion::VoIP::Asterisk::Manager::ManagerInterface
Example:
require 'drb' Adhearsion = DRbObject.new_with_uri "druby://localhost:9050" Adhearsion.call_into_context("Zap/g0/14155551212","my_context")