sockjs 0.2.1
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.
- data/LICENCE +19 -0
- data/README.textile +118 -0
- data/lib/meta-state.rb +151 -0
- data/lib/rack/sockjs.rb +173 -0
- data/lib/sockjs.rb +59 -0
- data/lib/sockjs/callbacks.rb +19 -0
- data/lib/sockjs/connection.rb +45 -0
- data/lib/sockjs/delayed-response-body.rb +99 -0
- data/lib/sockjs/duck-punch-rack-mount.rb +12 -0
- data/lib/sockjs/duck-punch-thin-response.rb +15 -0
- data/lib/sockjs/examples/protocol_conformance_test.rb +73 -0
- data/lib/sockjs/faye.rb +15 -0
- data/lib/sockjs/protocol.rb +97 -0
- data/lib/sockjs/servers/request.rb +136 -0
- data/lib/sockjs/servers/response.rb +169 -0
- data/lib/sockjs/session.rb +388 -0
- data/lib/sockjs/transport.rb +354 -0
- data/lib/sockjs/transports/eventsource.rb +30 -0
- data/lib/sockjs/transports/htmlfile.rb +69 -0
- data/lib/sockjs/transports/iframe.rb +68 -0
- data/lib/sockjs/transports/info.rb +48 -0
- data/lib/sockjs/transports/jsonp.rb +84 -0
- data/lib/sockjs/transports/websocket.rb +166 -0
- data/lib/sockjs/transports/welcome_screen.rb +17 -0
- data/lib/sockjs/transports/xhr.rb +75 -0
- data/lib/sockjs/version.rb +13 -0
- data/spec/sockjs/protocol_spec.rb +49 -0
- data/spec/sockjs/session_spec.rb +51 -0
- data/spec/sockjs/transport_spec.rb +73 -0
- data/spec/sockjs/transports/eventsource_spec.rb +56 -0
- data/spec/sockjs/transports/htmlfile_spec.rb +72 -0
- data/spec/sockjs/transports/iframe_spec.rb +66 -0
- data/spec/sockjs/transports/jsonp_spec.rb +252 -0
- data/spec/sockjs/transports/websocket_spec.rb +101 -0
- data/spec/sockjs/transports/welcome_screen_spec.rb +36 -0
- data/spec/sockjs/transports/xhr_spec.rb +314 -0
- data/spec/sockjs/version_spec.rb +18 -0
- data/spec/sockjs_spec.rb +8 -0
- data/spec/spec_helper.rb +121 -0
- data/spec/support/async-test.rb +42 -0
- metadata +171 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env bundle exec rspec
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require "spec_helper"
|
5
|
+
require "sockjs/version"
|
6
|
+
|
7
|
+
describe SockJS do
|
8
|
+
it "should define VERSION" do
|
9
|
+
constants = described_class.constants.map(&:to_sym)
|
10
|
+
constants.should include(:GEM_VERSION)
|
11
|
+
SockJS::GEM_VERSION.should be_an_instance_of(String)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should define PROTOCOL_VERSION" do
|
15
|
+
constants = described_class.constants.map(&:to_sym)
|
16
|
+
constants.should include(:PROTOCOL_VERSION)
|
17
|
+
end
|
18
|
+
end
|
data/spec/sockjs_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'support/async-test.rb'
|
4
|
+
require 'support/shared-contexts'
|
5
|
+
require 'stringio'
|
6
|
+
require 'thin'
|
7
|
+
require 'sockjs'
|
8
|
+
require 'sockjs/servers/request'
|
9
|
+
require 'sockjs/servers/response'
|
10
|
+
require 'sockjs/session'
|
11
|
+
|
12
|
+
require 'sockjs/examples/protocol_conformance_test'
|
13
|
+
require 'sockjs/version'
|
14
|
+
|
15
|
+
module TransportSpecMacros
|
16
|
+
def transport_handler_eql(path, method)
|
17
|
+
describe SockJS::Transport do
|
18
|
+
describe "transports[#{path}]" do
|
19
|
+
let :route_set do
|
20
|
+
mock("Route Set")
|
21
|
+
end
|
22
|
+
|
23
|
+
let :connection do
|
24
|
+
mock("Connection")
|
25
|
+
end
|
26
|
+
|
27
|
+
let :options do
|
28
|
+
{}
|
29
|
+
end
|
30
|
+
|
31
|
+
let :path_matcher do
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have a #{described_class} at #{method}" do
|
36
|
+
route_set.should_receive(:add_route).with(instance_of(described_class), hash_including(:path_info, :request_method => method), {})
|
37
|
+
described_class.add_route(route_set, connection, options)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class FakeRequest < SockJS::Request
|
45
|
+
attr_reader :chunks
|
46
|
+
attr_writer :data
|
47
|
+
attr_accessor :path_info, :query_string, :if_none_match, :content_type
|
48
|
+
|
49
|
+
def initialize(env = Hash.new)
|
50
|
+
self.env.merge!(env)
|
51
|
+
@query_string = {}
|
52
|
+
@chunks = []
|
53
|
+
end
|
54
|
+
|
55
|
+
def session_key=(value)
|
56
|
+
@env['rack.routing_args'] ||= {}
|
57
|
+
@env['rack.routing_args'][:session_key] = value
|
58
|
+
end
|
59
|
+
|
60
|
+
def env
|
61
|
+
@env ||= {
|
62
|
+
"async.callback" => Proc.new do |status, headers, body|
|
63
|
+
# This is so we can test it.
|
64
|
+
# Block passed to body.each will be used
|
65
|
+
# as the @body_callback in DelayedResponseBody.
|
66
|
+
body.each do |chunk|
|
67
|
+
next if chunk == "0\r\n\r\n"
|
68
|
+
@chunks << chunk.split("\r\n").last
|
69
|
+
end
|
70
|
+
end,
|
71
|
+
|
72
|
+
"async.close" => EventMachine::DefaultDeferrable.new
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
def session_id
|
77
|
+
"session-id"
|
78
|
+
end
|
79
|
+
|
80
|
+
def origin
|
81
|
+
"*"
|
82
|
+
end
|
83
|
+
|
84
|
+
def fresh?(etag)
|
85
|
+
@if_none_match == etag
|
86
|
+
end
|
87
|
+
|
88
|
+
def data
|
89
|
+
StringIO.new(@data || "")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class FakeSession < SockJS::Session
|
94
|
+
def set_timer
|
95
|
+
end
|
96
|
+
|
97
|
+
def reset_timer
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class SockJS::Response
|
102
|
+
def chunks
|
103
|
+
@request.chunks
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
RSpec.configure do |config|
|
108
|
+
config.backtrace_clean_patterns.delete(/gems/)
|
109
|
+
config.extend(TransportSpecMacros)
|
110
|
+
config.before do
|
111
|
+
class SockJS::Transport
|
112
|
+
def session_class
|
113
|
+
FakeSession
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
config.after do
|
119
|
+
SockJS::no_debug!
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'thin'
|
2
|
+
require 'eventmachine'
|
3
|
+
|
4
|
+
module Thin
|
5
|
+
module Async
|
6
|
+
class Test
|
7
|
+
VERSION = '1.0.0'
|
8
|
+
|
9
|
+
class Callback
|
10
|
+
attr_reader :status, :headers, :body
|
11
|
+
|
12
|
+
def call args
|
13
|
+
@status, @headers, deferred_body = args
|
14
|
+
@body = ""
|
15
|
+
deferred_body.each {|s| @body << s }
|
16
|
+
|
17
|
+
deferred_body.callback { EM.stop }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(app, options={})
|
22
|
+
@app = app
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
callback = Callback.new
|
27
|
+
env.merge! 'async.callback' => callback
|
28
|
+
|
29
|
+
result = @app.call(env)
|
30
|
+
|
31
|
+
unless result.first == -1
|
32
|
+
EM.next_tick do
|
33
|
+
EM.stop
|
34
|
+
return result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
[callback.status, callback.headers, callback.body]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sockjs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Judson Lester
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: &76745750 !ruby/object:Gem::Requirement
|
17
|
+
none: true
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *76745750
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: thin
|
27
|
+
requirement: &76744510 !ruby/object:Gem::Requirement
|
28
|
+
none: true
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *76744510
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: json
|
38
|
+
requirement: &76743770 !ruby/object:Gem::Requirement
|
39
|
+
none: true
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *76743770
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: faye-websocket
|
49
|
+
requirement: &76742940 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 4
|
58
|
+
- 3
|
59
|
+
type: :runtime
|
60
|
+
prerelease: false
|
61
|
+
version_requirements: *76742940
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: regin
|
64
|
+
requirement: &76741840 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.3.8
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
- 3
|
73
|
+
- 8
|
74
|
+
type: :runtime
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: *76741840
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: rack-mount
|
79
|
+
requirement: &76761770 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ~>
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.8.3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
- 8
|
88
|
+
- 3
|
89
|
+
type: :runtime
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *76761770
|
92
|
+
description: ! ' SockJS is a WebSocket emulation library. It means that you use
|
93
|
+
the WebSocket API, only instead of WebSocket class you instantiate SockJS class.
|
94
|
+
In absence of WebSocket, some of the fallback transports will be used. This code
|
95
|
+
is compatible with SockJS protocol 0.2.1.
|
96
|
+
|
97
|
+
'
|
98
|
+
email: nyarly@gmail.com
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files:
|
102
|
+
- README.textile
|
103
|
+
files:
|
104
|
+
- LICENCE
|
105
|
+
- README.textile
|
106
|
+
- lib/meta-state.rb
|
107
|
+
- lib/rack/sockjs.rb
|
108
|
+
- lib/sockjs.rb
|
109
|
+
- lib/sockjs/delayed-response-body.rb
|
110
|
+
- lib/sockjs/duck-punch-rack-mount.rb
|
111
|
+
- lib/sockjs/duck-punch-thin-response.rb
|
112
|
+
- lib/sockjs/callbacks.rb
|
113
|
+
- lib/sockjs/connection.rb
|
114
|
+
- lib/sockjs/examples/protocol_conformance_test.rb
|
115
|
+
- lib/sockjs/faye.rb
|
116
|
+
- lib/sockjs/protocol.rb
|
117
|
+
- lib/sockjs/servers/request.rb
|
118
|
+
- lib/sockjs/servers/response.rb
|
119
|
+
- lib/sockjs/session.rb
|
120
|
+
- lib/sockjs/transport.rb
|
121
|
+
- lib/sockjs/transports/eventsource.rb
|
122
|
+
- lib/sockjs/transports/htmlfile.rb
|
123
|
+
- lib/sockjs/transports/iframe.rb
|
124
|
+
- lib/sockjs/transports/info.rb
|
125
|
+
- lib/sockjs/transports/jsonp.rb
|
126
|
+
- lib/sockjs/transports/websocket.rb
|
127
|
+
- lib/sockjs/transports/welcome_screen.rb
|
128
|
+
- lib/sockjs/transports/xhr.rb
|
129
|
+
- lib/sockjs/version.rb
|
130
|
+
- spec/sockjs/protocol_spec.rb
|
131
|
+
- spec/sockjs/session_spec.rb
|
132
|
+
- spec/sockjs/transport_spec.rb
|
133
|
+
- spec/sockjs/transports/eventsource_spec.rb
|
134
|
+
- spec/sockjs/transports/htmlfile_spec.rb
|
135
|
+
- spec/sockjs/transports/iframe_spec.rb
|
136
|
+
- spec/sockjs/transports/jsonp_spec.rb
|
137
|
+
- spec/sockjs/transports/websocket_spec.rb
|
138
|
+
- spec/sockjs/transports/welcome_screen_spec.rb
|
139
|
+
- spec/sockjs/transports/xhr_spec.rb
|
140
|
+
- spec/sockjs/version_spec.rb
|
141
|
+
- spec/sockjs_spec.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
- spec/support/async-test.rb
|
144
|
+
homepage: https://github.com/nyarly/sockjs-ruby
|
145
|
+
licenses: []
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ~>
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '1.9'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ! '>='
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
segments:
|
163
|
+
- 0
|
164
|
+
hash: -1068506783
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project: sockjs
|
167
|
+
rubygems_version: 1.8.15
|
168
|
+
signing_key:
|
169
|
+
specification_version: 3
|
170
|
+
summary: Ruby server for SockJS
|
171
|
+
test_files: []
|