websocket-rails 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,25 +1,37 @@
1
1
  # WebsocketRails Change Log
2
2
 
3
- March 12 2013
3
+ ## Version 0.4.4
4
+
5
+ April 28 2013
6
+
7
+ * Remove existing subscribers from a channel when making it private to
8
+ eliminate the potential for malicious users to eavesdrop on private
9
+ channels. Addresses issue #72.
10
+ * Prevent the server from crashing when receiving an uploaded file.
11
+ Addresses issue #68.
12
+ * Allow custom routes for the WebSocket server. Users of are
13
+ no longer forced to use the `/websocket` route. - Thanks to @Cominch
4
14
 
5
15
  ## Version 0.4.3
6
16
 
17
+ March 12 2013
18
+
7
19
  * Change the log output in Channel#trigger_event. Fixes issue #61.
8
20
  * Cancel the ping timer when removing disconnecting a Connection.
9
21
  * Fix uninitialized constant WebsocketRails::Internal controller error.
10
22
 
11
- March 1 2013
12
-
13
23
  ## Version 0.4.2
14
24
 
25
+ March 1 2013
26
+
15
27
  * Check to make sure ActiveRecord is defined before calling
16
28
  ActiveRecord::RecordInvalid in Dispatcher. Fixes issue #54. - Thanks to
17
29
  @nessche
18
30
 
19
- February 28 2013
20
-
21
31
  ## Version 0.4.1
22
32
 
33
+ February 28 2013
34
+
23
35
  * Fix bug in ControllerFactory#reload! that prevented the handling of
24
36
  internal events when running in the Development environment. Fixes issue #50. - Thanks to @nessche
25
37
 
@@ -32,10 +44,10 @@ Addresses issue #51. - Thanks to @ngauthier
32
44
  the Rails version and adds the correct path for the routes file. Fixes
33
45
  issue #49. - Thanks to @sgerrand
34
46
 
35
- February 27 2013
36
-
37
47
  ## Version 0.4.0
38
48
 
49
+ February 27 2013
50
+
39
51
  __There have been a few breaking changes in the public API since the
40
52
  last release. Please review the list below and consult the Wiki for more
41
53
  information regarding the usage of the new features.__
