jugglite 0.0.2.alpha → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -2
- data/lib/jugglite/app.rb +4 -1
- data/lib/jugglite/sse_connection.rb +17 -6
- data/lib/jugglite/version.rb +1 -1
- data/spec/acceptance/stream_and_publish_spec.rb +16 -16
- metadata +5 -5
data/CHANGELOG
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
= 0.0.3 /
|
1
|
+
= 0.0.3 / 2012-11-04
|
2
2
|
|
3
|
-
*
|
3
|
+
* support for Remy's Polyfill (which adds support for IE7+)
|
4
|
+
see https://github.com/remy/polyfills/blob/master/EventSource.js
|
5
|
+
and http://html5doctor.com/server-sent-events/
|
4
6
|
|
5
7
|
= 0.0.2.alpha / 2012-11-04
|
6
8
|
|
data/lib/jugglite/app.rb
CHANGED
@@ -5,7 +5,10 @@ module Jugglite
|
|
5
5
|
# Let's go for plain Rack y'all
|
6
6
|
class App
|
7
7
|
AsyncResponse = [-1, {}, []].freeze
|
8
|
-
Headers = {
|
8
|
+
Headers = {
|
9
|
+
'Content-Type' => 'text/event-stream;charset=utf-8',
|
10
|
+
'Cache-Control' => 'no-cache' # IE (through the Polyfill) will trip without this
|
11
|
+
}
|
9
12
|
|
10
13
|
# Options include:
|
11
14
|
# +path+ : the URI path to listen to ('/stream')
|
@@ -4,17 +4,19 @@ module Jugglite
|
|
4
4
|
|
5
5
|
def initialize(request)
|
6
6
|
@request = request
|
7
|
+
@longpolling = request.xhr?
|
7
8
|
@body = DeferrableBody.new
|
8
9
|
end
|
9
10
|
|
11
|
+
def longpolling?
|
12
|
+
@longpolling
|
13
|
+
end
|
14
|
+
|
10
15
|
def write(message, options = {})
|
16
|
+
reset_timeout if longpolling?
|
11
17
|
buffer = ""
|
12
|
-
options.each
|
13
|
-
|
14
|
-
end
|
15
|
-
message.each_line do |line|
|
16
|
-
buffer << "data: #{line.strip}\n"
|
17
|
-
end
|
18
|
+
options.each { |k, v| buffer << "#{k}: #{v}\n" }
|
19
|
+
message.each_line { |line| buffer << "data: #{line.strip}\n" }
|
18
20
|
@body.write(buffer << "\n")
|
19
21
|
end
|
20
22
|
|
@@ -38,5 +40,14 @@ module Jugglite
|
|
38
40
|
def errback(&block)
|
39
41
|
@body.errback(&block)
|
40
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def reset_timeout
|
46
|
+
# From http://html5doctor.com/server-sent-events/#using-the-polyfill
|
47
|
+
@timeout.cancel if @timeout
|
48
|
+
@timeout = EventMachine::Timer.new(0.25) do
|
49
|
+
self.close
|
50
|
+
end
|
51
|
+
end
|
41
52
|
end
|
42
53
|
end
|
data/lib/jugglite/version.rb
CHANGED
@@ -3,23 +3,23 @@ require 'net/http'
|
|
3
3
|
|
4
4
|
# Execute a GET request for +channel+ that reads the body in chunks
|
5
5
|
# until the +regexp+ is received or +timeout+ seconds have passed
|
6
|
-
def listen_on_channel_until(channel, regexp, timeout = 5)
|
7
|
-
|
8
|
-
|
6
|
+
# def listen_on_channel_until(channel, regexp, timeout = 5)
|
7
|
+
# Net::HTTP.start(@host, @port) do |http|
|
8
|
+
# request = Net::HTTP::Get.new("/?channel=#{@channel}")
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
10
|
+
# body = ""
|
11
|
+
# http.request(request) do |response|
|
12
|
+
# start_time = Time.now
|
13
|
+
# response.read_body do |chunk|
|
14
|
+
# body << chunk
|
15
|
+
# body.should include(": registered to channels: #{@channel}")
|
16
|
+
# http.finish
|
17
|
+
# break
|
18
|
+
# end
|
19
|
+
# break
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
# end
|
23
23
|
|
24
24
|
describe "Streaming and publishing" do
|
25
25
|
before(:all) do
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jugglite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- andruby
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thin
|
@@ -116,9 +116,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
117
|
none: false
|
118
118
|
requirements:
|
119
|
-
- - ! '
|
119
|
+
- - ! '>='
|
120
120
|
- !ruby/object:Gem::Version
|
121
|
-
version:
|
121
|
+
version: '0'
|
122
122
|
requirements: []
|
123
123
|
rubyforge_project:
|
124
124
|
rubygems_version: 1.8.23
|