asterisk-ami 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23aad48f08a544364eb4b8141a1a007ccbf9ad44
4
- data.tar.gz: b8a33710c383e6862b7d1ad8a3a2298697ffdc75
3
+ metadata.gz: d2c16d3026df5c4f13a86a2a772fdf6cae201ed3
4
+ data.tar.gz: 2b46c96f5058776a98ddc6a35dfefe3bb55c3166
5
5
  SHA512:
6
- metadata.gz: 72b32e800d65e830cadb351785a91ea6b4affa3a07ea5a62f09fb77deb02a5cde68bc11c5c207d6faba61b131c94d8b85b4a2dddc4a8ef054d88e918cf87d516
7
- data.tar.gz: 136424727ecabc5559b08096db78e5647bcd05e183e741820469b41f9910411bbf684a5c21f00c294307be76c447b7328ec12e2efbbfbbef3ca8c77fcafd5f0f
6
+ metadata.gz: f88972ba1a2a6633b03fd8ed7594b4a07bc2608dcaa693fab203c055c546e78550127c5d9392c517e71d3e7fc221e90af38a05bab6ecc28611e61561ff96b3ac
7
+ data.tar.gz: b2c99e20a2ba41333d681c13106372988ea3ae519192f6d3688d4c45c37e0ec8032319b7c564b4ac2d2e0cc4fcc6d5655d80dd04ed862225a4c70ebfbf0d8c74
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Asterisk::Ami
2
2
 
3
- TODO: Write a gem description
3
+ Asterisk Websocket to AMI proxy.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,9 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Run the ami proxy from the command line with the following command changing the ami_* parameters with your access details for asterisk.
22
+
23
+ $ bundle exec asterisk-ami localhost 8088 ami_user ami_password ami_host
22
24
 
23
25
  ## Contributing
24
26
 
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "titleize"
22
22
  spec.add_dependency "json"
23
- spec.add_dependency "em-websocket", "> 0.5.0"
23
+ spec.add_dependency "em-websocket", ">= 0.5.0"
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
26
26
  end
data/lib/ami.rb CHANGED
@@ -9,6 +9,7 @@ module Asterisk
9
9
 
10
10
  def initialize(username, password, host="localhost", port=5038)
11
11
  @connection = Asterisk::Connection.new(username, password, host, port)
12
+ @connected = false
12
13
  end
13
14
 
14
15
  def connect
@@ -95,5 +96,8 @@ module Asterisk
95
96
  Asterisk::Action.new("MailboxCount", {"Mailbox" => "#{exten}@#{context}"}).send(@connection)
96
97
  end
97
98
 
99
+ private
100
+ attr_accessor :connected
101
+
98
102
  end
99
103
  end
@@ -2,12 +2,13 @@ require File.expand_path(File.dirname(__FILE__)) + "/message_helper"
2
2
 
3
3
  module Asterisk
4
4
  class Action
5
+
5
6
  include Asterisk::MessageHelper
6
7
 
7
8
  def initialize(command, options={})
8
9
  @command = command
9
10
  @options = options
10
- @options[:action_id] = Random.rand(9999) unless @options.has_key?(:action_id)
11
+ @options[:action_id] = Random.rand(99999999) unless @options[:action_id]
11
12
  end
12
13
 
13
14
  def self.parse(str)
@@ -17,11 +18,11 @@ module Asterisk
17
18
 
18
19
  # send the ami action
19
20
  def send(connection)
20
- #puts self.to_ami
21
- connection.write(self.to_ami + "\r\n\r\n")
22
- #connection.waitfor("Match" => /\r\n\r\n/) do |received_data|
23
- #puts received_data
24
- #end
21
+ connection.write(self.to_ami)
22
+ end
23
+
24
+ def action_id
25
+ @options[:action_id]
25
26
  end
26
27
 
27
28
  # convert the action to ami string to send down wire
