radiowaves 0.0.1 → 0.0.2

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/Gemfile CHANGED
@@ -3,5 +3,6 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in radiowaves.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'rack-contrib'
6
7
  gem 'em-websocket'
7
8
  gem 'web-socket-ruby', :require => 'web_socket'
@@ -1,6 +1,9 @@
1
1
  require 'radiowaves/version'
2
+ require 'radiowaves/config'
3
+ require 'radiowaves/logging'
2
4
  require 'radiowaves/transmitter'
3
5
  require 'radiowaves/server'
6
+ require 'radiowaves/railtie'
4
7
 
5
8
  module Radiowaves
6
9
  end
@@ -0,0 +1,13 @@
1
+ module Radiowaves
2
+ module Config
3
+
4
+ def host
5
+ 'localhost'
6
+ end
7
+
8
+ def port
9
+ 12017
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Radiowaves
2
+ module Logging
3
+ def logger
4
+ @logger ||= Logger.new("#{Rails.root}/log/radiowaves.log")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ require 'rack/contrib/response_headers'
2
+
3
+ module Radiowaves
4
+ class Railtie < ::Rails::Railtie
5
+
6
+ include Config
7
+
8
+ rake_tasks do
9
+ load "tasks/radiowaves.tasks"
10
+ end
11
+
12
+ initializer 'radiowaves.add_uri_to_headers' do |app|
13
+ app.middleware.use Rack::ResponseHeaders do |headers|
14
+ headers['X-Radiowaves-URI'] = "ws://#{host}:#{port}"
15
+ end
16
+ end
17
+
18
+ initializer 'radiowaves.start_server' do
19
+ Thread.new {
20
+ Radiowaves::Server.new(host, port).start
21
+ }
22
+ end
23
+
24
+ initializer 'radiowaves.start_transmitter' do
25
+ Radiowaves::Transmitter.new(host, port).start
26
+ end
27
+
28
+ end
29
+ end
30
+
@@ -1,28 +1,36 @@
1
1
  require 'em-websocket'
2
2
 
3
3
  module Radiowaves
4
- class Server < ::Rails::Railtie
4
+ class Server
5
5
 
6
- rake_tasks do
7
- load "tasks/radiowaves.tasks"
6
+ include Logging
7
+
8
+ def initialize(host, port)
9
+ @host = host
10
+ @port = port
8
11
  end
9
12
 
10
- def self.start!(host='localhost', port=12010)
13
+ def start
11
14
  EventMachine.run {
12
15
  @channel = EM::Channel.new
13
- EventMachine::WebSocket.start(:host => host, :port => port) do |ws|
14
- ws.onopen {
15
- sid = @channel.subscribe { |msg| ws.send msg }
16
- ws.onmessage { |msg|
17
- @channel.push "#{msg}"
18
- }
19
- ws.onclose {
20
- @channel.unsubscribe(sid)
21
- }
16
+ EventMachine::WebSocket.start(:host => @host, :port => @port) do |ws|
17
+ ws.onopen {
18
+ logger.debug "*** ws.onopen"
19
+ sid = @channel.subscribe { |msg|
20
+ ws.send msg
21
+ }
22
+ ws.onmessage { |msg|
23
+ @channel.push "#{msg}"
22
24
  }
25
+ ws.onclose {
26
+ logger.debug "*** ws.onclose: #{sid}"
27
+ @channel.unsubscribe(sid)
28
+ }
29
+ }
23
30
  end
24
31
  }
25
32
  end
33
+
26
34
  end
27
35
  end
28
36
 
@@ -1,18 +1,21 @@
1
1
  require 'web_socket'
2
2
 
3
3
  module Radiowaves
4
- class Transmitter < ::Rails::Railtie
4
+ class Transmitter
5
5
 
6
- initializer "radiowaves.transmitter" do
7
- Radiowaves::Transmitter.start!
6
+ include Logging
7
+
8
+ def initialize(host, port)
9
+ @client = WebSocket.new("ws://#{host}:#{port}/")
8
10
  end
9
11
 
10
- def self.start!(host='localhost', port=12010)
12
+ def start
11
13
  ActiveSupport::Notifications.subscribe('process_action.action_controller') do |*args|
12
- client = WebSocket.new("ws://#{host}:#{port}/")
13
- client.send(ActiveSupport::Notifications::Event.new(*args).to_json)
14
+ event = ActiveSupport::Notifications::Event.new(*args).to_json
15
+ @client.send(event)
14
16
  end
15
17
  end
18
+
16
19
  end
17
20
  end
18
21
 
@@ -1,3 +1,3 @@
1
1
  module Radiowaves
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -12,6 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = %q{Transmits notifications in Rails to a websocket. Born as a supporting gem for "Rails panel" extension in Chrome.}
13
13
  gem.homepage = "https://github.com/dejan/radiowaves"
14
14
 
15
+ gem.add_dependency('rack-contrib')
15
16
  gem.add_dependency('em-websocket')
16
17
  gem.add_dependency('web-socket-ruby')
17
18
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiowaves
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-18 00:00:00.000000000 Z
12
+ date: 2012-11-24 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack-contrib
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: em-websocket
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -56,6 +72,9 @@ files:
56
72
  - README.md
57
73
  - Rakefile
58
74
  - lib/radiowaves.rb
75
+ - lib/radiowaves/config.rb
76
+ - lib/radiowaves/logging.rb
77
+ - lib/radiowaves/railtie.rb
59
78
  - lib/radiowaves/server.rb
60
79
  - lib/radiowaves/transmitter.rb
61
80
  - lib/radiowaves/version.rb