hkroger-websocket-rails 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +328 -0
- data/Gemfile +27 -0
- data/MIT-LICENSE +20 -0
- data/README.md +237 -0
- data/Rakefile +72 -0
- data/bin/thin-socketrails +45 -0
- data/lib/assets/javascripts/websocket_rails/abstract_connection.js.coffee +45 -0
- data/lib/assets/javascripts/websocket_rails/channel.js.coffee +70 -0
- data/lib/assets/javascripts/websocket_rails/event.js.coffee +42 -0
- data/lib/assets/javascripts/websocket_rails/http_connection.js.coffee +66 -0
- data/lib/assets/javascripts/websocket_rails/main.js +6 -0
- data/lib/assets/javascripts/websocket_rails/websocket_connection.js.coffee +29 -0
- data/lib/assets/javascripts/websocket_rails/websocket_rails.js.coffee +158 -0
- data/lib/config.ru +3 -0
- data/lib/generators/websocket_rails/install/install_generator.rb +33 -0
- data/lib/generators/websocket_rails/install/templates/events.rb +14 -0
- data/lib/generators/websocket_rails/install/templates/websocket_rails.rb +63 -0
- data/lib/hkroger-websocket-rails.rb +1 -0
- data/lib/rails/app/controllers/websocket_rails/delegation_controller.rb +13 -0
- data/lib/rails/config/routes.rb +7 -0
- data/lib/rails/tasks/websocket_rails.tasks +42 -0
- data/lib/spec_helpers/matchers/route_matchers.rb +65 -0
- data/lib/spec_helpers/matchers/trigger_matchers.rb +113 -0
- data/lib/spec_helpers/spec_helper_event.rb +34 -0
- data/lib/websocket-rails.rb +108 -0
- data/lib/websocket_rails/base_controller.rb +197 -0
- data/lib/websocket_rails/channel.rb +97 -0
- data/lib/websocket_rails/channel_manager.rb +55 -0
- data/lib/websocket_rails/configuration.rb +169 -0
- data/lib/websocket_rails/connection_adapters.rb +195 -0
- data/lib/websocket_rails/connection_adapters/http.rb +120 -0
- data/lib/websocket_rails/connection_adapters/web_socket.rb +36 -0
- data/lib/websocket_rails/connection_manager.rb +119 -0
- data/lib/websocket_rails/controller_factory.rb +80 -0
- data/lib/websocket_rails/data_store.rb +145 -0
- data/lib/websocket_rails/dispatcher.rb +129 -0
- data/lib/websocket_rails/engine.rb +26 -0
- data/lib/websocket_rails/event.rb +189 -0
- data/lib/websocket_rails/event_map.rb +184 -0
- data/lib/websocket_rails/event_queue.rb +33 -0
- data/lib/websocket_rails/internal_events.rb +37 -0
- data/lib/websocket_rails/logging.rb +133 -0
- data/lib/websocket_rails/spec_helpers.rb +3 -0
- data/lib/websocket_rails/synchronization.rb +182 -0
- data/lib/websocket_rails/user_manager.rb +276 -0
- data/lib/websocket_rails/version.rb +3 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/chat_controller.rb +53 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +34 -0
- data/spec/dummy/config/events.rb +7 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20130902222552_create_users.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +17 -0
- data/spec/dummy/log/production.log +0 -0
- data/spec/dummy/log/server.log +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +202 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/integration/connection_manager_spec.rb +135 -0
- data/spec/javascripts/support/jasmine.yml +52 -0
- data/spec/javascripts/support/jasmine_helper.rb +38 -0
- data/spec/javascripts/support/vendor/sinon-1.7.1.js +4343 -0
- data/spec/javascripts/websocket_rails/channel_spec.coffee +112 -0
- data/spec/javascripts/websocket_rails/event_spec.coffee +69 -0
- data/spec/javascripts/websocket_rails/helpers.coffee +6 -0
- data/spec/javascripts/websocket_rails/websocket_connection_spec.coffee +158 -0
- data/spec/javascripts/websocket_rails/websocket_rails_spec.coffee +274 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/spec_helpers/matchers/route_matchers_spec.rb +109 -0
- data/spec/spec_helpers/matchers/trigger_matchers_spec.rb +247 -0
- data/spec/spec_helpers/spec_helper_event_spec.rb +66 -0
- data/spec/support/helper_methods.rb +42 -0
- data/spec/support/mock_web_socket.rb +41 -0
- data/spec/unit/base_controller_spec.rb +74 -0
- data/spec/unit/channel_manager_spec.rb +58 -0
- data/spec/unit/channel_spec.rb +169 -0
- data/spec/unit/connection_adapters/http_spec.rb +88 -0
- data/spec/unit/connection_adapters/web_socket_spec.rb +30 -0
- data/spec/unit/connection_adapters_spec.rb +259 -0
- data/spec/unit/connection_manager_spec.rb +148 -0
- data/spec/unit/controller_factory_spec.rb +76 -0
- data/spec/unit/data_store_spec.rb +106 -0
- data/spec/unit/dispatcher_spec.rb +203 -0
- data/spec/unit/event_map_spec.rb +120 -0
- data/spec/unit/event_queue_spec.rb +36 -0
- data/spec/unit/event_spec.rb +181 -0
- data/spec/unit/logging_spec.rb +162 -0
- data/spec/unit/synchronization_spec.rb +150 -0
- data/spec/unit/target_validator_spec.rb +88 -0
- data/spec/unit/user_manager_spec.rb +165 -0
- metadata +320 -0
data/lib/config.ru
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module WebsocketRails
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
desc "Create the events.rb initializer and require the JS client in the application.js manifest."
|
9
|
+
|
10
|
+
class_option :manifest, :type => :string, :aliases => "-m", :default => 'application.js',
|
11
|
+
:desc => "Javascript manifest file to modify (or create)"
|
12
|
+
|
13
|
+
def create_events_initializer_file
|
14
|
+
template 'events.rb', File.join('config', 'events.rb')
|
15
|
+
template 'websocket_rails.rb', File.join('config', 'initializers', 'websocket_rails.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
def inject_websocket_rails_client
|
19
|
+
manifest = options[:manifest]
|
20
|
+
js_path = "app/assets/javascripts"
|
21
|
+
|
22
|
+
create_file("#{js_path}/#{manifest}") unless File.exists?("#{js_path}/#{manifest}")
|
23
|
+
|
24
|
+
append_to_file "#{js_path}/#{manifest}" do
|
25
|
+
out = ""
|
26
|
+
out << "//= require websocket_rails/main"
|
27
|
+
out << "\n"
|
28
|
+
out << "\n"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
WebsocketRails::EventMap.describe do
|
2
|
+
# You can use this file to map incoming events to controller actions.
|
3
|
+
# One event can be mapped to any number of controller actions. The
|
4
|
+
# actions will be executed in the order they were subscribed.
|
5
|
+
#
|
6
|
+
# Uncomment and edit the next line to handle the client connected event:
|
7
|
+
# subscribe :client_connected, :to => Controller, :with_method => :method_name
|
8
|
+
#
|
9
|
+
# Here is an example of mapping namespaced events:
|
10
|
+
# namespace :product do
|
11
|
+
# subscribe :new, :to => ProductController, :with_method => :new_product
|
12
|
+
# end
|
13
|
+
# The above will handle an event triggered on the client like `product.new`.
|
14
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
WebsocketRails.setup do |config|
|
2
|
+
|
3
|
+
# Uncomment to override the default log level. The log level can be
|
4
|
+
# any of the standard Logger log levels. By default it will mirror the
|
5
|
+
# current Rails environment log level.
|
6
|
+
# config.log_level = :debug
|
7
|
+
|
8
|
+
# Uncomment to change the default log file path.
|
9
|
+
# config.log_path = "#{Rails.root}/log/websocket_rails.log"
|
10
|
+
|
11
|
+
# Set to true if you wish to log the internal websocket_rails events
|
12
|
+
# such as the keepalive `websocket_rails.ping` event.
|
13
|
+
# config.log_internal_events = false
|
14
|
+
|
15
|
+
# Change to true to enable standalone server mode
|
16
|
+
# Start the standalone server with rake websocket_rails:start_server
|
17
|
+
# * Requires Redis
|
18
|
+
config.standalone = false
|
19
|
+
|
20
|
+
# Change to true to enable channel synchronization between
|
21
|
+
# multiple server instances.
|
22
|
+
# * Requires Redis.
|
23
|
+
config.synchronize = false
|
24
|
+
|
25
|
+
# Prevent Thin from daemonizing (default is true)
|
26
|
+
# config.daemonize = false
|
27
|
+
|
28
|
+
# Uncomment and edit to point to a different redis instance.
|
29
|
+
# Will not be used unless standalone or synchronization mode
|
30
|
+
# is enabled.
|
31
|
+
# config.redis_options = {:host => 'localhost', :port => '6379'}
|
32
|
+
|
33
|
+
# By default, all subscribers in to a channel will be removed
|
34
|
+
# when that channel is made private. If you don't wish active
|
35
|
+
# subscribers to be removed from a previously public channel
|
36
|
+
# when making it private, set the following to true.
|
37
|
+
# config.keep_subscribers_when_private = false
|
38
|
+
|
39
|
+
# Set to true if you wish to broadcast channel subscriber_join and
|
40
|
+
# subscriber_part events. All subscribers of a channel will be
|
41
|
+
# notified when other clients join and part the channel. If you are
|
42
|
+
# using the UserManager, the current_user object will be sent along
|
43
|
+
# with the event.
|
44
|
+
# config.broadcast_subscriber_events = true
|
45
|
+
|
46
|
+
# Used as the key for the WebsocketRails.users Hash. This method
|
47
|
+
# will be called on the `current_user` object in your controller
|
48
|
+
# if one exists. If `current_user` does not exist or does not
|
49
|
+
# respond to the identifier, the key will default to `connection.id`
|
50
|
+
# config.user_identifier = :id
|
51
|
+
|
52
|
+
# Uncomment and change this option to override the class associated
|
53
|
+
# with your `current_user` object. This class will be used when
|
54
|
+
# synchronization is enabled and you trigger events from background
|
55
|
+
# jobs using the WebsocketRails.users UserManager.
|
56
|
+
# config.user_class = User
|
57
|
+
|
58
|
+
# Supporting HTTP streaming on Internet Explorer versions 8 & 9
|
59
|
+
# requires CORS to be enabled for GET "/websocket" request.
|
60
|
+
# List here the origin domains allowed to perform the request.
|
61
|
+
# config.allowed_origins = ['http://localhost:3000']
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "websocket-rails"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module WebsocketRails
|
2
|
+
# This class provides a means for accessing the Rails
|
3
|
+
# controller helper methods defined in a user's application
|
4
|
+
# or in gems that the user has added to the project.
|
5
|
+
#
|
6
|
+
# Each active connection creates and stores it's own
|
7
|
+
# instance with the correct @_request and @_env objects
|
8
|
+
# set. WebsocketRails::BaseController sends missing
|
9
|
+
# methods to the active connection's delegation controller
|
10
|
+
# instance.
|
11
|
+
class DelegationController < ApplicationController
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
namespace :websocket_rails do
|
2
|
+
desc 'Start the WebsocketRails standalone server.'
|
3
|
+
task :start_server do
|
4
|
+
require "thin"
|
5
|
+
load "#{Rails.root}/config/initializers/websocket_rails.rb"
|
6
|
+
load "#{Rails.root}/config/events.rb"
|
7
|
+
|
8
|
+
options = WebsocketRails.config.thin_options
|
9
|
+
|
10
|
+
warn_if_standalone_not_enabled!
|
11
|
+
|
12
|
+
if options[:daemonize]
|
13
|
+
fork do
|
14
|
+
Thin::Controllers::Controller.new(options).start
|
15
|
+
end
|
16
|
+
else
|
17
|
+
Thin::Controllers::Controller.new(options).start
|
18
|
+
end
|
19
|
+
|
20
|
+
puts "Websocket Rails Standalone Server listening on port #{options[:port]}"
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Stop the WebsocketRails standalone server.'
|
24
|
+
task :stop_server do
|
25
|
+
require "thin"
|
26
|
+
load "#{Rails.root}/config/initializers/websocket_rails.rb"
|
27
|
+
load "#{Rails.root}/config/events.rb"
|
28
|
+
|
29
|
+
options = WebsocketRails.config.thin_options
|
30
|
+
|
31
|
+
warn_if_standalone_not_enabled!
|
32
|
+
|
33
|
+
Thin::Controllers::Controller.new(options).stop
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def warn_if_standalone_not_enabled!
|
38
|
+
return if WebsocketRails.standalone?
|
39
|
+
puts "Fail!"
|
40
|
+
puts "You must enable standalone mode in your websocket_rails.rb initializer to use the standalone server."
|
41
|
+
exit 1
|
42
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module WebsocketRails
|
2
|
+
|
3
|
+
module SpecHelpers
|
4
|
+
|
5
|
+
def self.verify_route(event, target, non_exclusive)
|
6
|
+
|
7
|
+
raise ArgumentError, 'event must be of type SpecHelperEvent' unless event.is_a? WebsocketRails::SpecHelperEvent
|
8
|
+
target_class, target_method = WebsocketRails::TargetValidator.validate_target target
|
9
|
+
|
10
|
+
result = false
|
11
|
+
no_of_routes = 0
|
12
|
+
event.dispatcher.event_map.routes_for event do |controller_class, method|
|
13
|
+
no_of_routes += 1
|
14
|
+
controller = controller_class.new
|
15
|
+
if controller.class == target_class and method == target_method
|
16
|
+
result = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
result and (non_exclusive or no_of_routes == 1)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
RSpec::Matchers.define :be_routed_to do |target|
|
28
|
+
|
29
|
+
match do |event|
|
30
|
+
WebsocketRails::SpecHelpers.verify_route event, target, true
|
31
|
+
end
|
32
|
+
|
33
|
+
failure_message_for_should do |event|
|
34
|
+
"expected event #{event.name} to be routed to target #{target}"
|
35
|
+
end
|
36
|
+
|
37
|
+
failure_message_for_should_not do |event|
|
38
|
+
"expected event #{event.name} not to be routed to target #{target}"
|
39
|
+
end
|
40
|
+
|
41
|
+
description do
|
42
|
+
"be routed to target #{target}"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
RSpec::Matchers.define :be_routed_only_to do |target|
|
48
|
+
|
49
|
+
match do |event|
|
50
|
+
WebsocketRails::SpecHelpers.verify_route event, target, false
|
51
|
+
end
|
52
|
+
|
53
|
+
failure_message_for_should do |event|
|
54
|
+
"expected event #{event.name} to be routed only to target #{target}"
|
55
|
+
end
|
56
|
+
|
57
|
+
failure_message_for_should_not do |event|
|
58
|
+
"expected event #{event.name} not to be routed only to target #{target}"
|
59
|
+
end
|
60
|
+
|
61
|
+
description do
|
62
|
+
"be routed only to target #{target}"
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module WebsocketRails
|
2
|
+
|
3
|
+
module SpecHelpers
|
4
|
+
|
5
|
+
def self.compare_trigger_data(event, data)
|
6
|
+
return true if data.nil?
|
7
|
+
return true if data == :any and event.data
|
8
|
+
return true if data == :nil and event.data.nil?
|
9
|
+
data.eql? event.data
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.expected_data_for_spec_message(data)
|
13
|
+
case data
|
14
|
+
when nil
|
15
|
+
''
|
16
|
+
when :nil
|
17
|
+
' with no data'
|
18
|
+
when :any
|
19
|
+
' with some data'
|
20
|
+
else
|
21
|
+
" with data #{data}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.actual_data_for_spec_message(data)
|
26
|
+
data ? "with data #{data}": 'with no data'
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.actual_for_spec_message(event, success)
|
30
|
+
if event.triggered?
|
31
|
+
if success.nil?
|
32
|
+
"triggered message #{actual_data_for_spec_message(event.data)}"
|
33
|
+
else
|
34
|
+
"triggered #{event.success ? 'a success' : 'a failure' } message #{actual_data_for_spec_message(event.data)}"
|
35
|
+
end
|
36
|
+
else
|
37
|
+
'did not trigger any message'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.verify_trigger(event, data, success)
|
42
|
+
return false unless event.triggered?
|
43
|
+
return false unless compare_trigger_data(event, data)
|
44
|
+
success.nil? || success == event.success
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
RSpec::Matchers.define :trigger_message do |data|
|
53
|
+
|
54
|
+
match do |event|
|
55
|
+
WebsocketRails::SpecHelpers.verify_trigger event, data, nil
|
56
|
+
end
|
57
|
+
|
58
|
+
failure_message_for_should do |event|
|
59
|
+
"expected #{event.encoded_name} to trigger message#{WebsocketRails::SpecHelpers.expected_data_for_spec_message data}, " +
|
60
|
+
"instead it #{WebsocketRails::SpecHelpers.actual_for_spec_message event, nil}"
|
61
|
+
end
|
62
|
+
|
63
|
+
failure_message_for_should_not do |event|
|
64
|
+
"expected #{event.encoded_name} not to trigger message#{WebsocketRails::SpecHelpers.expected_data_for_spec_message data}"
|
65
|
+
end
|
66
|
+
|
67
|
+
description do
|
68
|
+
"trigger message#{WebsocketRails::SpecHelpers.expected_data_for_spec_message data}"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
RSpec::Matchers.define :trigger_success_message do |data|
|
74
|
+
|
75
|
+
match do |event|
|
76
|
+
WebsocketRails::SpecHelpers.verify_trigger event, data, true
|
77
|
+
end
|
78
|
+
|
79
|
+
failure_message_for_should do |event|
|
80
|
+
"expected #{event.encoded_name} to trigger success message#{WebsocketRails::SpecHelpers.expected_data_for_spec_message data}, "+
|
81
|
+
"instead it #{WebsocketRails::SpecHelpers.actual_for_spec_message event, true}"
|
82
|
+
end
|
83
|
+
|
84
|
+
failure_message_for_should_not do |event|
|
85
|
+
"expected #{event.encoded_name} not to trigger success message#{WebsocketRails::SpecHelpers.expected_data_for_spec_message data}"
|
86
|
+
end
|
87
|
+
|
88
|
+
description do
|
89
|
+
"trigger success message#{WebsocketRails::SpecHelpers.expected_data_for_spec_message data}"
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
RSpec::Matchers.define :trigger_failure_message do |data|
|
95
|
+
|
96
|
+
match do |event|
|
97
|
+
WebsocketRails::SpecHelpers.verify_trigger event, data, false
|
98
|
+
end
|
99
|
+
|
100
|
+
failure_message_for_should do |event|
|
101
|
+
"expected #{event.encoded_name} to trigger failure message#{WebsocketRails::SpecHelpers.expected_data_for_spec_message data}, " +
|
102
|
+
"instead it #{WebsocketRails::SpecHelpers.actual_for_spec_message event, true}"
|
103
|
+
end
|
104
|
+
|
105
|
+
failure_message_for_should_not do |event|
|
106
|
+
"expected #{event.encoded_name} not to trigger failure message#{WebsocketRails::SpecHelpers.expected_data_for_spec_message data}"
|
107
|
+
end
|
108
|
+
|
109
|
+
description do
|
110
|
+
"trigger failure message#{WebsocketRails::SpecHelpers.expected_data_for_spec_message data}"
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module WebsocketRails
|
2
|
+
|
3
|
+
class SpecHelperEvent < Event
|
4
|
+
|
5
|
+
attr_reader :dispatcher, :triggered
|
6
|
+
|
7
|
+
alias :triggered? :triggered
|
8
|
+
|
9
|
+
def initialize(event_name,options={})
|
10
|
+
super(event_name, options)
|
11
|
+
@triggered = false
|
12
|
+
@dispatcher = Dispatcher.new(nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
def trigger
|
16
|
+
@triggered = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def dispatch
|
20
|
+
@dispatcher.dispatch(self)
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def connection
|
25
|
+
OpenStruct.new(:id => 1)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_event(name, data)
|
33
|
+
WebsocketRails::SpecHelperEvent.new(name, {data: data})
|
34
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require "active_support/dependencies"
|
2
|
+
require "logger"
|
3
|
+
require "thin"
|
4
|
+
|
5
|
+
module WebsocketRails
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def setup
|
9
|
+
yield config
|
10
|
+
end
|
11
|
+
|
12
|
+
def config
|
13
|
+
@config ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def synchronize?
|
17
|
+
config.synchronize == true || config.standalone == true
|
18
|
+
end
|
19
|
+
|
20
|
+
def standalone?
|
21
|
+
config.standalone == true
|
22
|
+
end
|
23
|
+
|
24
|
+
def logger
|
25
|
+
config.logger
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
require 'websocket_rails/engine'
|
32
|
+
|
33
|
+
require 'websocket_rails/configuration'
|
34
|
+
require 'websocket_rails/logging'
|
35
|
+
require 'websocket_rails/synchronization'
|
36
|
+
require 'websocket_rails/connection_manager'
|
37
|
+
require 'websocket_rails/dispatcher'
|
38
|
+
require 'websocket_rails/controller_factory'
|
39
|
+
require 'websocket_rails/event'
|
40
|
+
require 'websocket_rails/event_map'
|
41
|
+
require 'websocket_rails/event_queue'
|
42
|
+
require 'websocket_rails/channel'
|
43
|
+
require 'websocket_rails/channel_manager'
|
44
|
+
require 'websocket_rails/user_manager'
|
45
|
+
require 'websocket_rails/base_controller'
|
46
|
+
require 'websocket_rails/internal_events'
|
47
|
+
|
48
|
+
require 'websocket_rails/connection_adapters'
|
49
|
+
require 'websocket_rails/connection_adapters/http'
|
50
|
+
require 'websocket_rails/connection_adapters/web_socket'
|
51
|
+
|
52
|
+
# Exceptions
|
53
|
+
class WebsocketRails::InvalidConnectionError < StandardError
|
54
|
+
def rack_response
|
55
|
+
[400,{'Content-Type' => 'text/plain'},['invalid connection']]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class WebsocketRails::EventRoutingError < StandardError
|
60
|
+
|
61
|
+
attr_reader :event, :controller, :method
|
62
|
+
|
63
|
+
def initialize(event, controller, method)
|
64
|
+
@event = event
|
65
|
+
@controller = controller
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_s
|
69
|
+
out = "Routing Error:\n"
|
70
|
+
out << "Event: #{event.name}\n"
|
71
|
+
out << "Controller #{controller.class} does not respond to #{method}"
|
72
|
+
out
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_json
|
76
|
+
super({
|
77
|
+
:error => "EventRoutingError",
|
78
|
+
:event => event.name,
|
79
|
+
:method => method,
|
80
|
+
:reason => "Controller #{controller.class} does not respond to #{method}"
|
81
|
+
})
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
class WebsocketRails::ConfigDeprecationError < StandardError
|
87
|
+
def to_s
|
88
|
+
out = "Deprecation Error:\n\n\t"
|
89
|
+
out << "config/initializers/events.rb has been moved to config/events.rb\n\t"
|
90
|
+
out << "Make sure events.rb is in the proper location and the old one has been removed.\n\t"
|
91
|
+
out << "More information can be found in the wiki.\n\n"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
raise WebsocketRails::ConfigDeprecationError if File.exists?("config/initializers/events.rb")
|
96
|
+
|
97
|
+
|
98
|
+
# Deprecation Notices
|
99
|
+
class WebsocketRails::Dispatcher
|
100
|
+
def self.describe_events(&block)
|
101
|
+
raise "This method has been deprecated. Please use WebsocketRails::EventMap.describe instead."
|
102
|
+
end
|
103
|
+
end
|
104
|
+
class WebsocketRails::Events
|
105
|
+
def self.describe_events(&block)
|
106
|
+
raise "This method has been deprecated. Please use WebsocketRails::EventMap.describe instead."
|
107
|
+
end
|
108
|
+
end
|