opal-drb 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opal/drb/drb_conn.rb +1 -1
- data/lib/opal/drb/version.rb +1 -1
- data/lib/opal/drb/websocket.rb +24 -24
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54baa5953deb2f759b8ddeabe50f9e0d7f3e2e7c69fbb446b208ed59514f11c1
|
4
|
+
data.tar.gz: 87cb35cfb700ade0d9fb180def4811628494a4eb9fc32ee40f7f30e29e39d247
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcadd165c9f20a2c80ede70c7d3b95bbed9799730aa1be91f9d9b3d3123375abe4650c002d6415f4d19a17a39a6eadd3009f3c55a8d07f2d087c0f7f1cbeefa7
|
7
|
+
data.tar.gz: 2e518ce27d32546f4593fb9ba0ef3da705748df6d6f1766494d54822ab248e8e5b80b4029be522309005054cd5361441f7e35568d35ae943a3c6b0f4d669fb44
|
data/lib/opal/drb/drb_conn.rb
CHANGED
data/lib/opal/drb/version.rb
CHANGED
data/lib/opal/drb/websocket.rb
CHANGED
@@ -90,6 +90,14 @@ module DRb
|
|
90
90
|
def initialize(uri, ws)
|
91
91
|
@uri = uri
|
92
92
|
@ws = ws
|
93
|
+
@handlers = {}
|
94
|
+
|
95
|
+
ws.onmessage do |event|
|
96
|
+
message_data = event.data.to_s
|
97
|
+
sender_id = message_data.slice(0, 36)
|
98
|
+
message = message_data.slice(36, message_data.length - 36)
|
99
|
+
@handlers.delete(sender_id).call(message)
|
100
|
+
end
|
93
101
|
end
|
94
102
|
|
95
103
|
def self.open(uri)
|
@@ -107,6 +115,21 @@ module DRb
|
|
107
115
|
self.new(uri, ws)
|
108
116
|
end
|
109
117
|
|
118
|
+
def send(data, &block)
|
119
|
+
sender_id = SecureRandom.uuid
|
120
|
+
@handlers[sender_id] = block
|
121
|
+
byte_data = sender_id.bytes.each_slice(2).map(&:first)
|
122
|
+
byte_data += data.bytes.each_slice(2).map(&:first)
|
123
|
+
|
124
|
+
if @ws.connecting?
|
125
|
+
@ws.onopen do
|
126
|
+
@ws.send(`new Uint8Array(#{byte_data}).buffer`)
|
127
|
+
end
|
128
|
+
else
|
129
|
+
@ws.send(`new Uint8Array(#{byte_data}).buffer`)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
110
133
|
def [](uri)
|
111
134
|
@sockets[uri].ws
|
112
135
|
end
|
@@ -201,7 +224,6 @@ module DRb
|
|
201
224
|
@config = config
|
202
225
|
@msg = DRbMessage.new(@config)
|
203
226
|
@req_stream = stream
|
204
|
-
@sender_id = SecureRandom.uuid
|
205
227
|
end
|
206
228
|
|
207
229
|
def close
|
@@ -237,7 +259,6 @@ module DRb
|
|
237
259
|
@res = nil
|
238
260
|
@config = config
|
239
261
|
@msg = DRbMessage.new(@config)
|
240
|
-
@sender_id = SecureRandom.uuid
|
241
262
|
end
|
242
263
|
|
243
264
|
def alive?
|
@@ -259,15 +280,7 @@ module DRb
|
|
259
280
|
|
260
281
|
def send(uri, data)
|
261
282
|
promise = Promise.new
|
262
|
-
|
263
|
-
message_data = event.data.to_s
|
264
|
-
sender_id = message_data.slice(0, 36)
|
265
|
-
message = message_data.slice(36, message_data.length - 36)
|
266
|
-
|
267
|
-
unless sender_id == @sender_id
|
268
|
-
next
|
269
|
-
end
|
270
|
-
|
283
|
+
@pool.send(data) do |message|
|
271
284
|
reply_stream = StrStream.new
|
272
285
|
reply_stream.write(message.to_s)
|
273
286
|
|
@@ -276,20 +289,7 @@ module DRb
|
|
276
289
|
end
|
277
290
|
|
278
291
|
promise.resolve reply_stream
|
279
|
-
@pool.ws.off(event_handler)
|
280
292
|
end
|
281
|
-
@pool.ws.onmessage(&event_handler)
|
282
|
-
byte_data = @sender_id.bytes.each_slice(2).map(&:first)
|
283
|
-
byte_data += data.bytes.each_slice(2).map(&:first)
|
284
|
-
|
285
|
-
if @pool.ws.connecting?
|
286
|
-
@pool.ws.onopen do
|
287
|
-
@pool.ws.send(`new Uint8Array(#{byte_data}).buffer`)
|
288
|
-
end
|
289
|
-
else
|
290
|
-
@pool.ws.send(`new Uint8Array(#{byte_data}).buffer`)
|
291
|
-
end
|
292
|
-
|
293
293
|
promise
|
294
294
|
end
|
295
295
|
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.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- youchan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -119,8 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
|
-
|
123
|
-
rubygems_version: 2.7.6
|
122
|
+
rubygems_version: 3.0.1
|
124
123
|
signing_key:
|
125
124
|
specification_version: 4
|
126
125
|
summary: A dRuby implementation for Opal
|