Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Created August 16, 2011 09:20
Show Gist options
  • Save chrisroos/1148721 to your computer and use it in GitHub Desktop.
Save chrisroos/1148721 to your computer and use it in GitHub Desktop.
Testing communication between two Tropo clients

Very simple project to test the problem we're seeing with Tropo clients receiving events for calls they didn't initiate.

In one terminal start the 'answer' script with ruby answer.rb. In the other start the 'dial' script with ruby dial.rb. The dial script correctly sends a dial command and the answer script correctly answers. What's odd is that the answer script gets events for 'ringing' and 'answered'. My understanding is that those events should be sent to the dial script as that's responsible for the call it initiated.

require 'bundler/setup'
require 'blather/client/client'
Blather.logger.level = Logger::DEBUG
client = Blather::Client.setup '[email protected]', '1'
client.register_handler(:ready) do
puts "Connected ! send messages to #{client.jid.stripped}."
end
client.register_handler(:presence) do |m|
if m.xpath('//x:offer', 'x' => 'urn:xmpp:rayo:1').any?
answer_iq = Blather::Stanza::Iq.new(:set, m.from.to_s)
answer_iq['from'] = m.to.to_s
Nokogiri::XML::Builder.with(answer_iq) do |xml|
xml.send "answer_", {"xmlns" => 'urn:xmpp:rayo:1'}
end
client.write answer_iq
end
end
EM.run do
client.run
end
require 'bundler/setup'
require 'blather/client/client'
Blather.logger.level = Logger::DEBUG
client = Blather::Client.setup '[email protected]', '1'
client.register_handler(:ready) do
puts "Connected ! send messages to #{client.jid.stripped}."
dial_iq = Blather::Stanza::Iq.new(:set, '127.0.0.1')
dial_iq['from'] = '[email protected]'
Nokogiri::XML::Builder.with(dial_iq) do |xml|
xml.send "dial_", {"xmlns" => 'urn:xmpp:rayo:1', 'to' => 'sip:[email protected]', 'from' => 'sip:[email protected]'}
end
client.write dial_iq
end
client.register_handler(:presence) do |m|
end
EM.run do
client.run
end
source :rubygems
gem 'blather'
GEM
remote: http://rubygems.org/
specs:
activesupport (3.0.9)
blather (0.5.4)
activesupport (>= 3.0.7)
eventmachine (~> 0.12.6)
minitest (>= 1.7.1)
niceogiri (>= 0.0.4)
nokogiri (~> 1.4.0)
eventmachine (0.12.10)
minitest (2.4.0)
niceogiri (0.0.4)
nokogiri (>= 1.4.0)
nokogiri (1.4.7)
PLATFORMS
ruby
DEPENDENCIES
blather
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment