punchblock-console 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README +0 -0
- data/bin/pbconsole +123 -0
- data/lib/punchblock/console/commands.rb +41 -0
- data/lib/punchblock/console/version.rb +3 -0
- data/punchblock-console.gemspec +33 -0
- metadata +156 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2011 The Adhearsion Foundation, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
File without changes
|
data/bin/pbconsole
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
require 'rubygems'
|
4
|
+
require 'punchblock'
|
5
|
+
require 'pry'
|
6
|
+
require 'logger'
|
7
|
+
require 'optparse'
|
8
|
+
require 'punchblock/console/commands'
|
9
|
+
|
10
|
+
include Punchblock
|
11
|
+
|
12
|
+
Thread.abort_on_exception = true
|
13
|
+
|
14
|
+
options = { :username => 'usera@127.0.0.1', :password => '1', :auto_reconnect => false }
|
15
|
+
|
16
|
+
option_parser = OptionParser.new do |opts|
|
17
|
+
opts.banner = "Usage: punchblock-console [-u usera@127.0.0.1] [-p abc123]"
|
18
|
+
opts.on("-u", "--username USERNAME", String, "Specify the XMPP JID to connect to") do |u|
|
19
|
+
options[:username] = u
|
20
|
+
end
|
21
|
+
opts.on("-p", "--password PASSWORD", String, "Specify the XMPP password to use") do |p|
|
22
|
+
options[:password] = p
|
23
|
+
end
|
24
|
+
opts.on("-d", "--rayo-domain DOMAIN", String, "Specify the domain Rayo is running on") do |d|
|
25
|
+
options[:rayo_domain] = d
|
26
|
+
end
|
27
|
+
opts.on("--wire-log-file log/wirelog.log", String, "Specify the file to which the wire log should be written") do |wlf|
|
28
|
+
options[:wire_log_file] = wlf
|
29
|
+
end
|
30
|
+
opts.on("--transport-log-file log/transportlog.log", String, "Specify the file to which the transport log should be written") do |tlf|
|
31
|
+
options[:transport_log_file] = tlf
|
32
|
+
end
|
33
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
34
|
+
puts opts
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
opts.on_tail("-v", "--version", "Show version") do
|
38
|
+
puts VERSION
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
option_parser.parse!
|
45
|
+
rescue
|
46
|
+
puts $!
|
47
|
+
option_parser.parse '--help'
|
48
|
+
end
|
49
|
+
|
50
|
+
if options.has_key? :wire_log_file
|
51
|
+
options[:wire_logger] = Logger.new options.delete(:wire_log_file)
|
52
|
+
options[:wire_logger].level = Logger::DEBUG
|
53
|
+
options[:wire_logger].debug "Starting up..."
|
54
|
+
end
|
55
|
+
|
56
|
+
if options.has_key? :transport_log_file
|
57
|
+
options[:transport_logger] = Logger.new options.delete(:transport_log_file)
|
58
|
+
options[:transport_logger].level = Logger::DEBUG
|
59
|
+
options[:transport_logger].debug "Starting up..."
|
60
|
+
end
|
61
|
+
|
62
|
+
connection = Connection::XMPP.new options
|
63
|
+
client = Client.new :connection => connection
|
64
|
+
|
65
|
+
[:INT, :TERM].each do |signal|
|
66
|
+
trap signal do
|
67
|
+
puts "Shutting down!"
|
68
|
+
client.stop
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
client_thread = Thread.new do
|
73
|
+
begin
|
74
|
+
client.run
|
75
|
+
rescue => e
|
76
|
+
puts "Exception in XMPP thread! #{e.message}"
|
77
|
+
puts e.backtrace.join("\t\n")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
CALL_QUEUES = {}
|
82
|
+
|
83
|
+
### DISPATCHER THREAD
|
84
|
+
# This thread multiplexes the event stream from the underlying connection
|
85
|
+
# handler and routes them to the correct queue for each call. It also starts
|
86
|
+
# a call handler, the run_call method) after creating the queue.
|
87
|
+
Thread.new do
|
88
|
+
loop do
|
89
|
+
event = client.event_queue.pop
|
90
|
+
case event
|
91
|
+
when Punchblock::Connection::Connected
|
92
|
+
puts "Punchblock connected!"
|
93
|
+
when Event::Offer
|
94
|
+
raise "Duplicate call ID for #{event.call_id}" if CALL_QUEUES.has_key?(event.call_id)
|
95
|
+
CALL_QUEUES[event.call_id] = Queue.new
|
96
|
+
CALL_QUEUES[event.call_id].push event
|
97
|
+
run_call client, event
|
98
|
+
when Event
|
99
|
+
CALL_QUEUES[event.call_id].push event
|
100
|
+
else
|
101
|
+
puts "Unknown event: #{event.inspect}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def run_call(client, offer)
|
107
|
+
### CALL THREAD
|
108
|
+
# One thread is spun up to handle each call.
|
109
|
+
Thread.new do
|
110
|
+
raise "Unknown call #{offer.call_id}" unless CALL_QUEUES.has_key?(offer.call_id)
|
111
|
+
queue = CALL_QUEUES[offer.call_id]
|
112
|
+
call = queue.pop
|
113
|
+
commands = PunchblockConsole::Commands.new client, offer.call_id, queue
|
114
|
+
|
115
|
+
puts "Incoming offer to #{offer.to} from #{offer.headers_hash[:from]} #{offer}"
|
116
|
+
commands.pry
|
117
|
+
|
118
|
+
# Clean up the queue.
|
119
|
+
CALL_QUEUES[offer.call_id] = nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
client_thread.join
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module PunchblockConsole
|
2
|
+
class Commands
|
3
|
+
def initialize(client, call_id, queue) # :nodoc:
|
4
|
+
@client, @call_id, @queue = client, call_id, queue
|
5
|
+
end
|
6
|
+
|
7
|
+
def accept # :nodoc:
|
8
|
+
write Command::Accept.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def answer # :nodoc:
|
12
|
+
write Command::Answer.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def hangup # :nodoc:
|
16
|
+
write Command::Hangup.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def reject(reason = nil) # :nodoc:
|
20
|
+
write Command::Reject.new(:reason => reason)
|
21
|
+
end
|
22
|
+
|
23
|
+
def redirect(dest) # :nodoc:
|
24
|
+
write Command::Redirect.new(:to => dest)
|
25
|
+
end
|
26
|
+
|
27
|
+
def record(options = {})
|
28
|
+
write Component::Record.new(options)
|
29
|
+
end
|
30
|
+
|
31
|
+
def say(string, type = :text) # :nodoc:
|
32
|
+
component = Component::Tropo::Say.new(type => string)
|
33
|
+
write component
|
34
|
+
component.complete_event.resource
|
35
|
+
end
|
36
|
+
|
37
|
+
def write(command) # :nodoc:
|
38
|
+
@client.execute_command command, :call_id => @call_id, :async => false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "punchblock/console/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "punchblock-console"
|
7
|
+
s.version = PunchblockConsole::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.licenses = ["MIT"]
|
10
|
+
s.authors = ["Ben Klang", "Ben Langfeld", "Jason Goecke"]
|
11
|
+
s.email = %q{punchblock@adhearsion.com}
|
12
|
+
s.homepage = %q{https://github.com/adhearsion/punchblock}
|
13
|
+
s.summary = "An interactive debugging console for Punchblock"
|
14
|
+
s.description = "This gem provides a simple interactive console for troubleshooting and debugging the Rayo protocol via Punchblock."
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.7") if s.respond_to? :required_rubygems_version=
|
22
|
+
|
23
|
+
s.add_runtime_dependency %q<punchblock>, [">= 0.5.0"]
|
24
|
+
|
25
|
+
s.add_development_dependency %q<bundler>, ["~> 1.0.0"]
|
26
|
+
s.add_development_dependency %q<rspec>, ["~> 2.3.0"]
|
27
|
+
s.add_development_dependency %q<ci_reporter>, [">= 1.6.3"]
|
28
|
+
s.add_development_dependency %q<yard>, ["~> 0.6.0"]
|
29
|
+
s.add_development_dependency %q<rcov>, [">= 0"]
|
30
|
+
s.add_development_dependency %q<rake>, [">= 0"]
|
31
|
+
s.add_development_dependency %q<mocha>, [">= 0"]
|
32
|
+
s.add_development_dependency %q<i18n>, [">= 0"]
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: punchblock-console
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben Klang
|
9
|
+
- Ben Langfeld
|
10
|
+
- Jason Goecke
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2011-11-07 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: punchblock
|
18
|
+
requirement: &2151883000 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.5.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *2151883000
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: &2151877900 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.0.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *2151877900
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rspec
|
40
|
+
requirement: &2151876080 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.3.0
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *2151876080
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: ci_reporter
|
51
|
+
requirement: &2151873160 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.6.3
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *2151873160
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: yard
|
62
|
+
requirement: &2151871300 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.6.0
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *2151871300
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rcov
|
73
|
+
requirement: &2151867980 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *2151867980
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rake
|
84
|
+
requirement: &2151864940 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *2151864940
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: mocha
|
95
|
+
requirement: &2151860240 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *2151860240
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: i18n
|
106
|
+
requirement: &2151858800 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: *2151858800
|
115
|
+
description: This gem provides a simple interactive console for troubleshooting and
|
116
|
+
debugging the Rayo protocol via Punchblock.
|
117
|
+
email: punchblock@adhearsion.com
|
118
|
+
executables:
|
119
|
+
- pbconsole
|
120
|
+
extensions: []
|
121
|
+
extra_rdoc_files: []
|
122
|
+
files:
|
123
|
+
- .gitignore
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README
|
127
|
+
- bin/pbconsole
|
128
|
+
- lib/punchblock/console/commands.rb
|
129
|
+
- lib/punchblock/console/version.rb
|
130
|
+
- punchblock-console.gemspec
|
131
|
+
homepage: https://github.com/adhearsion/punchblock
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ! '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 1.3.7
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.8.10
|
153
|
+
signing_key:
|
154
|
+
specification_version: 3
|
155
|
+
summary: An interactive debugging console for Punchblock
|
156
|
+
test_files: []
|