faye-websocket 0.10.6 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
data/examples/app.rb DELETED
@@ -1,54 +0,0 @@
1
- require 'faye/websocket'
2
- require 'permessage_deflate'
3
- require 'rack'
4
-
5
- static = Rack::File.new(File.dirname(__FILE__))
6
- options = {:extensions => [PermessageDeflate], :ping => 5}
7
-
8
- App = lambda do |env|
9
- if Faye::WebSocket.websocket?(env)
10
- ws = Faye::WebSocket.new(env, ['irc', 'xmpp'], options)
11
- p [:open, ws.url, ws.version, ws.protocol]
12
-
13
- ws.onmessage = lambda do |event|
14
- ws.send(event.data)
15
- end
16
-
17
- ws.onclose = lambda do |event|
18
- p [:close, event.code, event.reason]
19
- ws = nil
20
- end
21
-
22
- ws.rack_response
23
-
24
- elsif Faye::EventSource.eventsource?(env)
25
- es = Faye::EventSource.new(env)
26
- time = es.last_event_id.to_i
27
-
28
- p [:open, es.url, es.last_event_id]
29
-
30
- loop = EM.add_periodic_timer(2) do
31
- time += 1
32
- es.send("Time: #{time}")
33
- EM.add_timer(1) do
34
- es.send('Update!!', :event => 'update', :id => time) if es
35
- end
36
- end
37
-
38
- es.send("Welcome!\n\nThis is an EventSource server.")
39
-
40
- es.onclose = lambda do |event|
41
- EM.cancel_timer(loop)
42
- p [:close, es.url]
43
- es = nil
44
- end
45
-
46
- es.rack_response
47
-
48
- else
49
- static.call(env)
50
- end
51
- end
52
-
53
- def App.log(message)
54
- end
@@ -1,47 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'cgi'
4
- require 'faye/websocket'
5
- require 'permessage_deflate'
6
- require 'progressbar'
7
-
8
- EM.run {
9
- host = 'ws://localhost:9001'
10
- ruby = RUBY_PLATFORM =~ /java/ ? 'jruby' : 'cruby'
11
- agent = CGI.escape("#{ruby}-#{RUBY_VERSION}")
12
- cases = 0
13
- options = {:extensions => [PermessageDeflate]}
14
-
15
- socket = Faye::WebSocket::Client.new("#{host}/getCaseCount")
16
- progress = nil
17
-
18
- socket.onmessage = lambda do |event|
19
- puts "Total cases to run: #{event.data}"
20
- cases = event.data.to_i
21
- progress = ProgressBar.create(:title => 'Autobahn', :total => cases)
22
- end
23
-
24
- run_case = lambda do |n|
25
- if n > cases
26
- socket = Faye::WebSocket::Client.new("#{host}/updateReports?agent=#{agent}")
27
- socket.onclose = lambda { |e| EM.stop }
28
- next
29
- end
30
-
31
- url = "#{host}/runCase?case=#{n}&agent=#{agent}"
32
- socket = Faye::WebSocket::Client.new(url, [], options)
33
-
34
- socket.onmessage = lambda do |event|
35
- socket.send(event.data)
36
- end
37
-
38
- socket.on :close do |event|
39
- progress.increment
40
- run_case[n + 1]
41
- end
42
- end
43
-
44
- socket.onclose = lambda do |event|
45
- run_case[1]
46
- end
47
- }
data/examples/client.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'faye/websocket'
4
- require 'eventmachine'
5
- require 'permessage_deflate'
6
-
7
- EM.run {
8
- url = ARGV[0]
9
- proxy = ARGV[1]
10
-
11
- ws = Faye::WebSocket::Client.new(url, [],
12
- :proxy => {:origin => proxy, :headers => {'User-Agent' => 'Echo'}},
13
- :headers => {'Origin' => 'http://faye.jcoglan.com'},
14
- :extensions => [PermessageDeflate]
15
- )
16
-
17
- ws.onopen = lambda do |event|
18
- p [:open, ws.headers]
19
- ws.send('mic check')
20
- end
21
-
22
- ws.onclose = lambda do |close|
23
- p [:close, close.code, close.reason]
24
- EM.stop
25
- end
26
-
27
- ws.onerror = lambda do |error|
28
- p [:error, error.message]
29
- end
30
-
31
- ws.onmessage = lambda do |message|
32
- p [:message, message.data]
33
- end
34
- }
data/examples/config.ru DELETED
@@ -1,13 +0,0 @@
1
- # Run using your favourite server:
2
- #
3
- # thin start -R examples/config.ru -p 7000
4
- # rainbows -c examples/rainbows.conf -E production examples/config.ru -p 7000
5
-
6
- require 'rubygems'
7
- require 'bundler/setup'
8
- require File.expand_path('../app', __FILE__)
9
-
10
- Faye::WebSocket.load_adapter('thin')
11
- Faye::WebSocket.load_adapter('rainbows')
12
-
13
- run App
@@ -1,20 +0,0 @@
1
- defaults
2
- mode http
3
- timeout client 5s
4
- timeout connect 5s
5
- timeout server 5s
6
-
7
- frontend all 0.0.0.0:3000
8
- mode http
9
- timeout client 120s
10
-
11
- option forwardfor
12
- option http-server-close
13
- option http-pretend-keepalive
14
-
15
- default_backend sockets
16
-
17
- backend sockets
18
- balance uri depth 2
19
- timeout server 120s
20
- server socket1 127.0.0.1:7000
@@ -1,14 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'eventmachine'
4
- require 'websocket/driver'
5
-
6
- require File.expand_path('../../spec/proxy_server', __FILE__)
7
-
8
- port = ARGV[0]
9
- secure = ARGV[1] == 'tls'
10
-
11
- EM.run {
12
- proxy = ProxyServer.new(:debug => true)
13
- proxy.listen(port, secure)
14
- }
@@ -1,3 +0,0 @@
1
- Rainbows! do
2
- use :EventMachine
3
- end
data/examples/server.rb DELETED
@@ -1,50 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'rack/content_length'
4
- require 'rack/chunked'
5
-
6
- port = ARGV[0] || 7000
7
- secure = ARGV[1] == 'tls'
8
- engine = ARGV[2] || 'thin'
9
- spec = File.expand_path('../../spec', __FILE__)
10
-
11
- require File.expand_path('../app', __FILE__)
12
- Faye::WebSocket.load_adapter(engine)
13
-
14
- case engine
15
-
16
- when 'goliath'
17
- class WebSocketServer < Goliath::API
18
- def response(env)
19
- App.call(env)
20
- end
21
- end
22
-
23
- when 'puma'
24
- events = Puma::Events.new($stdout, $stderr)
25
- binder = Puma::Binder.new(events)
26
- binder.parse(["tcp://0.0.0.0:#{port}"], App)
27
- server = Puma::Server.new(App, events)
28
- server.binder = binder
29
- server.run.join
30
-
31
- when 'rainbows'
32
- rackup = Unicorn::Configurator::RACKUP
33
- rackup[:port] = port
34
- rackup[:set_listener] = true
35
- options = rackup[:options]
36
- options[:config_file] = File.expand_path('../rainbows.conf', __FILE__)
37
- Rainbows::HttpServer.new(App, options).start.join
38
-
39
- when 'thin'
40
- thin = Rack::Handler.get('thin')
41
- thin.run(App, :Port => port) do |server|
42
- if secure
43
- server.ssl_options = {
44
- :private_key_file => spec + '/server.key',
45
- :cert_chain_file => spec + '/server.crt'
46
- }
47
- server.ssl = true
48
- end
49
- end
50
- end
data/examples/sse.html DELETED
@@ -1,38 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
- <title>EventSource test</title>
6
- </head>
7
- <body>
8
-
9
- <h1>EventSource test</h1>
10
- <ul></ul>
11
-
12
- <script type="text/javascript">
13
- var logger = document.getElementsByTagName('ul')[0],
14
- socket = new EventSource('/');
15
-
16
- var log = function(text) {
17
- logger.innerHTML += '<li>' + text + '</li>';
18
- };
19
-
20
- socket.onopen = function() {
21
- log('OPEN');
22
- };
23
-
24
- socket.onmessage = function(event) {
25
- log('MESSAGE: ' + event.data);
26
- };
27
-
28
- socket.addEventListener('update', function(event) {
29
- log('UPDATE(' + event.lastEventId + '): ' + event.data);
30
- });
31
-
32
- socket.onerror = function(event) {
33
- log('ERROR: ' + event.message);
34
- };
35
- </script>
36
-
37
- </body>
38
- </html>
data/examples/ws.html DELETED
@@ -1,43 +0,0 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta http-equiv="Content-type" content="text/html; charset=utf-8">
5
- <title>WebSocket test</title>
6
- </head>
7
- <body>
8
-
9
- <h1>WebSocket test</h1>
10
- <ul></ul>
11
-
12
- <script type="text/javascript">
13
- var logger = document.getElementsByTagName('ul')[0],
14
- Socket = window.MozWebSocket || window.WebSocket,
15
- protos = ['foo', 'bar', 'xmpp'],
16
- socket = new Socket('ws://' + location.hostname + ':' + location.port + '/', protos),
17
- index = 0;
18
-
19
- var log = function(text) {
20
- logger.innerHTML += '<li>' + text + '</li>';
21
- };
22
-
23
- socket.addEventListener('open', function() {
24
- log('OPEN: ' + socket.protocol);
25
- socket.send('Hello, world');
26
- });
27
-
28
- socket.onerror = function(event) {
29
- log('ERROR: ' + event.message);
30
- };
31
-
32
- socket.onmessage = function(event) {
33
- log('MESSAGE: ' + event.data);
34
- setTimeout(function() { socket.send(++index + ' ' + event.data) }, 2000);
35
- };
36
-
37
- socket.onclose = function(event) {
38
- log('CLOSE: ' + event.code + ', ' + event.reason);
39
- };
40
- </script>
41
-
42
- </body>
43
- </html>