@@ -1,5 +1,5 @@
1
1
  module Asterisk
2
2
  module Ami
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -20,13 +20,13 @@ module Asterisk
20
20
  puts "connected"
21
21
  @connection.waitfor(/Asterisk Call Manager\/\d+\.\d+/) {|response| puts response }
22
22
  puts "Logging in.."
23
- Asterisk::Action.new(:login, :username => @username, :secret => @password).send(@connection)
23
+ Asterisk::Action.new(:login, :username => @username, :secret => @password).send(self)
24
24
  puts "Done."
25
25
  end
26
26
  end
27
27
 
28
- def write(str)
29
- @connection.write(str + "\r\n\r\n")
28
+ def write(command)
29
+ @connection.write(command + "\r\n\r\n")
30
30
  end
31
31
 
32
32
  def events(&block)
@@ -43,6 +43,8 @@ module Asterisk
43
43
  begin
44
44
  if message.include?("Event")
45
45
  yield Asterisk::Event.parse(message) if block_given?
46
+ else
47
+ puts message
46
48
  end
47
49
  rescue Errno::EPIPE => e
48
50
  puts "Error in connection to Asterisk: #{e.message}"
@@ -1,9 +1,10 @@
1
- module Asterisk
1
+ require File.expand_path(File.dirname(__FILE__)) + "/message_helper"
2
2
 
3
+ module Asterisk
3
4
  class Event
4
5
  include Asterisk::MessageHelper
5
6
  def self.parse(str)
6
7
  parse_lines(str)
7
8
  end
8
9
  end
9
- end
10
+ end
@@ -9,24 +9,26 @@ require 'em-websocket'
9
9
  Thread.abort_on_exception = true
10
10
  # WebSocket.debug = true
11
11
 
12
- if ARGV.size != 5
13
- $stderr.puts("Usage: asterisk-ami ACCEPTED_DOMAIN PORT AMI_USERNAME AMI_PASSWORD AMI_HOSTNAME")
12
+ if ARGV.size < 3
13
+ $stderr.puts("Usage: asterisk-ami AMI_USERNAME AMI_PASSWORD AMI_HOSTNAME [ACCEPTED_DOMAIN] [PORT]")
14
14
  exit(1)
15
15
  end
16
16
 
17
- # server = WebSocketServer.new(
18
- # :accepted_domains => [ARGV[0], "localhost"],
19
- # :port => ARGV[1].to_i())
20
17
 
21
- port = ARGV[1].to_i
22
18
 
23
- ami_username = ARGV[2]
24
- ami_password = ARGV[3]
25
- ami_host = ARGV[4]
19
+ host = ARGV[3]
20
+ port = ARGV[4].to_i
21
+
22
+ ami_host = ARGV[0]
23
+ ami_username = ARGV[1]
24
+ ami_password = ARGV[2]
25
+
26
+ host = "0.0.0.0" if host.nil?
27
+ port = 8088 if port==0
26
28
 
27
29
  puts "Starting Server on port #{port}"
28
30
  EM.run {
29
- EM::WebSocket.run(:host => "0.0.0.0", :port => port) do |ws|
31
+ EM::WebSocket.run(:host => host, :port => port) do |ws|
30
32
  ws.onopen { |handshake|
31
33
 
32
34
  puts "Websocket connection request received"
@@ -44,18 +46,48 @@ EM.run {
44
46
  puts "Recieved message: #{msg}"
45
47
 
46
48
  if msg.is_json?
47
- puts "its json"
48
49
  data = JSON.parse(msg)
49
- puts data
50
50
  if data["command"]
51
- puts "its a command"
52
51
  case data["command"]
53
52
  when "initiate-call"
54
- puts "initiate call!"
55
- ami_command = Asterisk::Action.new("Originate", :channel => "SIP/#{data["from"]}", :exten => data["to"], :priority => 1, :context => "default")
56
- puts ami_command.to_ami
53
+ ami_command = Asterisk::Action.new(:originate, :action_id => data["action_id"], :channel => "SIP/#{data["from"]}", :extension => data["to"], :priority => 1, :context => "default")
54
+ when "hangup"
55
+ ami_command = Asterisk::Action.new(:hangup, :action_id => data["action_id"], :channel => data["channel"])
56
+ when "transfer"
57
+ ami_command = Asterisk::Action.new(:blind_transfer, :action_id => data["action_id"], :channel => data["channel"], :extension => data["to"], :context => "default")
58
+
59
+ when "hold"
60
+ if data.has_key?("timeout")
61
+ timeout = data["timeout"].to_s.to_i
62
+ else
63
+ timeout = 60
64
+ end
65
+ ami_command = Asterisk::Action.new(:park, :action_id => data["action_id"], :channel => data["channel"], :channel2 => data["my_channel"], :timeout => (timeout*1000).to_s)
66
+ when "unhold"
67
+ ami_command = Asterisk::Action.new(:bridge, :action_id => data["action_id"], :channel => data["my_channel"], :channel2 => data["remote_channel"], :tone => "yes")
68
+ when "start-recording"
69
+ ami_command = Asterisk::Action.new(:monitor, :action_id => data["action_id"], :channel => data["channel"], :format => "wav", :mix => "true")
70
+ when "stop-recording"
71
+ ami_command = Asterisk::Action.new(:stop_monitor, :action_id => data["action_id"], :channel => data["channel"])
72
+ when "pause-recording"
73
+ ami_command = Asterisk::Action.new(:pause_monitor, :action_id => data["action_id"], :channel => data["channel"])
74
+ when "resume-recording"
75
+ ami_command = Asterisk::Action.new(:unpause_monitor, :action_id => data["action_id"], :channel => data["channel"])
76
+ when "queue-add"
77
+ ami_command = Asterisk::Action.new(:queue_add, :action_id => data["action_id"], :channel => data["channel"])
78
+ when "queue-pause"
79
+ ami_command = Asterisk::Action.new(:queue_pause, :action_id => data["action_id"], :channel => data["channel"])
80
+ when "queue-remove"
81
+ ami_command = Asterisk::Action.new(:queue_remove, :action_id => data["action_id"], :channel => data["channel"])
82
+ when "queues"
83
+ ami_command = Asterisk::Action.new(:queues, :action_id => data["action_id"], :channel => data["channel"])
84
+ when "queue-status"
85
+ ami_command = Asterisk::Action.new(:queue_status, :action_id => data["action_id"], :channel => data["channel"])
86
+ when "get_variable"
87
+ ami_command = Asterisk::Action.new(:get_var, :action_id => data["action_id"], :channel => data["channel"], :variable => data["name"])
57
88
  end
58
- ami_command.send(@connection)
89
+ puts ami_command.to_ami
90
+ @connection.send(ami_command)
59
91
  else
60
92
  ws.send ("No action found to execute, you must supply a command")
61
93
  end
@@ -64,9 +96,10 @@ EM.run {
64
96
  end
65
97
  }
66
98
 
67
- @connection = Asterisk::Connection.new(ARGV[2], ARGV[3], ARGV[4])
99
+ @connection = Asterisk::Connection.new(ami_username, ami_password, ami_host)
68
100
  t = Thread.new do
69
101
  @connection.events do |data|
102
+ puts " ==== #{data[:event]} ==== "
70
103
  puts data.to_json
71
104
  ws.send(data.to_json)
72
105
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asterisk-ami
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stewart McKee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-27 00:00:00.000000000 Z
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: titleize
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: em-websocket
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.5.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.5.0
55
55
  - !ruby/object:Gem::Dependency
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  requirements: []
129
129
  rubyforge_project:
130
- rubygems_version: 2.2.0.rc.1
130
+ rubygems_version: 2.4.8
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Asterisk AMI integration gem