async-websocket 0.14.0 → 0.19.0
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 +4 -4
- data/lib/async/websocket/adapters/http.rb +64 -0
- data/lib/async/websocket/adapters/rack.rb +11 -28
- data/{spec/async/websocket/upgrade.rb → lib/async/websocket/adapters/rails.rb} +20 -19
- data/lib/async/websocket/client.rb +19 -13
- data/lib/async/websocket/connect_request.rb +4 -0
- data/lib/async/websocket/connection.rb +1 -0
- data/lib/async/websocket/version.rb +1 -1
- metadata +37 -101
- data/.editorconfig +0 -6
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -21
- data/Gemfile +0 -7
- data/README.md +0 -143
- data/async-websocket.gemspec +0 -29
- data/examples/chat/.env +0 -3
- data/examples/chat/README.md +0 -147
- data/examples/chat/client.rb +0 -32
- data/examples/chat/config.ru +0 -150
- data/examples/chat/multi-client.rb +0 -79
- data/examples/mud/client.rb +0 -34
- data/examples/mud/config.ru +0 -142
- data/examples/rack/client.rb +0 -19
- data/examples/rack/config.ru +0 -12
- data/examples/utopia/.bowerrc +0 -4
- data/examples/utopia/.gitignore +0 -9
- data/examples/utopia/.rspec +0 -4
- data/examples/utopia/Gemfile +0 -33
- data/examples/utopia/Guardfile +0 -29
- data/examples/utopia/README.md +0 -16
- data/examples/utopia/Rakefile +0 -8
- data/examples/utopia/config.ru +0 -47
- data/examples/utopia/config/README.md +0 -7
- data/examples/utopia/config/environment.rb +0 -8
- data/examples/utopia/lib/readme.txt +0 -1
- data/examples/utopia/pages/_heading.xnode +0 -2
- data/examples/utopia/pages/_page.xnode +0 -30
- data/examples/utopia/pages/client/client.js +0 -28
- data/examples/utopia/pages/client/index.xnode +0 -8
- data/examples/utopia/pages/errors/exception.xnode +0 -5
- data/examples/utopia/pages/errors/file-not-found.xnode +0 -5
- data/examples/utopia/pages/links.yaml +0 -2
- data/examples/utopia/pages/server/controller.rb +0 -26
- data/examples/utopia/public/_static/icon.png +0 -0
- data/examples/utopia/public/_static/site.css +0 -205
- data/examples/utopia/public/_static/utopia-background.svg +0 -1
- data/examples/utopia/public/_static/utopia.svg +0 -1
- data/examples/utopia/public/readme.txt +0 -1
- data/examples/utopia/spec/spec_helper.rb +0 -31
- data/examples/utopia/spec/website_context.rb +0 -11
- data/examples/utopia/spec/website_spec.rb +0 -56
- data/examples/utopia/tasks/bower.rake +0 -45
- data/examples/utopia/tasks/deploy.rake +0 -13
- data/examples/utopia/tasks/development.rake +0 -34
- data/examples/utopia/tasks/environment.rake +0 -17
- data/examples/utopia/tasks/log.rake +0 -17
- data/examples/utopia/tasks/static.rake +0 -43
- data/spec/async/websocket/adapters/rack/client.rb +0 -38
- data/spec/async/websocket/adapters/rack/config.ru +0 -23
- data/spec/async/websocket/adapters/rack_spec.rb +0 -84
- data/spec/async/websocket/connection_spec.rb +0 -34
- data/spec/async/websocket/server_examples.rb +0 -117
- data/spec/async/websocket/server_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -16
@@ -1,7 +0,0 @@
|
|
1
|
-
# Utopia Config
|
2
|
-
|
3
|
-
This directory contains `environment.rb` which is used to initialize the running environment for tasks and servers.
|
4
|
-
|
5
|
-
## Setting Environment Variables
|
6
|
-
|
7
|
-
If you wish to set environment variables on a per-deployment basis, you can do so by creating an `config/environment.yaml` and populating it with key-value pairs.
|
@@ -1 +0,0 @@
|
|
1
|
-
You can add additional code for your application in this directory, and require it directly from the config.ru.
|
@@ -1,30 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<?r response.cache! ?>
|
5
|
-
|
6
|
-
<?r if title = self[:title] ?>
|
7
|
-
<title>#{title.gsub(/<.*?>/, "")} - Utopia</title>
|
8
|
-
<?r else ?>
|
9
|
-
<title>Utopia</title>
|
10
|
-
<?r end ?>
|
11
|
-
|
12
|
-
<base href="#{first.node.uri_path}"/>
|
13
|
-
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
14
|
-
|
15
|
-
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous" />
|
16
|
-
|
17
|
-
<link rel="icon" type="image/png" href="/_static/icon.png" />
|
18
|
-
<link rel="stylesheet" href="/_static/site.css" type="text/css" media="screen" />
|
19
|
-
</head>
|
20
|
-
|
21
|
-
<body class="#{attributes[:class]}">
|
22
|
-
<header>
|
23
|
-
<img src="/_static/utopia.svg" />
|
24
|
-
</header>
|
25
|
-
|
26
|
-
<div id="page">
|
27
|
-
<utopia:content/>
|
28
|
-
</div>
|
29
|
-
</body>
|
30
|
-
</html>
|
@@ -1,28 +0,0 @@
|
|
1
|
-
|
2
|
-
var url = new URL('/server/connect', window.location.href);
|
3
|
-
url.protocol = url.protocol.replace('http', 'ws');
|
4
|
-
|
5
|
-
console.log("Connecting to server", url);
|
6
|
-
var server = new WebSocket(url.href);
|
7
|
-
console.log("Connected to", server);
|
8
|
-
|
9
|
-
server.onopen = function(event) {
|
10
|
-
chat.onkeypress = function(event) {
|
11
|
-
if (event.keyCode == 13) {
|
12
|
-
server.send(JSON.stringify({text: chat.value}));
|
13
|
-
|
14
|
-
chat.value = "";
|
15
|
-
}
|
16
|
-
}
|
17
|
-
};
|
18
|
-
|
19
|
-
server.onmessage = function(event) {
|
20
|
-
console.log("Got message", event);
|
21
|
-
|
22
|
-
var message = JSON.parse(event.data);
|
23
|
-
|
24
|
-
var pre = document.createElement('pre');
|
25
|
-
pre.innerText = message.text;
|
26
|
-
|
27
|
-
response.appendChild(pre);
|
28
|
-
};
|
@@ -1,26 +0,0 @@
|
|
1
|
-
|
2
|
-
prepend Actions
|
3
|
-
|
4
|
-
require 'async/websocket/adapters/rack'
|
5
|
-
require 'set'
|
6
|
-
|
7
|
-
$connections = Set.new
|
8
|
-
|
9
|
-
on 'connect' do |request|
|
10
|
-
response = Async::WebSocket::Adapters::Rack.open(request.env) do |connection|
|
11
|
-
$connections << connection
|
12
|
-
|
13
|
-
while message = connection.read
|
14
|
-
$connections.each do |connection|
|
15
|
-
puts "Server sending message: #{message.inspect}"
|
16
|
-
connection.write(message)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
ensure
|
20
|
-
$connections.delete(connection)
|
21
|
-
end
|
22
|
-
|
23
|
-
Async.logger.info(self, request, response)
|
24
|
-
|
25
|
-
respond?(response)
|
26
|
-
end
|
Binary file
|
@@ -1,205 +0,0 @@
|
|
1
|
-
|
2
|
-
html {
|
3
|
-
font-family: "PT Sans", Verdana, Helvetica, Arial, sans-serif;
|
4
|
-
font-size: 16px;
|
5
|
-
}
|
6
|
-
|
7
|
-
pre {
|
8
|
-
tab-size: 2;
|
9
|
-
}
|
10
|
-
|
11
|
-
@media (min-width: 40em) {
|
12
|
-
html {
|
13
|
-
font-size: 18px;
|
14
|
-
}
|
15
|
-
|
16
|
-
pre {
|
17
|
-
tab-size: 4;
|
18
|
-
}
|
19
|
-
}
|
20
|
-
|
21
|
-
@media (min-width: 80em) {
|
22
|
-
html {
|
23
|
-
font-size: 20px;
|
24
|
-
}
|
25
|
-
|
26
|
-
pre {
|
27
|
-
tab-size: 4;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
body {
|
32
|
-
padding: 0;
|
33
|
-
margin: 0;
|
34
|
-
|
35
|
-
background-color: #fafafa;
|
36
|
-
}
|
37
|
-
|
38
|
-
body > header {
|
39
|
-
margin: 1rem 0 1rem 0;
|
40
|
-
|
41
|
-
background-color: white;
|
42
|
-
|
43
|
-
background-image: url(utopia-background.svg);
|
44
|
-
|
45
|
-
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
|
46
|
-
}
|
47
|
-
|
48
|
-
body > header img {
|
49
|
-
display: block;
|
50
|
-
margin: auto;
|
51
|
-
height: 4rem;
|
52
|
-
}
|
53
|
-
|
54
|
-
p, ul, ol {
|
55
|
-
color: #555;
|
56
|
-
}
|
57
|
-
|
58
|
-
p strong {
|
59
|
-
color: #222;
|
60
|
-
}
|
61
|
-
|
62
|
-
h1, h2, h3, h4, h5, h6 {
|
63
|
-
margin: 2rem 1rem 1rem 1rem;
|
64
|
-
color: #4E8DD9;
|
65
|
-
}
|
66
|
-
|
67
|
-
h1 {
|
68
|
-
margin-bottom: 4rem;
|
69
|
-
}
|
70
|
-
|
71
|
-
h2 {
|
72
|
-
margin-top: 6rem;
|
73
|
-
}
|
74
|
-
|
75
|
-
img {
|
76
|
-
border: none;
|
77
|
-
}
|
78
|
-
|
79
|
-
a {
|
80
|
-
color: #33a;
|
81
|
-
}
|
82
|
-
|
83
|
-
a:hover {
|
84
|
-
color: #55c;
|
85
|
-
}
|
86
|
-
|
87
|
-
p, ul, ol, dl, h3 {
|
88
|
-
margin: 2rem;
|
89
|
-
}
|
90
|
-
|
91
|
-
li {
|
92
|
-
margin: 0.2rem;
|
93
|
-
}
|
94
|
-
|
95
|
-
li > ul, li > ol {
|
96
|
-
margin: 0;
|
97
|
-
}
|
98
|
-
|
99
|
-
pre {
|
100
|
-
overflow: auto;
|
101
|
-
|
102
|
-
padding: 1rem 2rem;
|
103
|
-
font-size: 0.8rem;
|
104
|
-
|
105
|
-
border-top: 1px solid #ccc;
|
106
|
-
border-bottom: 1px solid #ccc;
|
107
|
-
|
108
|
-
background-color: #eee;
|
109
|
-
}
|
110
|
-
|
111
|
-
h3 {
|
112
|
-
border-bottom: 1px solid #ccf;
|
113
|
-
}
|
114
|
-
|
115
|
-
ul {
|
116
|
-
margin-bottom: 1rem;
|
117
|
-
}
|
118
|
-
|
119
|
-
h2, h3, h4, h5, h6 {
|
120
|
-
font-weight: normal;
|
121
|
-
}
|
122
|
-
|
123
|
-
body.front h1 {
|
124
|
-
font-weight: normal;
|
125
|
-
font-size: 300%;
|
126
|
-
color: #F89432;
|
127
|
-
|
128
|
-
text-align: center;
|
129
|
-
}
|
130
|
-
|
131
|
-
footer {
|
132
|
-
text-align: right;
|
133
|
-
margin: 2rem;
|
134
|
-
font-size: 0.65rem;
|
135
|
-
color: #aaa;
|
136
|
-
}
|
137
|
-
|
138
|
-
nav {
|
139
|
-
position: absolute;
|
140
|
-
margin: 2.5rem;
|
141
|
-
font-size: 0.8rem;
|
142
|
-
color: #aaa;
|
143
|
-
}
|
144
|
-
|
145
|
-
section.features {
|
146
|
-
display: flex;
|
147
|
-
flex-wrap: wrap;
|
148
|
-
justify-content: space-around;
|
149
|
-
|
150
|
-
margin: 1rem;
|
151
|
-
}
|
152
|
-
|
153
|
-
section.features > div {
|
154
|
-
box-sizing: border-box;
|
155
|
-
|
156
|
-
flex-basis: 20rem;
|
157
|
-
flex-grow: 1;
|
158
|
-
|
159
|
-
color: #171e42;
|
160
|
-
margin: 1rem;
|
161
|
-
padding: 1rem;
|
162
|
-
|
163
|
-
padding-left: 3rem;
|
164
|
-
|
165
|
-
position: relative;
|
166
|
-
}
|
167
|
-
|
168
|
-
section.features > div i {
|
169
|
-
position: absolute;
|
170
|
-
left: 0rem;
|
171
|
-
|
172
|
-
font-size: 1.5rem;
|
173
|
-
text-align: center;
|
174
|
-
|
175
|
-
width: 3rem;
|
176
|
-
color: #fafafa;
|
177
|
-
text-shadow: 0px 0px 1px #000;
|
178
|
-
}
|
179
|
-
|
180
|
-
section.features p {
|
181
|
-
margin: 0;
|
182
|
-
maring-bottom: 1rem;
|
183
|
-
font-size: 80%;
|
184
|
-
}
|
185
|
-
|
186
|
-
section.features h2 {
|
187
|
-
margin: 0;
|
188
|
-
font-size: 1.1rem;
|
189
|
-
padding: 0;
|
190
|
-
}
|
191
|
-
|
192
|
-
form fieldset {
|
193
|
-
border: 0;
|
194
|
-
}
|
195
|
-
|
196
|
-
form fieldset textarea {
|
197
|
-
box-sizing: border-box;
|
198
|
-
|
199
|
-
width: 100%;
|
200
|
-
height: 10rem;
|
201
|
-
}
|
202
|
-
|
203
|
-
form fieldset.footer {
|
204
|
-
text-align: right;
|
205
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 10 80" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><rect x="0" y="0" width="10" height="56" style="fill:#f79433;"/><rect x="0" y="56" width="10" height="24" style="fill:#4e8dd8;"/></svg>
|
@@ -1 +0,0 @@
|
|
1
|
-
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 420 80" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><g><rect x="0" y="0" width="420" height="56" style="fill:#f79433;"/><rect x="0" y="56" width="420" height="24" style="fill:#4e8dd8;"/><g><path d="M75.145,70.819c2.37,-3.097 4.173,-6.921 5.111,-11.365c0.91,-4.318 1.498,-9.261 1.498,-14.692l0,-44.762l-62.754,0l0,44.762c0,2.628 0.244,5.333 0.407,8.035c0.168,2.782 0.674,5.515 1.345,8.118c0.68,2.644 1.739,5.173 3.067,7.517c1.363,2.405 3.263,4.526 5.609,6.303c2.319,1.755 5.245,3.163 8.677,4.172c1.617,0.478 3.416,1.093 5.354,1.093l13.856,0c3.071,0 5.797,-1.058 8.131,-2.001c4.042,-1.631 7.305,-4.049 9.699,-7.18Z" style="fill:#fff;fill-rule:nonzero;"/><path d="M151.481,18.701l0,-18.701l-62.754,-0.022l0,18.723l22.246,0l0.02,61.299l17.93,0l-0.02,-61.299l22.578,0Z" style="fill:#fff;fill-rule:nonzero;"/><path d="M229.926,39.999c0,-22.051 -16.979,-39.992 -37.852,-39.992c-20.872,0 -37.851,17.942 -37.851,39.992c0,22.054 16.979,39.994 37.851,39.994c20.873,0 37.852,-17.94 37.852,-39.994Z" style="fill:#fff;fill-rule:nonzero;"/><path d="M269.238,50.909c9.717,0 17.181,-2.066 22.183,-6.395c5.087,-4.399 7.667,-10.942 7.667,-19.575c0,-3.257 -0.393,-5.962 -1.167,-8.476c-0.778,-2.528 -1.883,-4.934 -3.281,-6.814c-1.401,-1.882 -3.098,-3.458 -5.045,-4.703c-1.895,-1.21 -4.003,-2.198 -6.264,-2.943c-2.239,-0.737 -4.64,-1.263 -7.139,-1.56c-2.464,-0.292 -5.016,-0.443 -7.587,-0.443l-29.468,0l0,80l17.93,0l0,-29.091l12.171,0Z" style="fill:#fff;fill-rule:nonzero;"/><rect x="304.879" y="0" width="17.93" height="80" style="fill:#fff;"/><path d="M362.589,0l-29.477,80l75.888,0l-31.247,-80l-15.164,0Z" style="fill:#fff;fill-rule:nonzero;"/></g></g></svg>
|
@@ -1 +0,0 @@
|
|
1
|
-
This directory is required by Apache/Phusion Passenger and contains static assets that are typically served using sendfile.
|
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
if ENV['COVERAGE']
|
3
|
-
begin
|
4
|
-
require 'simplecov'
|
5
|
-
|
6
|
-
SimpleCov.start do
|
7
|
-
add_filter "/spec/"
|
8
|
-
end
|
9
|
-
|
10
|
-
if ENV['TRAVIS']
|
11
|
-
require 'coveralls'
|
12
|
-
Coveralls.wear!
|
13
|
-
end
|
14
|
-
rescue LoadError
|
15
|
-
warn "Could not load simplecov: #{$!}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
require 'bundler/setup'
|
20
|
-
require 'utopia'
|
21
|
-
|
22
|
-
require 'async/rspec'
|
23
|
-
|
24
|
-
RSpec.configure do |config|
|
25
|
-
# Enable flags like --only-failures and --next-failure
|
26
|
-
config.example_status_persistence_file_path = '.rspec_status'
|
27
|
-
|
28
|
-
config.expect_with :rspec do |c|
|
29
|
-
c.syntax = :expect
|
30
|
-
end
|
31
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rack/test'
|
3
|
-
|
4
|
-
RSpec.shared_context "website" do
|
5
|
-
include Rack::Test::Methods
|
6
|
-
|
7
|
-
let(:rackup_path) {File.expand_path('../config.ru', __dir__)}
|
8
|
-
let(:rackup_directory) {File.dirname(rackup_path)}
|
9
|
-
|
10
|
-
let(:app) {Rack::Builder.parse_file(rackup_path).first}
|
11
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
|
2
|
-
require_relative 'website_context'
|
3
|
-
|
4
|
-
require 'falcon/server'
|
5
|
-
require 'falcon/adapters/rack'
|
6
|
-
|
7
|
-
require 'async/http/endpoint'
|
8
|
-
require 'async/websocket/client'
|
9
|
-
|
10
|
-
# Learn about best practice specs from http://betterspecs.org
|
11
|
-
RSpec.describe "my website" do
|
12
|
-
include_context "website"
|
13
|
-
|
14
|
-
it "should have an accessible front page" do
|
15
|
-
get "/"
|
16
|
-
|
17
|
-
follow_redirect!
|
18
|
-
|
19
|
-
expect(last_response.status).to be == 200
|
20
|
-
end
|
21
|
-
|
22
|
-
context "websockets" do
|
23
|
-
include_context Async::RSpec::Reactor
|
24
|
-
|
25
|
-
let(:endpoint) {Async::HTTP::Endpoint.parse("http://localhost:9282")}
|
26
|
-
let(:server) {Falcon::Server.new(Falcon::Adapters::Rack.new(app), endpoint)}
|
27
|
-
|
28
|
-
let(:hello_message) do
|
29
|
-
{
|
30
|
-
user: "test",
|
31
|
-
text: "Hello World",
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
let!(:server_task) do
|
36
|
-
server_task = reactor.async do
|
37
|
-
server.run
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
after(:each) do
|
42
|
-
server_task.stop
|
43
|
-
end
|
44
|
-
|
45
|
-
it "can connect to server" do
|
46
|
-
endpoint.connect do |socket|
|
47
|
-
connection = Async::WebSocket::Client.new(socket, "ws://localhost/server/connect")
|
48
|
-
|
49
|
-
connection.write(hello_message)
|
50
|
-
|
51
|
-
message = connection.read
|
52
|
-
expect(message).to be == hello_message
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|