jugglite 0.6.0 → 1.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b51ae9f570f0b97660639998883771ec4d6595a
4
- data.tar.gz: 5c4908a07f85a24caa317db97df70f37273edd0e
3
+ metadata.gz: 697ae333596582eea2d8786ca65f1a38c04fd351
4
+ data.tar.gz: a6b798faf7f89cb54a7407607c55dc5a6eedf975
5
5
  SHA512:
6
- metadata.gz: fb7095e9e0efc013925a87827d6df16eaff2bc1e05875900d5197c90fcdcf363bca5cce164ce60b110182adfc53ede9f180c1db817fc4aede2b40b44df63da93
7
- data.tar.gz: c6c9942ae51bf578bdadff91b2690b84c42bae8bd1780fbc4daef488e86e5b47cd712ad3f3b43cb46241c09cf7fd0311632997deb9f5c9faa11f4840f342e1b7
6
+ metadata.gz: 43e9167fef4b48692684495c24dcf30f679c2fb95bdb9392ee91fa66765d680a9d01fa715d1efb28bf807d0cdf2536e217ab7b14c0feb56c2155a6d15a9ca438
7
+ data.tar.gz: dd19ee67bd88235ab5d1e5107f8eea18e71ab8c92f378350c9f2e811501d39ee7f1500f51153c463a4135a88b187badfd35bd0306a159bf6a4286b44c9859d07
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.2.0
3
4
  - 2.1.0
4
5
  - 2.0.0
5
6
  - 1.9.3
data/README.md CHANGED
@@ -36,7 +36,19 @@ This setup is great because it allows you to do channel authorization on a per r
36
36
  user_id = request.session['user_id']
37
37
  user_id ? ['broadcast', "player_#{user_id}"] : []
38
38
  }
39
- get 'stream', to: Jugglite::App.new(nil, namespace: "app:#{Rails.env}:", allowed_channels: @allowed_channels)
39
+
40
+ @on_register = ->(connection) {
41
+ # Store something in connection.data
42
+ # connection.request holds the Rack::Request
43
+ }
44
+
45
+ @on_unregister = ->(connection) {
46
+ # Called when the connection is dropped or closed.
47
+ # You can access the connection.data set in the +on_register+ call
48
+ # Or use the connect.request.
49
+ }
50
+
51
+ get 'stream', to: Jugglite::App.new(nil, namespace: "app:#{Rails.env}:", allowed_channels: @allowed_channels, on_register: @on_register, on_unregister: @on_unregister)
40
52
 
41
53
  # ...
42
54
  ```
@@ -17,6 +17,9 @@ module Jugglite
17
17
  # +allowed_channels+ :
18
18
  # * an array with allowed channel names
19
19
  # * a proc that takes a Rack::Request and returns an array of allowed channels for that particular request
20
+ # +on_register+ : a Proc that takes a Sse::Connection as argument and is called right after a connection is initiated.
21
+ # +on_unregister+ : a Proc that takes a Sse::Connection as argument and is called right after a connection is initiated.
22
+ # The same Sse::Connection object will be passed to the on_register and on_unregister callbacks. You can for example use the +connection.data+ attribute to store an identifier.
20
23
  def initialize(app = nil, options = {})
21
24
  @app = app
22
25
  @options = {
@@ -100,10 +103,12 @@ module Jugglite
100
103
  def register_connection(connection)
101
104
  requested_channels = channels_for_request(connection.request)
102
105
  subscribe_to_new_channels(requested_channels - @redis_channels)
106
+ @options[:on_register].call(connection) if @options[:on_register]
103
107
  @subscription_map[connection] = requested_channels
104
108
  end
105
109
 
106
110
  def unregister_connection(connection)
111
+ @options[:on_unregister].call(connection) if @options[:on_register]
107
112
  @subscription_map.delete(connection)
108
113
  end
109
114
 
@@ -2,6 +2,9 @@ module Jugglite
2
2
  class SseConnection
3
3
  attr_reader :body, :request
4
4
 
5
+ # +data+ can hold optional information to track a connection
6
+ attr_accessor :data
7
+
5
8
  def initialize(request)
6
9
  @request = request
7
10
  @longpolling = request.xhr?
@@ -1,3 +1,3 @@
1
1
  module Jugglite
2
- VERSION = "0.6.0"
2
+ VERSION = "1.0.0.pre"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jugglite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 1.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - andruby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thin
@@ -107,9 +107,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ">="
110
+ - - ">"
111
111
  - !ruby/object:Gem::Version
112
- version: '0'
112
+ version: 1.3.1
113
113
  requirements: []
114
114
  rubyforge_project:
115
115
  rubygems_version: 2.4.5