data/README.md CHANGED
@@ -11,6 +11,13 @@ Check out the [CHANGELOG](https://github.com/DanKnox/websocket-rails/blob/master
11
11
  As of version 0.2.0, non event machine based web servers such as Phusion
12
12
  Passenger are supported through the use of the [Standalone Server Mode](https://github.com/DanKnox/websocket-rails/wiki/Standalone-Server-Mode).
13
13
 
14
+ **Note About Development**
15
+
16
+ I am currently seeking a co-maintainer for this project. My time has
17
+ been limited recently and I have not been as attentive to issues and
18
+ feature requests as I would like. If you are interested in helping out
19
+ please send me an email or post a message on the issue tracker.
20
+
14
21
  ## Overview
15
22
 
16
23
  Start treating client side events as first class citizens inside your
@@ -21,11 +21,12 @@ class WebSocketRails.HttpConnection
21
21
  xmlhttp
22
22
 
23
23
  constructor: (@url, @dispatcher) ->
24
+ @_url = @url
24
25
  @_conn = @createXMLHttpObject()
25
26
  @last_pos = 0
26
27
  @message_queue = []
27
28
  @_conn.onreadystatechange = @parse_stream
28
- @_conn.open "GET", "/websocket", true
29
+ @_conn.open "GET", @_url, true
29
30
  @_conn.send()
30
31
 
31
32
  parse_stream: =>
@@ -43,7 +44,7 @@ class WebSocketRails.HttpConnection
43
44
  @post_data @dispatcher.connection_id, event.serialize()
44
45
 
45
46
  post_data: (connection_id, payload) ->
46
- $.ajax "/websocket",
47
+ $.ajax @_url,
47
48
  type: 'POST'
48
49
  data:
49
50
  client_id: connection_id
@@ -2,7 +2,7 @@
2
2
  WebsocketRails JavaScript Client
3
3
 
4
4
  Setting up the dispatcher:
5
- var dispatcher = new WebSocketRails('localhost:3000');
5
+ var dispatcher = new WebSocketRails('localhost:3000/websocket');
6
6
  dispatcher.on_open = function() {
7
7
  // trigger a server event immediately after opening connection
8
8
  dispatcher.trigger('new_user',{user_name: 'guest'});
@@ -7,7 +7,7 @@ WebsocketRails.setup do |config|
7
7
 
8
8
  # Uncomment to change the default log file path.
9
9
  # config.log_path = "#{Rails.root}/log/websocket_rails.log"
10
-
10
+
11
11
  # Set to true if you wish to log the internal websocket_rails events
12
12
  # such as the keepalive `websocket_rails.ping` event.
13
13
  # config.log_internal_events = false
@@ -26,6 +26,12 @@ WebsocketRails.setup do |config|
26
26
  # Will not be used unless standalone or synchronization mode
27
27
  # is enabled.
28
28
  # config.redis_options = {:host => 'localhost', :port => '6379'}
29
+
30
+ # By default, all subscribers in to a channel will be removed
31
+ # when that channel is made private. If you don't wish active
32
+ # subscribers to be removed from a previously public channel
33
+ # when making it private, set the following to true.
34
+ # config.keep_subscribers_when_private = false
29
35
  end
30
36
 
31
37
  WebsocketRails::EventMap.describe do
@@ -3,6 +3,8 @@ module WebsocketRails
3
3
 
4
4
  include Logging
5
5
 
6
+ delegate :config, :to => WebsocketRails
7
+
6
8
  attr_reader :name, :subscribers
7
9
 
8
10
  def initialize(channel_name)
@@ -38,6 +40,9 @@ module WebsocketRails
38
40
  end
39
41
 
40
42
  def make_private
43
+ unless config.keep_subscribers_when_private?
44
+ @subscribers.clear
45
+ end
41
46
  @private = true
42
47
  end
43
48
 
@@ -1,6 +1,14 @@
1
1
  module WebsocketRails
2
2
  class Configuration
3
3
 
4
+ def keep_subscribers_when_private?
5
+ @keep_subscribers_when_private ||= false
6
+ end
7
+
8
+ def keep_subscribers_when_private=(value)
9
+ @keep_subscribers_when_private = value
10
+ end
11
+
4
12
  def route_block=(routes)
5
13
  @event_routes = routes
6
14
  end
@@ -58,6 +58,9 @@ module WebsocketRails
58
58
  # :channel =>
59
59
  # The name of the channel that this event is destined for.
60
60
  class Event
61
+
62
+ class UnknownDataType < StandardError; end;
63
+
61
64
  extend Logging
62
65
 
63
66
  def self.log_header
@@ -65,10 +68,22 @@ module WebsocketRails
65
68
  end
66
69
 
67
70
  def self.new_from_json(encoded_data, connection)
68
- event_name, data = JSON.parse encoded_data
69
- data = data.merge(:connection => connection).with_indifferent_access
70
- Event.new event_name, data
71
- rescue JSON::ParserError => ex
71
+ case encoded_data
72
+ when String
73
+ event_name, data = JSON.parse encoded_data
74
+ data = data.merge(:connection => connection).with_indifferent_access
75
+ Event.new event_name, data
76
+ # when Array
77
+ # TODO: Handle file
78
+ #File.open("/tmp/test#{rand(100)}.jpg", "wb") do |file|
79
+ # encoded_data.each do |byte|
80
+ # file << byte.chr
81
+ # end
82
+ #end
83
+ else
84
+ raise UnknownDataType
85
+ end
86
+ rescue JSON::ParserError, UnknownDataType => ex
72
87
  warn "Invalid Event Received: #{ex}"
73
88
  debug "Event Data: #{encoded_data}"
74
89
  log_exception(ex)
@@ -1,3 +1,3 @@
1
1
  module WebsocketRails
2
- VERSION = "0.4.3"
2
+ VERSION = "0.4.4"
3
3
  end
@@ -1139,3 +1139,5 @@ Connecting to database specified by database.yml
1139
1139
  Connecting to database specified by database.yml
1140
1140
  Connecting to database specified by database.yml
1141
1141
  Connecting to database specified by database.yml
1142
+ Connecting to database specified by database.yml
1143
+ Connecting to database specified by database.yml
@@ -57,6 +57,10 @@ module WebsocketRails
57
57
  end
58
58
 
59
59
  context "private channels" do
60
+ before do
61
+ subject.subscribers << connection
62
+ end
63
+
60
64
  it "should be public by default" do
61
65
  subject.instance_variable_get(:@private).should_not be_true
62
66
  end
@@ -66,6 +70,26 @@ module WebsocketRails
66
70
  subject.make_private
67
71
  subject.instance_variable_get(:@private).should be_true
68
72
  end
73
+
74
+ context "when Configuration#keep_subscribers_when_private? is false" do
75
+ it "should clear any existing subscribers in the channel" do
76
+ subject.subscribers.count.should == 1
77
+ subject.make_private
78
+ subject.subscribers.count.should == 0
79
+ end
80
+ end
81
+
82
+ context "when Configuration#keep_subscribers_when_private? is true" do
83
+ before do
84
+ WebsocketRails.config.keep_subscribers_when_private = true
85
+ end
86
+
87
+ it "should leave the existing subscribers in the channel" do
88
+ subject.subscribers.count.should == 1
89
+ subject.make_private
90
+ subject.subscribers.count.should == 1
91
+ end
92
+ end
69
93
  end
70
94
 
71
95
  describe "#is_private?" do
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.4.3
4
+ version: 0.4.4
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: 2013-03-13 00:00:00.000000000 Z
14
+ date: 2013-04-28 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -300,7 +300,7 @@ files:
300
300
  - CHANGELOG.md
301
301
  homepage: http://danknox.github.com/websocket-rails/
302
302
  licenses: []
303
- post_install_message: ! " Welcome to WebsocketRails v0.4.3!\n\n There have been
303
+ post_install_message: ! " Welcome to WebsocketRails v0.4.4!\n\n There have been
304
304
  a few significant changes in the public\n API, so if you are upgrading please be
305
305
  sure to read the\n CHANGELOG located at:\n\n http://github.com/DanKnox/websocket-rails/CHANGELOG.md\n"
306
306
  rdoc_options: []
@@ -314,7 +314,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
314
314
  version: '0'
315
315
  segments:
316
316
  - 0
317
- hash: -1144546358314647981
317
+ hash: 4427836168917747429
318
318
  required_rubygems_version: !ruby/object:Gem::Requirement
319
319
  none: false
320
320
  requirements:
@@ -323,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
323
  version: '0'
324
324
  segments:
325
325
  - 0
326
- hash: -1144546358314647981
326
+ hash: 4427836168917747429
327
327
  requirements: []
328
328
  rubyforge_project: websocket-rails
329
329
  rubygems_version: 1.8.25