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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0158791283f1da9ef7fe755bd019899508f3d647fc9f18984e2b7ef77a3074db'
4
- data.tar.gz: 22b4fcb061a87637d7c108e465e65ae3388379850a85f1f65e8661f7d1867b1c
3
+ metadata.gz: 7686aad6fd1477dbc9d869ff6da2b67177ea774d79d49851e19e96625331f9f8
4
+ data.tar.gz: 571d4a0ef3b98e7d69a4a5b77460861db96dc1b385579125fe998fd241d40993
5
5
  SHA512:
6
- metadata.gz: b6ec6a61a6b1c63545739a2dec75455a1a9a68addde791deb339f4190246e5469875f13e8fa84f45505d579073668d45dd4bdc28c833fba3f5164a8f21a4afd7
7
- data.tar.gz: f37bf0833c8c894fc5d0f71248abf4c1cac83bf4a4f6b70676d6f044217ba9ac2ccb6edc60ead20dfa53c6c8c47e872eb0db559e0c2229faf6e85f03c139c049
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 `Utopia::Controller`:
25
+ Here is how to use within `Rack`:
26
26
 
27
- on 'list' do |request|
28
- fail! unless Async::WebSocket?(request.env)
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
- Process.spawn("ls -lah", :out => write)
34
- write.close
30
+ require 'async/websocket/server'
35
31
 
36
- read.each_line do |line|
37
- connection.text(line)
38
- end
32
+ $connections = []
39
33
 
40
- connection.close
41
- end
34
+ run lambda {|env|
35
+ Async::WebSocket::Server.open(env) do |connection|
36
+ $connections << connection
42
37
 
43
- succeed!
44
- end
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(:spec) do |task|
5
- task.rspec_opts = ["--require", "simplecov"] if ENV['COVERAGE']
6
- end
4
+ RSpec::Core::RakeTask.new(:test)
7
5
 
8
- task :default => :spec
6
+ task :default => :test
@@ -35,7 +35,7 @@ Async::Reactor.run do |task|
35
35
  end
36
36
 
37
37
  while message = connection.next_message
38
- puts "Message from server: #{message.inspect}"
38
+ puts "From server: #{message.inspect}"
39
39
  end
40
40
  end
41
41
  end
@@ -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
- env['rack.hijack'].call
40
+ # https://github.com/rack/rack/blob/master/SPEC#L89-L93
41
+ peer = env['rack.hijack'].call
41
42
 
42
- connection = self.new(env, env['rack.hijack_io'])
43
+ connection = self.new(env, peer)
43
44
 
44
45
  if block_given?
45
46
  begin
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module WebSocket
23
- VERSION = "0.3.0"
23
+ VERSION = "0.4.0"
24
24
  end
25
25
  end
@@ -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, [server_address])}
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.3.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-03-14 00:00:00.000000000 Z
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