websocket-rails 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,10 +2,10 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rspec-rails"
5
+ gem "rspec-rails", ">=2.12.0"
6
6
  gem "therubyrhino"
7
7
  gem "therubyracer"
8
- gem "jasmine"
8
+ gem "jasmine", ">=1.2.0"
9
9
  gem "headless"
10
10
  gem "coffee-script"
11
11
  gem "thin"
@@ -16,6 +16,7 @@ gem "ruby_gntp"
16
16
  gem "guard"
17
17
  gem "guard-rspec"
18
18
  gem "guard-coffeescript"
19
+ gem "rb-fsevent"
19
20
 
20
21
  platforms :jruby do
21
22
  gem 'activerecord-jdbcsqlite3-adapter', :require => 'jdbc-sqlite3', :require => 'arjdbc'
data/README.md CHANGED
@@ -33,6 +33,7 @@ Check out the [Example Application](https://github.com/DanKnox/websocket-rails-E
33
33
  * [The
34
34
  DataStore](https://github.com/DanKnox/websocket-rails/wiki/Using-the-DataStore)
35
35
  * [Reloading Controllers In Development](https://github.com/DanKnox/websocket-rails/wiki/Reloading-Controllers-In-Development)
36
+ * [Multiple Servers and Background Jobs](https://github.com/DanKnox/websocket-rails/wiki/Multiple-Servers-and-Background-Jobs)
36
37
 
37
38
  ## Handle Events With Class
38
39
 
data/lib/config.ru ADDED
@@ -0,0 +1,3 @@
1
+ require "websocket-rails"
2
+
3
+ run WebsocketRails::ConnectionManager.new
@@ -1,3 +1,23 @@
1
+ WebsocketRails.setup do |config|
2
+
3
+ # Change to :debug for debugging output
4
+ config.log_level = :default
5
+
6
+ # Change to true to enable standalone server mode
7
+ # Start the standalone server with rake websocket_rails:start_server
8
+ # Requires Redis
9
+ config.standalone = false
10
+
11
+ # Change to true to enable channel synchronization between
12
+ # multiple server instances. Requires Redis.
13
+ config.synchronize = false
14
+
15
+ # Uncomment and edit to point to a different redis instance.
16
+ # Will not be used unless standalone or synchronization mode
17
+ # is enabled.
18
+ #config.redis_options = {:host => 'localhost', :port => '6379'}
19
+ end
20
+
1
21
  WebsocketRails::EventMap.describe do
2
22
  # You can use this file to map incoming events to controller actions.
3
23
  # One event can be mapped to any number of controller actions. The
@@ -0,0 +1,38 @@
1
+ namespace :websocket_rails do
2
+ desc 'Test rails task'
3
+ task :start_server do
4
+ require "thin"
5
+ load "#{Rails.root}/config/initializers/events.rb"
6
+
7
+ options = WebsocketRails.thin_options
8
+
9
+ unless WebsocketRails.standalone?
10
+ warn_standalone_not_enabled!
11
+ end
12
+
13
+ fork do
14
+ Thin::Controllers::Controller.new(options).start
15
+ end
16
+
17
+ puts "Websocket Rails Standalone Server listening on port #{options[:port]}"
18
+ end
19
+
20
+ task :stop_server do
21
+ require "thin"
22
+ load "#{Rails.root}/config/initializers/events.rb"
23
+
24
+ options = WebsocketRails.thin_options
25
+
26
+ unless WebsocketRails.standalone?
27
+ warn_standalone_not_enabled!
28
+ end
29
+
30
+ Thin::Controllers::Controller.new(options).stop
31
+ end
32
+ end
33
+
34
+ def warn_standalone_not_enabled!
35
+ puts "Fail!"
36
+ puts "You must enable standalone mode in your events.rb initializer to use the standalone server."
37
+ exit 1
38
+ end
@@ -28,7 +28,7 @@ module WebsocketRails
28
28
  module_function :synchronize, :synchronize=
29
29
 
30
30
  def self.synchronize?
31
- @synchronize == true
31
+ (@synchronize == true) || (@standalone == true)
32
32
  end
33
33
 
34
34
  def self.redis_options
@@ -42,6 +42,44 @@ module WebsocketRails
42
42
  def self.redis_defaults
43
43
  {:host => '127.0.0.1', :port => 6379}
44
44
  end
45
+
46
+ attr_accessor :standalone
47
+ module_function :standalone, :standalone=
48
+
49
+ def self.standalone?
50
+ @standalone == true
51
+ end
52
+
53
+ def self.standalone_port
54
+ @standalone_port ||= '3001'
55
+ end
56
+
57
+ def self.standalone_port=(port)
58
+ @standalone_port = port
59
+ end
60
+
61
+ def self.thin_options
62
+ @thin_options ||= thin_defaults
63
+ end
64
+
65
+ def self.thin_options=(options = {})
66
+ @thin_options = thin_defaults.merge(options)
67
+ end
68
+
69
+ def self.thin_defaults
70
+ {
71
+ :port => standalone_port,
72
+ :pid => "#{Rails.root}/tmp/pids/websocket_rails.pid",
73
+ :log => "#{Rails.root}/log/websocket_rails.log",
74
+ :tag => 'websocket_rails',
75
+ :rackup => "#{Rails.root}/config.ru",
76
+ :threaded => true,
77
+ :daemonize => true,
78
+ :dirname => Rails.root,
79
+ :max_persistent_conns => 1024,
80
+ :max_conns => 1024
81
+ }
82
+ end
45
83
  end
46
84
 
47
85
  require 'websocket_rails/engine'
@@ -8,5 +8,10 @@ module WebsocketRails
8
8
  paths["app/controllers"] << "lib/rails/app/controllers"
9
9
  paths["config/routes"] << "lib/rails/config/routes.rb"
10
10
 
11
+ rake_tasks do
12
+ require 'websocket-rails'
13
+ load 'rails/tasks/websocket_rails.tasks'
14
+ end
15
+
11
16
  end
12
17
  end
@@ -63,8 +63,6 @@ module WebsocketRails
63
63
  remove_server(server_token)
64
64
  end
65
65
 
66
- private
67
-
68
66
  def self.generate_unique_token
69
67
  begin
70
68
  token = SecureRandom.urlsafe_base64
@@ -1,3 +1,3 @@
1
1
  module WebsocketRails
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -578,3 +578,150 @@ Connecting to database specified by database.yml
578
578
  Connecting to database specified by database.yml
579
579
  Connecting to database specified by database.yml
580
580
  Connecting to database specified by database.yml
581
+ Connecting to database specified by database.yml
582
+ Connecting to database specified by database.yml
583
+ Connecting to database specified by database.yml
584
+ Connecting to database specified by database.yml
585
+ Connecting to database specified by database.yml
586
+ Connecting to database specified by database.yml
587
+ Connecting to database specified by database.yml
588
+ Connecting to database specified by database.yml
589
+ Connecting to database specified by database.yml
590
+ Connecting to database specified by database.yml
591
+ Connecting to database specified by database.yml
592
+ Connecting to database specified by database.yml
593
+ Connecting to database specified by database.yml
594
+ Connecting to database specified by database.yml
595
+ Connecting to database specified by database.yml
596
+ Connecting to database specified by database.yml
597
+ Connecting to database specified by database.yml
598
+ Connecting to database specified by database.yml
599
+ Connecting to database specified by database.yml
600
+ Connecting to database specified by database.yml
601
+ Connecting to database specified by database.yml
602
+ Connecting to database specified by database.yml
603
+ Connecting to database specified by database.yml
604
+ Connecting to database specified by database.yml
605
+ Connecting to database specified by database.yml
606
+ Connecting to database specified by database.yml
607
+ Connecting to database specified by database.yml
608
+ Connecting to database specified by database.yml
609
+ Connecting to database specified by database.yml
610
+ Connecting to database specified by database.yml
611
+ Connecting to database specified by database.yml
612
+ Connecting to database specified by database.yml
613
+ Connecting to database specified by database.yml
614
+ Connecting to database specified by database.yml
615
+ Connecting to database specified by database.yml
616
+ Connecting to database specified by database.yml
617
+ Connecting to database specified by database.yml
618
+ Connecting to database specified by database.yml
619
+ Connecting to database specified by database.yml
620
+ Connecting to database specified by database.yml
621
+ Connecting to database specified by database.yml
622
+ Connecting to database specified by database.yml
623
+ Connecting to database specified by database.yml
624
+ Connecting to database specified by database.yml
625
+ Connecting to database specified by database.yml
626
+ Connecting to database specified by database.yml
627
+ Connecting to database specified by database.yml
628
+ Connecting to database specified by database.yml
629
+ Connecting to database specified by database.yml
630
+ Connecting to database specified by database.yml
631
+ Connecting to database specified by database.yml
632
+ Connecting to database specified by database.yml
633
+ Connecting to database specified by database.yml
634
+ Connecting to database specified by database.yml
635
+ Connecting to database specified by database.yml
636
+ Connecting to database specified by database.yml
637
+ Connecting to database specified by database.yml
638
+ Connecting to database specified by database.yml
639
+ Connecting to database specified by database.yml
640
+ Connecting to database specified by database.yml
641
+ Connecting to database specified by database.yml
642
+ Connecting to database specified by database.yml
643
+ Connecting to database specified by database.yml
644
+ Connecting to database specified by database.yml
645
+ Connecting to database specified by database.yml
646
+ Connecting to database specified by database.yml
647
+ Connecting to database specified by database.yml
648
+ Connecting to database specified by database.yml
649
+ Connecting to database specified by database.yml
650
+ Connecting to database specified by database.yml
651
+ Connecting to database specified by database.yml
652
+ Connecting to database specified by database.yml
653
+ Connecting to database specified by database.yml
654
+ Connecting to database specified by database.yml
655
+ Connecting to database specified by database.yml
656
+ Connecting to database specified by database.yml
657
+ Connecting to database specified by database.yml
658
+ Connecting to database specified by database.yml
659
+ Connecting to database specified by database.yml
660
+ Connecting to database specified by database.yml
661
+ Connecting to database specified by database.yml
662
+ Connecting to database specified by database.yml
663
+ Connecting to database specified by database.yml
664
+ Connecting to database specified by database.yml
665
+ Connecting to database specified by database.yml
666
+ Connecting to database specified by database.yml
667
+ Connecting to database specified by database.yml
668
+ Connecting to database specified by database.yml
669
+ Connecting to database specified by database.yml
670
+ Connecting to database specified by database.yml
671
+ Connecting to database specified by database.yml
672
+ Connecting to database specified by database.yml
673
+ Connecting to database specified by database.yml
674
+ Connecting to database specified by database.yml
675
+ Connecting to database specified by database.yml
676
+ Connecting to database specified by database.yml
677
+ Connecting to database specified by database.yml
678
+ Connecting to database specified by database.yml
679
+ Connecting to database specified by database.yml
680
+ Connecting to database specified by database.yml
681
+ Connecting to database specified by database.yml
682
+ Connecting to database specified by database.yml
683
+ Connecting to database specified by database.yml
684
+ Connecting to database specified by database.yml
685
+ Connecting to database specified by database.yml
686
+ Connecting to database specified by database.yml
687
+ Connecting to database specified by database.yml
688
+ Connecting to database specified by database.yml
689
+ Connecting to database specified by database.yml
690
+ Connecting to database specified by database.yml
691
+ Connecting to database specified by database.yml
692
+ Connecting to database specified by database.yml
693
+ Connecting to database specified by database.yml
694
+ Connecting to database specified by database.yml
695
+ Connecting to database specified by database.yml
696
+ Connecting to database specified by database.yml
697
+ Connecting to database specified by database.yml
698
+ Connecting to database specified by database.yml
699
+ Connecting to database specified by database.yml
700
+ Connecting to database specified by database.yml
701
+ Connecting to database specified by database.yml
702
+ Connecting to database specified by database.yml
703
+ Connecting to database specified by database.yml
704
+ Connecting to database specified by database.yml
705
+ Connecting to database specified by database.yml
706
+ Connecting to database specified by database.yml
707
+ Connecting to database specified by database.yml
708
+ Connecting to database specified by database.yml
709
+ Connecting to database specified by database.yml
710
+ Connecting to database specified by database.yml
711
+ Connecting to database specified by database.yml
712
+ Connecting to database specified by database.yml
713
+ Connecting to database specified by database.yml
714
+ Connecting to database specified by database.yml
715
+ Connecting to database specified by database.yml
716
+ Connecting to database specified by database.yml
717
+ Connecting to database specified by database.yml
718
+ Connecting to database specified by database.yml
719
+ Connecting to database specified by database.yml
720
+ Connecting to database specified by database.yml
721
+ Connecting to database specified by database.yml
722
+ Connecting to database specified by database.yml
723
+ Connecting to database specified by database.yml
724
+ Connecting to database specified by database.yml
725
+ Connecting to database specified by database.yml
726
+ Connecting to database specified by database.yml
727
+ Connecting to database specified by database.yml
@@ -31,6 +31,16 @@ module WebsocketRails
31
31
  end
32
32
  end
33
33
 
34
+ around do |example|
35
+ EM.run do
36
+ example.run
37
+ end
38
+ end
39
+
40
+ after do
41
+ EM.stop
42
+ end
43
+
34
44
  shared_examples "an evented rack server" do
35
45
  context "new connections" do
36
46
  it "should execute the controller action associated with the 'client_connected' event" do
@@ -68,10 +78,10 @@ module WebsocketRails
68
78
  let(:encoded_channel_message) { channel_message.to_json }
69
79
 
70
80
  it "should subscribe the connection to the correct channel" do
71
- #channel = WebsocketRails[:test_chan]
72
- #@server.call( env )
73
- #channel.should_receive(:subscribe).with(socket)
74
- #socket.on_message encoded_channel_message
81
+ channel = WebsocketRails[:test_chan]
82
+ @server.call( env )
83
+ channel.should_receive(:subscribe).with(socket)
84
+ socket.on_message encoded_channel_message
75
85
  end
76
86
  end
77
87
 
data/spec/spec_helper.rb CHANGED
@@ -24,21 +24,14 @@ RSpec.configure do |config|
24
24
  # config.mock_with :flexmock
25
25
  # config.mock_with :rr
26
26
  config.mock_with :rspec
27
-
27
+
28
28
  config.include WebsocketRails::HelperMethods
29
29
 
30
30
  # If true, the base class of anonymous controllers will be inferred
31
31
  # automatically. This will be the default behavior in future versions of
32
32
  # rspec-rails.
33
33
  config.infer_base_class_for_anonymous_controllers = false
34
-
35
- config.before(:all) do
36
- silence_output
37
- end
38
-
39
- config.after(:all) do
40
- enable_output
41
- end
34
+
42
35
  end
43
36
 
44
37
  def silence_output
@@ -58,7 +58,7 @@ module WebsocketRails
58
58
  end
59
59
 
60
60
  describe "#remove_server" do
61
- it "should add the unique token to the active_servers key in redis" do
61
+ it "should remove the unique token from the active_servers key in redis" do
62
62
  Redis.any_instance.should_receive(:srem).with("websocket_rails.active_servers", "token")
63
63
  subject.remove_server "token"
64
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-20 00:00:00.000000000 Z
14
+ date: 2012-11-26 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -171,10 +171,12 @@ files:
171
171
  - lib/assets/javascripts/websocket_rails/main.js
172
172
  - lib/assets/javascripts/websocket_rails/websocket_connection.js.coffee
173
173
  - lib/assets/javascripts/websocket_rails/websocket_rails.js.coffee
174
+ - lib/config.ru
174
175
  - lib/generators/websocket_rails/install/install_generator.rb
175
176
  - lib/generators/websocket_rails/install/templates/events.rb
176
177
  - lib/rails/app/controllers/websocket_rails/delegation_controller.rb
177
178
  - lib/rails/config/routes.rb
179
+ - lib/rails/tasks/websocket_rails.tasks
178
180
  - lib/websocket-rails.rb
179
181
  - lib/websocket_rails/base_controller.rb
180
182
  - lib/websocket_rails/channel.rb
@@ -283,7 +285,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
283
285
  version: '0'
284
286
  segments:
285
287
  - 0
286
- hash: -4523362608196587549
288
+ hash: -1199514115316704579
287
289
  required_rubygems_version: !ruby/object:Gem::Requirement
288
290
  none: false
289
291
  requirements:
@@ -292,10 +294,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
294
  version: '0'
293
295
  segments:
294
296
  - 0
295
- hash: -4523362608196587549
297
+ hash: -1199514115316704579
296
298
  requirements: []
297
299
  rubyforge_project: websocket-rails
298
- rubygems_version: 1.8.24
300
+ rubygems_version: 1.8.19
299
301
  signing_key:
300
302
  specification_version: 3
301
303
  summary: Plug and play websocket support for ruby on rails. Includes event router