websocket-rails 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/.gitignore +4 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +3 -0
  4. data/Gemfile +6 -1
  5. data/Gemfile.lock +28 -12
  6. data/MIT-LICENSE +1 -1
  7. data/README.md +122 -14
  8. data/Rakefile +18 -10
  9. data/bin/thin-socketrails +30 -0
  10. data/lib/websocket-rails.rb +11 -2
  11. data/lib/websocket_rails/base_controller.rb +91 -10
  12. data/lib/websocket_rails/connection_manager.rb +57 -27
  13. data/lib/websocket_rails/data_store.rb +34 -4
  14. data/lib/websocket_rails/dispatcher.rb +25 -46
  15. data/lib/websocket_rails/events.rb +53 -0
  16. data/lib/websocket_rails/version.rb +1 -1
  17. data/{test → spec}/dummy/Rakefile +0 -0
  18. data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
  19. data/spec/dummy/app/controllers/chat_controller.rb +57 -0
  20. data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
  21. data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
  22. data/{test → spec}/dummy/config.ru +0 -0
  23. data/{test → spec}/dummy/config/application.rb +1 -1
  24. data/{test → spec}/dummy/config/boot.rb +0 -0
  25. data/{test → spec}/dummy/config/database.yml +0 -0
  26. data/{test → spec}/dummy/config/environment.rb +0 -0
  27. data/{test → spec}/dummy/config/environments/development.rb +0 -0
  28. data/{test → spec}/dummy/config/environments/production.rb +0 -0
  29. data/{test → spec}/dummy/config/environments/test.rb +0 -0
  30. data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
  31. data/spec/dummy/config/initializers/events.rb +7 -0
  32. data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
  33. data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
  34. data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
  35. data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
  36. data/{test → spec}/dummy/config/locales/en.yml +0 -0
  37. data/{test → spec}/dummy/config/routes.rb +0 -0
  38. data/{test/dummy/public/favicon.ico → spec/dummy/db/test.sqlite3} +0 -0
  39. data/{test/dummy/public/stylesheets/.gitkeep → spec/dummy/log/development.log} +0 -0
  40. data/spec/dummy/log/production.log +0 -0
  41. data/spec/dummy/log/server.log +0 -0
  42. data/spec/dummy/log/test.log +0 -0
  43. data/{test → spec}/dummy/public/404.html +0 -0
  44. data/{test → spec}/dummy/public/422.html +0 -0
  45. data/{test → spec}/dummy/public/500.html +0 -0
  46. data/spec/dummy/public/favicon.ico +0 -0
  47. data/{test → spec}/dummy/public/javascripts/application.js +0 -0
  48. data/{test → spec}/dummy/public/javascripts/controls.js +0 -0
  49. data/{test → spec}/dummy/public/javascripts/dragdrop.js +0 -0
  50. data/{test → spec}/dummy/public/javascripts/effects.js +0 -0
  51. data/{test → spec}/dummy/public/javascripts/prototype.js +0 -0
  52. data/{test → spec}/dummy/public/javascripts/rails.js +0 -0
  53. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  54. data/{test → spec}/dummy/script/rails +0 -0
  55. data/spec/spec_helper.rb +60 -0
  56. data/spec/support/mock_web_socket.rb +27 -0
  57. data/spec/unit/connection_manager_spec.rb +111 -0
  58. data/spec/unit/data_store_spec.rb +15 -0
  59. data/spec/unit/dispatcher_spec.rb +57 -0
  60. data/spec/unit/events_spec.rb +70 -0
  61. data/websocket-rails.gemspec +2 -2
  62. metadata +65 -53
  63. data/lib/websocket_rails/extensions/common.rb +0 -11
  64. data/lib/websocket_rails/extensions/websocket_rack.rb +0 -55
  65. data/test/integration/navigation_test.rb +0 -7
  66. data/test/support/integration_case.rb +0 -5
  67. data/test/test_helper.rb +0 -22
  68. data/test/websocket_rails_test.rb +0 -7
@@ -1,11 +0,0 @@
1
- require 'websocket_rails/extensions/websocket_rack'
2
- module WebsocketRails
3
- module Extensions
4
- module Common
5
- def self.apply!
6
- Rack::WebSocket::Handler::Thin.send(:include,RackWebsocketExtensions)
7
- end
8
- end
9
- end
10
- end
11
-
@@ -1,55 +0,0 @@
1
- module WebsocketRails
2
- module Extensions
3
- module RackWebsocketExtensions
4
- def self.included(base)
5
- base.class_eval do
6
- alias :call_legacy :call
7
- alias :call :new_call
8
-
9
- alias :send_data_legacy :send_data
10
- alias :send_data :new_send_data
11
-
12
- alias :close_websocket_legacy :close_websocket
13
- alias :close_websocket :new_close_websocket
14
- end
15
- end
16
- # Build request from Rack env
17
- @@connection_pool = {}
18
- def new_call(env)
19
- env['websocket.client_id'] ||= rand(100000)
20
- @env = env
21
- socket = env['async.connection']
22
- request = request_from_env(env)
23
- @connection = Rack::WebSocket::Handler::Base::Connection.new(self, socket, :debug => @options[:debug])
24
- @@connection_pool[env['websocket.client_id']] = @connection
25
- puts "We have #{@@connection_pool.count} open connection(s)\n"
26
- @@connection_pool[env['websocket.client_id']].dispatch(request) ? async_response : failure_response
27
- end
28
-
29
- # Forward send_data to server
30
- def new_send_data(data,uid)
31
- if @@connection_pool[uid]
32
- @@connection_pool[uid].send( data )
33
- end
34
- end
35
-
36
- # Forward send_data to server
37
- def send_data_all(data)
38
- if @@connection_pool
39
- @@connection_pool.each do |k,connection|
40
- connection.send( data )
41
- end
42
- end
43
- end
44
-
45
- # Forward close_websocket to server
46
- def new_close_websocket
47
- close_connection(env['websocket.client_id'])
48
- end
49
-
50
- def close_connection(uid)
51
- @@connection_pool.delete_if {|k,v| k == uid}
52
- end
53
- end
54
- end
55
- end
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class NavigationTest < ActiveSupport::IntegrationCase
4
- test "truth" do
5
- assert_kind_of Dummy::Application, Rails.application
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- # Define a bare test case to use with Capybara
2
- class ActiveSupport::IntegrationCase < ActiveSupport::TestCase
3
- include Capybara
4
- include Rails.application.routes.url_helpers
5
- end
data/test/test_helper.rb DELETED
@@ -1,22 +0,0 @@
1
- # Configure Rails Envinronment
2
- ENV["RAILS_ENV"] = "test"
3
-
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
- require "rails/test_help"
6
-
7
- ActionMailer::Base.delivery_method = :test
8
- ActionMailer::Base.perform_deliveries = true
9
- ActionMailer::Base.default_url_options[:host] = "test.com"
10
-
11
- Rails.backtrace_cleaner.remove_silencers!
12
-
13
- # Configure capybara for integration testing
14
- require "capybara/rails"
15
- Capybara.default_driver = :rack_test
16
- Capybara.default_selector = :css
17
-
18
- # Run any available migration
19
- ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
20
-
21
- # Load support files
22
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
@@ -1,7 +0,0 @@
1
- require 'test_helper'
2
-
3
- class Websocket-railsTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, Websocket-rails
6
- end
7
- end