async-websocket 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -31
- data/Rakefile +2 -4
- data/{chat → examples/chat}/client.rb +1 -1
- data/{chat → examples/chat}/config.ru +1 -2
- data/lib/async/websocket/server.rb +3 -2
- data/lib/async/websocket/version.rb +1 -1
- data/spec/async/websocket/connection_spec.rb +2 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7686aad6fd1477dbc9d869ff6da2b67177ea774d79d49851e19e96625331f9f8
|
4
|
+
data.tar.gz: 571d4a0ef3b98e7d69a4a5b77460861db96dc1b385579125fe998fd241d40993
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8efc539eae9d51793916583673e14b664b142a8caa513dee77d227989d82e71c9b091ff50976edbfecb285c47deb0d51a03e91a5b5b3cf90ab31e3fc946d93fb
|
7
|
+
data.tar.gz: 1a172ec98828d65179e6a4e7e36cc155b39e7e43709244d2f57c33f4e6b643f58ac2b082d3bcfc4ffe14835349cfca02bc54f5ab4dce5231544f964049342357
|
data/README.md
CHANGED
@@ -22,45 +22,31 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
Here is how to use within `
|
25
|
+
Here is how to use within `Rack`:
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
Async::WebSocket.open(request.env) do |connection|
|
31
|
-
read, write = IO.pipe
|
27
|
+
```ruby
|
28
|
+
#!/usr/bin/env falcon serve --concurrency 1 -c
|
32
29
|
|
33
|
-
|
34
|
-
write.close
|
30
|
+
require 'async/websocket/server'
|
35
31
|
|
36
|
-
|
37
|
-
connection.text(line)
|
38
|
-
end
|
32
|
+
$connections = []
|
39
33
|
|
40
|
-
|
41
|
-
|
34
|
+
run lambda {|env|
|
35
|
+
Async::WebSocket::Server.open(env) do |connection|
|
36
|
+
$connections << connection
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
`connection` is an instance of [`WebSocket::Driver`][1].
|
47
|
-
|
48
|
-
[1]: https://github.com/faye/websocket-driver-ruby
|
49
|
-
|
50
|
-
If you want to handle incoming messages, you must listen for these and then handle them:
|
51
|
-
|
52
|
-
on 'echo' do |request|
|
53
|
-
fail! unless Async::WebSocket?(request.env)
|
54
|
-
|
55
|
-
Async::WebSocket.open(request.env) do |connection|
|
56
|
-
connection.on(:message) do |event|
|
57
|
-
connection.text(event.data)
|
58
|
-
connection.close
|
38
|
+
while message = connection.next_message
|
39
|
+
$connections.each do |connection|
|
40
|
+
connection.send_message(message)
|
59
41
|
end
|
60
42
|
end
|
61
|
-
|
62
|
-
succeed!
|
63
43
|
end
|
44
|
+
|
45
|
+
[200, {}, ["Hello World"]]
|
46
|
+
}
|
47
|
+
```
|
48
|
+
|
49
|
+
And [here is a client program](example/client.rb) which can read input from `stdin` and send messages to the server.
|
64
50
|
|
65
51
|
## Contributing
|
66
52
|
|
data/Rakefile
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rspec/core/rake_task"
|
3
3
|
|
4
|
-
RSpec::Core::RakeTask.new(:
|
5
|
-
task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
|
6
|
-
end
|
4
|
+
RSpec::Core::RakeTask.new(:test)
|
7
5
|
|
8
|
-
task :default => :
|
6
|
+
task :default => :test
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'async/websocket/server'
|
4
4
|
|
5
|
-
Message = Struct.new(:user, :contents, :created_at)
|
6
|
-
|
7
5
|
$connections = []
|
8
6
|
|
9
7
|
run lambda {|env|
|
@@ -17,5 +15,6 @@ run lambda {|env|
|
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
18
|
+
Async::Task.current.sleep(0.1)
|
20
19
|
[200, {}, ["Hello World"]]
|
21
20
|
}
|
@@ -37,9 +37,10 @@ module Async
|
|
37
37
|
|
38
38
|
def self.open(env)
|
39
39
|
if ::WebSocket::Driver.websocket?(env)
|
40
|
-
|
40
|
+
# https://github.com/rack/rack/blob/master/SPEC#L89-L93
|
41
|
+
peer = env['rack.hijack'].call
|
41
42
|
|
42
|
-
connection = self.new(env,
|
43
|
+
connection = self.new(env, peer)
|
43
44
|
|
44
45
|
if block_given?
|
45
46
|
begin
|
@@ -23,13 +23,14 @@ require 'async/websocket/client'
|
|
23
23
|
|
24
24
|
require 'rack/test'
|
25
25
|
require 'falcon/server'
|
26
|
+
require 'falcon/adapters/rack'
|
26
27
|
|
27
28
|
RSpec.describe Async::WebSocket::Connection do
|
28
29
|
include_context Async::RSpec::Reactor
|
29
30
|
|
30
31
|
let(:server_address) {Async::IO::Endpoint.tcp('0.0.0.0', 9000)}
|
31
32
|
let(:app) {Rack::Builder.parse_file(File.expand_path('../connection_spec.ru', __FILE__)).first}
|
32
|
-
let(:server) {Falcon::Server.new(app,
|
33
|
+
let(:server) {Falcon::Server.new(Falcon::Adapters::Rack.new(app), server_address)}
|
33
34
|
|
34
35
|
it "should connect to the websocket server" do
|
35
36
|
server_task = reactor.async do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-websocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-driver
|
@@ -122,8 +122,8 @@ files:
|
|
122
122
|
- README.md
|
123
123
|
- Rakefile
|
124
124
|
- async-websocket.gemspec
|
125
|
-
- chat/client.rb
|
126
|
-
- chat/config.ru
|
125
|
+
- examples/chat/client.rb
|
126
|
+
- examples/chat/config.ru
|
127
127
|
- lib/async/websocket.rb
|
128
128
|
- lib/async/websocket/client.rb
|
129
129
|
- lib/async/websocket/connection.rb
|