faye-tls1-websocket 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ module Faye::WebSocket::API
2
+ class Event
3
+
4
+ attr_reader :type, :bubbles, :cancelable
5
+ attr_accessor :target, :current_target, :event_phase, :data, :message
6
+
7
+ CAPTURING_PHASE = 1
8
+ AT_TARGET = 2
9
+ BUBBLING_PHASE = 3
10
+
11
+ def initialize(event_type, options = {})
12
+ @type = event_type
13
+ metaclass = (class << self ; self ; end)
14
+ options.each do |key, value|
15
+ metaclass.__send__(:define_method, key) { value }
16
+ end
17
+ end
18
+
19
+ def init_event(event_type, can_bubble, cancelable)
20
+ @type = event_type
21
+ @bubbles = can_bubble
22
+ @cancelable = cancelable
23
+ end
24
+
25
+ def stop_propagation
26
+ end
27
+
28
+ def prevent_default
29
+ end
30
+
31
+ end
32
+ end
33
+
@@ -0,0 +1,57 @@
1
+ module Faye::WebSocket::API
2
+ module EventTarget
3
+
4
+ include ::WebSocket::Driver::EventEmitter
5
+ events = %w[open message error close]
6
+
7
+ events.each do |event_type|
8
+ define_method "on#{event_type}=" do |handler|
9
+ EventMachine.next_tick do
10
+ flush(event_type, &handler)
11
+ instance_variable_set("@on#{event_type}", handler)
12
+ end
13
+ end
14
+ end
15
+
16
+ def add_event_listener(event_type, listener, use_capture = false)
17
+ add_listener(event_type, &listener)
18
+ end
19
+
20
+ def add_listener(event_type, &listener)
21
+ EventMachine.next_tick do
22
+ flush(event_type, &listener)
23
+ super(event_type, &listener)
24
+ end
25
+ end
26
+
27
+ def remove_event_listener(event_type, listener, use_capture = false)
28
+ remove_listener(event_type, &listener)
29
+ end
30
+
31
+ def dispatch_event(event)
32
+ event.target = event.current_target = self
33
+ event.event_phase = Event::AT_TARGET
34
+
35
+ callback = instance_variable_get("@on#{ event.type }")
36
+ count = listener_count(event.type)
37
+
38
+ unless callback or count > 0
39
+ @buffers ||= Hash.new { |k,v| k[v] = [] }
40
+ @buffers[event.type].push(event)
41
+ end
42
+
43
+ callback.call(event) if callback
44
+ emit(event.type, event)
45
+ end
46
+
47
+ private
48
+
49
+ def flush(event_type, &callback)
50
+ if buffer = @buffers && @buffers.delete(event_type.to_s)
51
+ buffer.each { |event| callback.call(event) }
52
+ end
53
+ end
54
+
55
+ end
56
+ end
57
+
@@ -0,0 +1,64 @@
1
+ module Faye
2
+ class WebSocket
3
+
4
+ class Client
5
+ include API
6
+
7
+ attr_reader :headers, :status
8
+
9
+ def initialize(url, protocols = nil, options = {})
10
+ @url = url
11
+ @uri = URI.parse(url)
12
+ @driver = ::WebSocket::Driver.client(self, :max_length => options[:max_length], :protocols => protocols)
13
+
14
+ [:open, :error].each do |event|
15
+ @driver.on(event) do
16
+ @headers = @driver.headers
17
+ @status = @driver.status
18
+ end
19
+ end
20
+
21
+ super(options)
22
+
23
+ port = @uri.port || (@uri.scheme == 'wss' ? 443 : 80)
24
+ EventMachine.connect(@uri.host, port, Connection) do |conn|
25
+ @stream = conn
26
+ conn.parent = self
27
+ end
28
+ rescue => error
29
+ event = Event.new('error', :message => "Network error: #{url}: #{error.message}")
30
+ event.init_event('error', false, false)
31
+ dispatch_event(event)
32
+ finalize(error.message, 1006)
33
+ end
34
+
35
+ private
36
+
37
+ def on_connect
38
+ @stream.start_tls(:ssl_version => :TLSv1) if @uri.scheme == 'wss'
39
+ @driver.start
40
+ end
41
+
42
+ module Connection
43
+ attr_accessor :parent
44
+
45
+ def connection_completed
46
+ parent.__send__(:on_connect)
47
+ end
48
+
49
+ def receive_data(data)
50
+ parent.__send__(:parse, data)
51
+ end
52
+
53
+ def unbind
54
+ parent.__send__(:finalize, '', 1006)
55
+ end
56
+
57
+ def write(data)
58
+ send_data(data) rescue nil
59
+ end
60
+ end
61
+ end
62
+
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,232 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faye-tls1-websocket
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.0
5
+ platform: ruby
6
+ authors:
7
+ - James Coglan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eventmachine-le
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: websocket-driver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: progressbar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: puma
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.0
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: 2.7.0
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.0.0
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: 2.7.0
75
+ - !ruby/object:Gem::Dependency
76
+ name: rack
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rspec
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec-eventmachine
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rainbows
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 4.4.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 4.4.0
131
+ - !ruby/object:Gem::Dependency
132
+ name: thin
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: 1.2.0
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 1.2.0
145
+ - !ruby/object:Gem::Dependency
146
+ name: goliath
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: passenger
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: 4.0.0
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: 4.0.0
173
+ description:
174
+ email: jcoglan@gmail.com
175
+ executables: []
176
+ extensions: []
177
+ extra_rdoc_files:
178
+ - README.md
179
+ files:
180
+ - CHANGELOG.md
181
+ - README.md
182
+ - examples/app.rb
183
+ - examples/autobahn_client.rb
184
+ - examples/client.rb
185
+ - examples/config.ru
186
+ - examples/haproxy.conf
187
+ - examples/rainbows.conf
188
+ - examples/server.rb
189
+ - examples/sse.html
190
+ - examples/ws.html
191
+ - lib/faye/adapters/goliath.rb
192
+ - lib/faye/adapters/rainbows.rb
193
+ - lib/faye/adapters/rainbows_client.rb
194
+ - lib/faye/adapters/thin.rb
195
+ - lib/faye/eventsource.rb
196
+ - lib/faye/rack_stream.rb
197
+ - lib/faye/websocket.rb
198
+ - lib/faye/websocket/adapter.rb
199
+ - lib/faye/websocket/api.rb
200
+ - lib/faye/websocket/api/event.rb
201
+ - lib/faye/websocket/api/event_target.rb
202
+ - lib/faye/websocket/client.rb
203
+ homepage: http://github.com/faye/faye-websocket-ruby
204
+ licenses:
205
+ - MIT
206
+ metadata: {}
207
+ post_install_message:
208
+ rdoc_options:
209
+ - "--main"
210
+ - README.md
211
+ - "--markup"
212
+ - markdown
213
+ require_paths:
214
+ - lib
215
+ required_ruby_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ requirements: []
226
+ rubyforge_project:
227
+ rubygems_version: 2.2.1
228
+ signing_key:
229
+ specification_version: 4
230
+ summary: Standards-compliant WebSocket server and client
231
+ test_files: []
232
+ has_rdoc: