async-websocket 0.6.1 → 0.7.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/.editorconfig +2 -0
- data/README.md +38 -3
- data/async-websocket.gemspec +1 -1
- data/examples/chat/client.rb +2 -2
- data/examples/middleware/client.rb +2 -2
- data/lib/async/websocket/client.rb +11 -3
- data/lib/async/websocket/version.rb +1 -1
- data/spec/async/websocket/client_spec.rb +32 -0
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da0bf747ee0c56a69b828547451fc478169ee13b8cf181a15af6ba5b7ab73b03
|
4
|
+
data.tar.gz: 4bb105f0a98f8b4f39020aa0882745d8915b1bec7155a5fb410f3ae985d06503
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cb039babe87b956995754dbecf8ce5b93924359b86ff5b51676fa5b9bdc1a7f0f88a85b042e04cb52d8aac900991ed3ea49eb936c6ef66760f7a7179e4d077d
|
7
|
+
data.tar.gz: b6fe79b03396ff4b748436cbdaad3e5430b1890ec602c3cb1373e7a1ba04f84d4afdd625007991532aea1fa184275554e97fb4a27d1c6e70ae46c598560257c9
|
data/.editorconfig
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,44 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
There are [examples](examples/) which include:
|
26
|
+
|
27
|
+
- [A command line chat client and application server](examples/chat/client.rb) which can read input from `stdin` and send messages to the server.
|
28
|
+
- [A utopia-based web application](examples/utopia) which uses a JavaScript client to connect to a web application server.
|
29
|
+
|
30
|
+
### Client Side with Async
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
#!/usr/bin/env ruby
|
34
|
+
|
35
|
+
require 'async'
|
36
|
+
require 'async/io/stream'
|
37
|
+
require 'async/http/url_endpoint'
|
38
|
+
require 'async/websocket/client'
|
39
|
+
|
40
|
+
USER = ARGV.pop || "anonymous"
|
41
|
+
URL = ARGV.pop || "ws://localhost:9292"
|
42
|
+
|
43
|
+
Async do |task|
|
44
|
+
endpoint = Async::HTTP::URLEndpoint.parse(URL)
|
45
|
+
headers = {'token' => 'wubalubadubdub'}
|
46
|
+
|
47
|
+
endpoint.connect do |socket|
|
48
|
+
connection = Async::WebSocket::Client.new(socket, URL, headers)
|
49
|
+
|
50
|
+
connection.send_message({
|
51
|
+
user: USER,
|
52
|
+
status: "connected",
|
53
|
+
})
|
54
|
+
|
55
|
+
while message = connection.next_message
|
56
|
+
puts message.inspect
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
### Server Side with Rack & Falcon
|
26
63
|
|
27
64
|
```ruby
|
28
65
|
#!/usr/bin/env falcon serve --concurrency 1 -c
|
@@ -46,8 +83,6 @@ run lambda {|env|
|
|
46
83
|
}
|
47
84
|
```
|
48
85
|
|
49
|
-
And [here is a client program](examples/chat/client.rb) which can read input from `stdin` and send messages to the server.
|
50
|
-
|
51
86
|
## Contributing
|
52
87
|
|
53
88
|
1. Fork it
|
data/async-websocket.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "async-rspec"
|
23
23
|
spec.add_development_dependency "falcon", "~> 0.17.0"
|
24
24
|
|
25
|
-
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "bundler"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.6"
|
27
27
|
spec.add_development_dependency "rake"
|
28
28
|
end
|
data/examples/chat/client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'async
|
3
|
+
require 'async'
|
4
4
|
require 'async/io/stream'
|
5
5
|
require 'async/http/url_endpoint'
|
6
6
|
require 'async/websocket/client'
|
@@ -8,7 +8,7 @@ require 'async/websocket/client'
|
|
8
8
|
USER = ARGV.pop || "anonymous"
|
9
9
|
URL = ARGV.pop || "ws://localhost:9292"
|
10
10
|
|
11
|
-
Async
|
11
|
+
Async do |task|
|
12
12
|
stdin = Async::IO::Stream.new(
|
13
13
|
Async::IO::Generic.new($stdin)
|
14
14
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'async
|
3
|
+
require 'async'
|
4
4
|
require 'async/io/stream'
|
5
5
|
require 'async/http/url_endpoint'
|
6
6
|
require 'async/websocket/client'
|
@@ -8,7 +8,7 @@ require 'async/websocket/client'
|
|
8
8
|
USER = ARGV.pop || "anonymous"
|
9
9
|
URL = ARGV.pop || "ws://localhost:9292"
|
10
10
|
|
11
|
-
Async
|
11
|
+
Async do |task|
|
12
12
|
stdin = Async::IO::Stream.new(
|
13
13
|
Async::IO::Generic.new($stdin)
|
14
14
|
)
|
@@ -24,10 +24,18 @@ module Async
|
|
24
24
|
module WebSocket
|
25
25
|
# This is a basic synchronous websocket client:
|
26
26
|
class Client < Connection
|
27
|
-
def initialize(socket, url = "ws://.")
|
27
|
+
def initialize(socket, url = "ws://.", headers = {})
|
28
28
|
@url = url
|
29
|
-
|
30
|
-
super socket,
|
29
|
+
|
30
|
+
super socket, build_client(headers)
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_client(headers)
|
34
|
+
::WebSocket::Driver.client(self).tap do |client|
|
35
|
+
headers.each do |key, value|
|
36
|
+
client.set_header(key, value)
|
37
|
+
end
|
38
|
+
end
|
31
39
|
end
|
32
40
|
end
|
33
41
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "async/websocket/client"
|
2
|
+
|
3
|
+
RSpec.describe Async::WebSocket::Client do
|
4
|
+
let(:client_double) {
|
5
|
+
instance_double(WebSocket::Driver::Client, on: nil, start: nil)
|
6
|
+
}
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(WebSocket::Driver).to receive(:client).and_return(client_double)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets headers on the driver" do
|
13
|
+
headers = {
|
14
|
+
"Foo" => "Bar",
|
15
|
+
"Baz" => "Qux"
|
16
|
+
}
|
17
|
+
|
18
|
+
headers.each do |key, value|
|
19
|
+
expect(client_double).to receive(:set_header).with(key, value)
|
20
|
+
end
|
21
|
+
|
22
|
+
described_class.new(double(write: nil), "", headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
context "without passing headers" do
|
26
|
+
it "does not fail" do
|
27
|
+
expect {
|
28
|
+
described_class.new(double(write: nil))
|
29
|
+
}.not_to raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
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.7.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:
|
11
|
+
date: 2019-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: websocket-driver
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- lib/async/websocket/connection.rb
|
167
167
|
- lib/async/websocket/server.rb
|
168
168
|
- lib/async/websocket/version.rb
|
169
|
+
- spec/async/websocket/client_spec.rb
|
169
170
|
- spec/async/websocket/connection_spec.rb
|
170
171
|
- spec/async/websocket/connection_spec.ru
|
171
172
|
- spec/spec_helper.rb
|
@@ -188,12 +189,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
189
|
- !ruby/object:Gem::Version
|
189
190
|
version: '0'
|
190
191
|
requirements: []
|
191
|
-
|
192
|
-
rubygems_version: 2.7.6
|
192
|
+
rubygems_version: 3.0.2
|
193
193
|
signing_key:
|
194
194
|
specification_version: 4
|
195
195
|
summary: An async websocket library on top of websocket-driver.
|
196
196
|
test_files:
|
197
|
+
- spec/async/websocket/client_spec.rb
|
197
198
|
- spec/async/websocket/connection_spec.rb
|
198
199
|
- spec/async/websocket/connection_spec.ru
|
199
200
|
- spec/spec_helper.rb
|