opal-drb 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: c71959cd30828a5ce4f4e195aa305cc6b39d0ee8
4
- data.tar.gz: b92b60c638453174af654dfefa2a56a5f0e76971
3
+ metadata.gz: b15bcbd00eb42ad9a6e0bbd97eff77a0cf839d67
4
+ data.tar.gz: 1e1c07dddf6707a8f1aee7d102b90a091918a027
5
5
  SHA512:
6
- metadata.gz: 6f0ddc332aba0a9625f3c2dd9ecfa625489c014f89eb3d79f8cef1256be277efe29cd43c1f89df6fffeaa557f8691891384001a9a5cabc3ec1bcb2e7eabda03e
7
- data.tar.gz: a368f158fb6aec43bdf87ccd1bad0bf58c7b975d4825f24ba7b103b2f5330843a1260760c85e5579871f3a278ab8ee7594e6a4c5b18fbf7571f3012339cb71d6
6
+ metadata.gz: fbae91fd2584a7d00a86b888ef1066e66cd170108d5ef10cdeb3ff87cb37f6bf40a2a38927e57bfb023cfe34a7162cc64cdf395b5ddc058c88f7cb7dca0b1eac
7
+ data.tar.gz: faffca7fce4a793ea4a1109cf1dadb582d5332345113f5612917c12d14e0653fd4afbd4a754258fdefb38b51a15d2d05545862dfcab775ff361d3912a216252a
@@ -1,15 +1,17 @@
1
1
  module DRb
2
2
  class DRbServer
3
- attr_reader :uri
4
-
5
3
  def initialize(uri)
6
- @uri = uri
7
- @protocol = DRbProtocol.open_server(@uri)
4
+ @protocol = DRbProtocol.open_server(uri)
8
5
  run
9
6
  end
10
7
 
8
+ def uri
9
+ @protocol.uri
10
+ end
11
+
11
12
  def run
12
13
  @protocol.accept do |client|
14
+ run
13
15
  begin
14
16
  succ = false
15
17
  invoke_method = InvokeMethod.new(self, client)
@@ -1,5 +1,5 @@
1
1
  module Opal
2
2
  module DRb
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require 'native'
2
2
  require 'promise'
3
+ require 'securerandom'
3
4
 
4
5
  class ArrayBuffer
5
6
  include Native
@@ -29,11 +30,15 @@ class WebSocket
29
30
  end
30
31
 
31
32
  def onmessage
32
- add_event_listener('message') {|event| yield MessageEvent.new(event) }
33
+ add_event_listener('message') {|event| yield MessageEvent.new(event) if self.open? }
33
34
  end
34
35
 
35
36
  def onopen
36
- add_event_listener('open') {|event| yield MessageEvent.new(event) }
37
+ add_event_listener('open') {|event| yield MessageEvent.new(event) if self.open? }
38
+ end
39
+
40
+ def open?
41
+ `self.native.readyState == 1`
37
42
  end
38
43
 
39
44
  alias_native :close
@@ -87,6 +92,7 @@ module DRb
87
92
  raise(DRbBadScheme, uri) unless uri =~ /^ws:/
88
93
  raise(DRbBadURI, 'can\'t parse uri:' + uri)
89
94
  end
95
+
90
96
  Server.new(uri, config)
91
97
  end
92
98
 
@@ -94,17 +100,16 @@ module DRb
94
100
  attr_reader :uri
95
101
 
96
102
  def initialize(uri, config)
97
- @uri = uri
103
+ @uri = "#{uri}/#{SecureRandom.uuid}"
98
104
  @config = config
99
105
  end
100
106
 
101
107
  def close
102
- u = URI.parse(@uri)
103
- RackApp.close("#{u.host}:#{u.port}")
108
+ @ws.close
104
109
  end
105
110
 
106
111
  def accept
107
- ws = ::WebSocket.new(uri)
112
+ ws = ::WebSocket.new(@uri)
108
113
  ws.onmessage do |event|
109
114
  stream = StrStream.new(event.data.to_s)
110
115
  server_side = ServerSide.new(stream, @config, uri)
@@ -189,11 +194,14 @@ module DRb
189
194
  end
190
195
 
191
196
  promise.resolve reply_stream
197
+
198
+ @ws.close
192
199
  end
193
200
 
194
201
  @ws.onopen do
195
202
  @ws.send(`new Uint8Array(#{data.bytes.each_slice(2).map(&:first)}).buffer`)
196
203
  end
204
+
197
205
  promise
198
206
  end
199
207
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-drb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - youchan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-15 00:00:00.000000000 Z
11
+ date: 2017-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: opal