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.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +6 -1
- data/Gemfile.lock +28 -12
- data/MIT-LICENSE +1 -1
- data/README.md +122 -14
- data/Rakefile +18 -10
- data/bin/thin-socketrails +30 -0
- data/lib/websocket-rails.rb +11 -2
- data/lib/websocket_rails/base_controller.rb +91 -10
- data/lib/websocket_rails/connection_manager.rb +57 -27
- data/lib/websocket_rails/data_store.rb +34 -4
- data/lib/websocket_rails/dispatcher.rb +25 -46
- data/lib/websocket_rails/events.rb +53 -0
- data/lib/websocket_rails/version.rb +1 -1
- data/{test → spec}/dummy/Rakefile +0 -0
- data/{test → spec}/dummy/app/controllers/application_controller.rb +0 -0
- data/spec/dummy/app/controllers/chat_controller.rb +57 -0
- data/{test → spec}/dummy/app/helpers/application_helper.rb +0 -0
- data/{test → spec}/dummy/app/views/layouts/application.html.erb +0 -0
- data/{test → spec}/dummy/config.ru +0 -0
- data/{test → spec}/dummy/config/application.rb +1 -1
- data/{test → spec}/dummy/config/boot.rb +0 -0
- data/{test → spec}/dummy/config/database.yml +0 -0
- data/{test → spec}/dummy/config/environment.rb +0 -0
- data/{test → spec}/dummy/config/environments/development.rb +0 -0
- data/{test → spec}/dummy/config/environments/production.rb +0 -0
- data/{test → spec}/dummy/config/environments/test.rb +0 -0
- data/{test → spec}/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/dummy/config/initializers/events.rb +7 -0
- data/{test → spec}/dummy/config/initializers/inflections.rb +0 -0
- data/{test → spec}/dummy/config/initializers/mime_types.rb +0 -0
- data/{test → spec}/dummy/config/initializers/secret_token.rb +0 -0
- data/{test → spec}/dummy/config/initializers/session_store.rb +0 -0
- data/{test → spec}/dummy/config/locales/en.yml +0 -0
- data/{test → spec}/dummy/config/routes.rb +0 -0
- data/{test/dummy/public/favicon.ico → spec/dummy/db/test.sqlite3} +0 -0
- data/{test/dummy/public/stylesheets/.gitkeep → spec/dummy/log/development.log} +0 -0
- data/spec/dummy/log/production.log +0 -0
- data/spec/dummy/log/server.log +0 -0
- data/spec/dummy/log/test.log +0 -0
- data/{test → spec}/dummy/public/404.html +0 -0
- data/{test → spec}/dummy/public/422.html +0 -0
- data/{test → spec}/dummy/public/500.html +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/{test → spec}/dummy/public/javascripts/application.js +0 -0
- data/{test → spec}/dummy/public/javascripts/controls.js +0 -0
- data/{test → spec}/dummy/public/javascripts/dragdrop.js +0 -0
- data/{test → spec}/dummy/public/javascripts/effects.js +0 -0
- data/{test → spec}/dummy/public/javascripts/prototype.js +0 -0
- data/{test → spec}/dummy/public/javascripts/rails.js +0 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/{test → spec}/dummy/script/rails +0 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/support/mock_web_socket.rb +27 -0
- data/spec/unit/connection_manager_spec.rb +111 -0
- data/spec/unit/data_store_spec.rb +15 -0
- data/spec/unit/dispatcher_spec.rb +57 -0
- data/spec/unit/events_spec.rb +70 -0
- data/websocket-rails.gemspec +2 -2
- metadata +65 -53
- data/lib/websocket_rails/extensions/common.rb +0 -11
- data/lib/websocket_rails/extensions/websocket_rack.rb +0 -55
- data/test/integration/navigation_test.rb +0 -7
- data/test/support/integration_case.rb +0 -5
- data/test/test_helper.rb +0 -22
- data/test/websocket_rails_test.rb +0 -7
@@ -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
|
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 }
|