punchblock-console 0.1.0 → 0.1.1
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 +12 -1
- data/Gemfile +0 -2
- data/Rakefile +3 -0
- data/bin/pbconsole +14 -82
- data/lib/punchblock/console/cli.rb +107 -0
- data/lib/punchblock/console/version.rb +1 -1
- metadata +23 -20
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Rakefile
ADDED
data/bin/pbconsole
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$:.push File.join(File.dirname(__FILE__), '..', 'lib')
|
3
3
|
require 'rubygems'
|
4
|
-
require 'punchblock'
|
5
|
-
require 'pry'
|
6
4
|
require 'logger'
|
7
5
|
require 'optparse'
|
8
|
-
require 'punchblock/console/
|
6
|
+
require 'punchblock/console/cli'
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
options = { :username => 'usera@127.0.0.1', :password => '1', :auto_reconnect => false }
|
8
|
+
options = { :username => 'usera@127.0.0.1',
|
9
|
+
:password => '1',
|
10
|
+
:auto_reconnect => false,
|
11
|
+
:connection_class => Connection::XMPP }
|
15
12
|
|
16
13
|
option_parser = OptionParser.new do |opts|
|
17
14
|
opts.banner = "Usage: punchblock-console [-u usera@127.0.0.1] [-p abc123]"
|
@@ -30,6 +27,14 @@ option_parser = OptionParser.new do |opts|
|
|
30
27
|
opts.on("--transport-log-file log/transportlog.log", String, "Specify the file to which the transport log should be written") do |tlf|
|
31
28
|
options[:transport_log_file] = tlf
|
32
29
|
end
|
30
|
+
opts.on("--asterisk", "Use Asterisk") do |tlf|
|
31
|
+
options[:connection_class] = Connection::Asterisk
|
32
|
+
options[:host] = '127.0.0.1'
|
33
|
+
options[:port] = 5038
|
34
|
+
end
|
35
|
+
opts.on("--prompt", "Provide a prompt immediately") do |tlf|
|
36
|
+
options[:prompt] = true
|
37
|
+
end
|
33
38
|
opts.on_tail("-h", "--help", "Show this message") do
|
34
39
|
puts opts
|
35
40
|
exit
|
@@ -47,77 +52,4 @@ rescue
|
|
47
52
|
option_parser.parse '--help'
|
48
53
|
end
|
49
54
|
|
50
|
-
|
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
|
55
|
+
PunchblockConsole::CLI.new(options).run
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'punchblock'
|
2
|
+
require 'pry'
|
3
|
+
require 'punchblock/console/commands'
|
4
|
+
|
5
|
+
include Punchblock
|
6
|
+
|
7
|
+
Thread.abort_on_exception = true
|
8
|
+
|
9
|
+
module PunchblockConsole
|
10
|
+
class CLI
|
11
|
+
attr_reader :options, :connection, :client, :call_queues
|
12
|
+
|
13
|
+
def initialize(options)
|
14
|
+
@options = options
|
15
|
+
setup_logging
|
16
|
+
@prompt = options.delete(:prompt)
|
17
|
+
@connection = options.delete(:connection_class).new options
|
18
|
+
@client = Client.new :connection => connection
|
19
|
+
@call_queues = {}
|
20
|
+
|
21
|
+
[:INT, :TERM].each do |signal|
|
22
|
+
trap signal do
|
23
|
+
puts "Shutting down!"
|
24
|
+
client.stop
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup_logging
|
30
|
+
if options.has_key? :wire_log_file
|
31
|
+
options[:wire_logger] = Logger.new options.delete(:wire_log_file)
|
32
|
+
options[:wire_logger].level = Logger::DEBUG
|
33
|
+
options[:wire_logger].debug "Starting up..."
|
34
|
+
end
|
35
|
+
|
36
|
+
if options.has_key? :transport_log_file
|
37
|
+
options[:transport_logger] = Logger.new options.delete(:transport_log_file)
|
38
|
+
options[:transport_logger].level = Logger::DEBUG
|
39
|
+
options[:transport_logger].debug "Starting up..."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def run
|
44
|
+
run_dispatcher
|
45
|
+
client_thread = run_client
|
46
|
+
pry if @prompt
|
47
|
+
client_thread.join
|
48
|
+
end
|
49
|
+
|
50
|
+
def run_client
|
51
|
+
Thread.new do
|
52
|
+
begin
|
53
|
+
client.run
|
54
|
+
rescue => e
|
55
|
+
puts "Exception in Punchblock client thread! #{e.message}"
|
56
|
+
puts e.backtrace.join("\t\n")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def run_dispatcher
|
62
|
+
### DISPATCHER THREAD
|
63
|
+
# This thread multiplexes the event stream from the underlying connection
|
64
|
+
# handler and routes them to the correct queue for each call. It also starts
|
65
|
+
# a call handler, the run_call method) after creating the queue.
|
66
|
+
Thread.new do
|
67
|
+
loop do
|
68
|
+
event = client.event_queue.pop
|
69
|
+
case event
|
70
|
+
when Connection::Connected
|
71
|
+
puts "Punchblock connected!"
|
72
|
+
when Event::Offer
|
73
|
+
raise "Duplicate call ID for #{event.call_id}" if call_queues.has_key?(event.call_id)
|
74
|
+
call_queues[event.call_id] = Queue.new
|
75
|
+
call_queues[event.call_id].push event
|
76
|
+
run_call client, event
|
77
|
+
when Event
|
78
|
+
if event.call_id
|
79
|
+
call_queues[event.call_id].push event
|
80
|
+
else
|
81
|
+
puts "Ad-hoc event: #{event.inspect}"
|
82
|
+
end
|
83
|
+
else
|
84
|
+
puts "Unknown event: #{event.inspect}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def run_call(client, offer)
|
91
|
+
### CALL THREAD
|
92
|
+
# One thread is spun up to handle each call.
|
93
|
+
Thread.new do
|
94
|
+
raise "Unknown call #{offer.call_id}" unless call_queues.has_key?(offer.call_id)
|
95
|
+
queue = call_queues[offer.call_id]
|
96
|
+
call = queue.pop
|
97
|
+
|
98
|
+
puts "Incoming offer to #{offer.to} from #{offer.headers_hash[:from]} #{offer}"
|
99
|
+
|
100
|
+
PunchblockConsole::Commands.new(client, offer.call_id, queue).pry
|
101
|
+
|
102
|
+
# Clean up the queue.
|
103
|
+
call_queues[offer.call_id] = nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: punchblock-console
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2011-11-
|
14
|
+
date: 2011-11-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: punchblock
|
18
|
-
requirement: &
|
18
|
+
requirement: &2152927980 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>='
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: 0.5.0
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *2152927980
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
|
-
requirement: &
|
29
|
+
requirement: &2152927340 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ~>
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: 1.0.0
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *2152927340
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rspec
|
40
|
-
requirement: &
|
40
|
+
requirement: &2152925960 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
@@ -45,10 +45,10 @@ dependencies:
|
|
45
45
|
version: 2.3.0
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *2152925960
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: ci_reporter
|
51
|
-
requirement: &
|
51
|
+
requirement: &2152966460 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
53
53
|
requirements:
|
54
54
|
- - ! '>='
|
@@ -56,10 +56,10 @@ dependencies:
|
|
56
56
|
version: 1.6.3
|
57
57
|
type: :development
|
58
58
|
prerelease: false
|
59
|
-
version_requirements: *
|
59
|
+
version_requirements: *2152966460
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: yard
|
62
|
-
requirement: &
|
62
|
+
requirement: &2152965960 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
64
|
requirements:
|
65
65
|
- - ~>
|
@@ -67,10 +67,10 @@ dependencies:
|
|
67
67
|
version: 0.6.0
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
|
-
version_requirements: *
|
70
|
+
version_requirements: *2152965960
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rcov
|
73
|
-
requirement: &
|
73
|
+
requirement: &2152965440 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
76
|
- - ! '>='
|
@@ -78,10 +78,10 @@ dependencies:
|
|
78
78
|
version: '0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
|
-
version_requirements: *
|
81
|
+
version_requirements: *2152965440
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: rake
|
84
|
-
requirement: &
|
84
|
+
requirement: &2152964760 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
87
|
- - ! '>='
|
@@ -89,10 +89,10 @@ dependencies:
|
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
|
-
version_requirements: *
|
92
|
+
version_requirements: *2152964760
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: mocha
|
95
|
-
requirement: &
|
95
|
+
requirement: &2152964020 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
98
98
|
- - ! '>='
|
@@ -100,10 +100,10 @@ dependencies:
|
|
100
100
|
version: '0'
|
101
101
|
type: :development
|
102
102
|
prerelease: false
|
103
|
-
version_requirements: *
|
103
|
+
version_requirements: *2152964020
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: i18n
|
106
|
-
requirement: &
|
106
|
+
requirement: &2152963240 !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
108
|
requirements:
|
109
109
|
- - ! '>='
|
@@ -111,7 +111,7 @@ dependencies:
|
|
111
111
|
version: '0'
|
112
112
|
type: :development
|
113
113
|
prerelease: false
|
114
|
-
version_requirements: *
|
114
|
+
version_requirements: *2152963240
|
115
115
|
description: This gem provides a simple interactive console for troubleshooting and
|
116
116
|
debugging the Rayo protocol via Punchblock.
|
117
117
|
email: punchblock@adhearsion.com
|
@@ -124,7 +124,9 @@ files:
|
|
124
124
|
- Gemfile
|
125
125
|
- LICENSE.txt
|
126
126
|
- README
|
127
|
+
- Rakefile
|
127
128
|
- bin/pbconsole
|
129
|
+
- lib/punchblock/console/cli.rb
|
128
130
|
- lib/punchblock/console/commands.rb
|
129
131
|
- lib/punchblock/console/version.rb
|
130
132
|
- punchblock-console.gemspec
|
@@ -154,3 +156,4 @@ signing_key:
|
|
154
156
|
specification_version: 3
|
155
157
|
summary: An interactive debugging console for Punchblock
|
156
158
|
test_files: []
|
159
|
+
has_rdoc:
|