isomorfeus-transport 2.5.5 → 22.9.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isomorfeus/core_ext/hash/deep_merge.rb +34 -0
- data/lib/isomorfeus/core_ext/kernel.rb +56 -0
- data/lib/isomorfeus/core_ext/object/deep_dup.rb +53 -0
- data/lib/isomorfeus/core_ext/object/duplicable.rb +60 -0
- data/lib/isomorfeus/transport/compressor_rack.rb +1 -1
- data/lib/isomorfeus/transport/config.rb +37 -0
- data/lib/isomorfeus/transport/rack_middleware.rb +16 -9
- data/lib/isomorfeus/transport/request_agent.rb +1 -0
- data/lib/isomorfeus/transport/server_socket_processor.rb +13 -1
- data/lib/isomorfeus/transport/version.rb +1 -1
- data/lib/isomorfeus/transport.rb +45 -38
- data/lib/isomorfeus-transport.rb +25 -16
- data/lib/lucid_channel.rb +103 -0
- data/lib/lucid_handler.rb +25 -0
- metadata +40 -90
- data/lib/isomorfeus/transport/handler/authentication_handler.rb +0 -55
- data/lib/isomorfeus/transport/imports.rb +0 -10
- data/lib/isomorfeus/transport/ssr_login.rb +0 -30
- data/lib/lucid_channel/base.rb +0 -8
- data/lib/lucid_channel/mixin.rb +0 -105
- data/lib/lucid_handler/base.rb +0 -8
- data/lib/lucid_handler/mixin.rb +0 -27
- data/node_modules/.package-lock.json +0 -27
- data/node_modules/ws/LICENSE +0 -19
- data/node_modules/ws/README.md +0 -489
- data/node_modules/ws/browser.js +0 -8
- data/node_modules/ws/index.js +0 -13
- data/node_modules/ws/lib/buffer-util.js +0 -126
- data/node_modules/ws/lib/constants.js +0 -12
- data/node_modules/ws/lib/event-target.js +0 -266
- data/node_modules/ws/lib/extension.js +0 -203
- data/node_modules/ws/lib/limiter.js +0 -55
- data/node_modules/ws/lib/permessage-deflate.js +0 -511
- data/node_modules/ws/lib/receiver.js +0 -618
- data/node_modules/ws/lib/sender.js +0 -478
- data/node_modules/ws/lib/stream.js +0 -159
- data/node_modules/ws/lib/subprotocol.js +0 -62
- data/node_modules/ws/lib/validation.js +0 -124
- data/node_modules/ws/lib/websocket-server.js +0 -488
- data/node_modules/ws/lib/websocket.js +0 -1264
- data/node_modules/ws/package.json +0 -61
- data/node_modules/ws/wrapper.mjs +0 -8
- data/package.json +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5c65f1c3f946008bde44c8e04b002cb6b51e5b9a0df8137d16bab6a72948c7c
|
4
|
+
data.tar.gz: 993ea2712d8cf4f825563020155f40175d63b5678e917aaa04ac72efa9a28274
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7129f7c878945e52e82887355b7561c24dfbf418b647285f58676494ba4939c8fd5230a4a9afd808bf42e8cb7e03fc5103825ac33a838fdf2e16c03925f19373
|
7
|
+
data.tar.gz: 4dffaf95a186c9c46a8593074aff9dcc6e14daa593b75c195d86469f08340f9876a835ff212c74dde1d920a6a1bb0d4772e14a3170b15354073ec6ef8dc4daa2
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# originally taken from: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
5
|
+
#
|
6
|
+
# h1 = { a: true, b: { c: [1, 2, 3] } }
|
7
|
+
# h2 = { a: false, b: { x: [3, 4, 5] } }
|
8
|
+
#
|
9
|
+
# h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
10
|
+
#
|
11
|
+
# Like with Hash#merge in the standard library, a block can be provided
|
12
|
+
# to merge values:
|
13
|
+
#
|
14
|
+
# h1 = { a: 100, b: 200, c: { c1: 100 } }
|
15
|
+
# h2 = { b: 250, c: { c1: 200 } }
|
16
|
+
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
17
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
18
|
+
def deep_merge(other_hash, &block)
|
19
|
+
dup.deep_merge!(other_hash, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Same as +deep_merge+, but modifies +self+.
|
23
|
+
def deep_merge!(other_hash, &block)
|
24
|
+
merge!(other_hash) do |key, this_val, other_val|
|
25
|
+
if this_val.is_a?(Hash) && other_val.is_a?(Hash)
|
26
|
+
this_val.deep_merge(other_val, &block)
|
27
|
+
elsif block_given?
|
28
|
+
block.call(key, this_val, other_val)
|
29
|
+
else
|
30
|
+
other_val
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Kernel
|
2
|
+
def promise(&block)
|
3
|
+
p = Promise.new
|
4
|
+
|
5
|
+
begin
|
6
|
+
result = block.call
|
7
|
+
return p.resolve(result) if result
|
8
|
+
rescue => e
|
9
|
+
return p.reject(e)
|
10
|
+
end
|
11
|
+
|
12
|
+
pr = proc do
|
13
|
+
begin
|
14
|
+
res = block.call
|
15
|
+
res ? p.resolve(res) : after(10, &pr)
|
16
|
+
rescue => e
|
17
|
+
p.reject(e)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after(10, &pr)
|
22
|
+
p
|
23
|
+
end
|
24
|
+
|
25
|
+
if RUBY_ENGINE == 'opal'
|
26
|
+
def on_browser?; true; end
|
27
|
+
def on_desktop?; false; end
|
28
|
+
def on_mobile?; false; end
|
29
|
+
def on_tablet?; false; end
|
30
|
+
def on_tv?; false; end
|
31
|
+
def on_server?; false; end
|
32
|
+
|
33
|
+
def after(time_ms, &block)
|
34
|
+
`setTimeout(#{block.to_n}, time_ms)`
|
35
|
+
end
|
36
|
+
|
37
|
+
# TODO remove before release
|
38
|
+
%x{
|
39
|
+
Opal.s = function() {
|
40
|
+
return Opal.Isomorfeus.store.$get_state().$to_n();
|
41
|
+
}
|
42
|
+
}
|
43
|
+
else
|
44
|
+
def on_browser?; false; end
|
45
|
+
def on_desktop?; false; end
|
46
|
+
def on_mobile?; false; end
|
47
|
+
def on_tablet?; false; end
|
48
|
+
def on_tv?; false; end
|
49
|
+
def on_server?; true; end
|
50
|
+
|
51
|
+
def after(time_ms, &block)
|
52
|
+
sleep time_ms/1000
|
53
|
+
block.call
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# originally taken from: https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/object/deep_dup.rb
|
2
|
+
|
3
|
+
class Object
|
4
|
+
# Returns a deep copy of object if it's duplicable. If it's
|
5
|
+
# not duplicable, returns +self+.
|
6
|
+
#
|
7
|
+
# object = Object.new
|
8
|
+
# dup = object.deep_dup
|
9
|
+
# dup.instance_variable_set(:@a, 1)
|
10
|
+
#
|
11
|
+
# object.instance_variable_defined?(:@a) # => false
|
12
|
+
# dup.instance_variable_defined?(:@a) # => true
|
13
|
+
def deep_dup
|
14
|
+
duplicable? ? dup : self
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Array
|
19
|
+
# Returns a deep copy of array.
|
20
|
+
#
|
21
|
+
# array = [1, [2, 3]]
|
22
|
+
# dup = array.deep_dup
|
23
|
+
# dup[1][2] = 4
|
24
|
+
#
|
25
|
+
# array[1][2] # => nil
|
26
|
+
# dup[1][2] # => 4
|
27
|
+
def deep_dup
|
28
|
+
map(&:deep_dup)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Hash
|
33
|
+
# Returns a deep copy of hash.
|
34
|
+
#
|
35
|
+
# hash = { a: { b: 'b' } }
|
36
|
+
# dup = hash.deep_dup
|
37
|
+
# dup[:a][:c] = 'c'
|
38
|
+
#
|
39
|
+
# hash[:a][:c] # => nil
|
40
|
+
# dup[:a][:c] # => "c"
|
41
|
+
def deep_dup
|
42
|
+
hash = dup
|
43
|
+
each_pair do |key, value|
|
44
|
+
if ::String === key || ::Symbol === key
|
45
|
+
hash[key] = value.deep_dup
|
46
|
+
else
|
47
|
+
hash.delete(key)
|
48
|
+
hash[key.deep_dup] = value.deep_dup
|
49
|
+
end
|
50
|
+
end
|
51
|
+
hash
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# originally taken from: https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/object/duplicable.rb
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Most objects are cloneable, but not all. For example you can't dup methods:
|
5
|
+
#
|
6
|
+
# method(:puts).dup # => TypeError: allocator undefined for Method
|
7
|
+
#
|
8
|
+
# Classes may signal their instances are not duplicable removing +dup+/+clone+
|
9
|
+
# or raising exceptions from them. So, to dup an arbitrary object you normally
|
10
|
+
# use an optimistic approach and are ready to catch an exception, say:
|
11
|
+
#
|
12
|
+
# arbitrary_object.dup rescue object
|
13
|
+
#
|
14
|
+
# Rails dups objects in a few critical spots where they are not that arbitrary.
|
15
|
+
# That rescue is very expensive (like 40 times slower than a predicate), and it
|
16
|
+
# is often triggered.
|
17
|
+
#
|
18
|
+
# That's why we hardcode the following cases and check duplicable? instead of
|
19
|
+
# using that rescue idiom.
|
20
|
+
#++
|
21
|
+
class Object
|
22
|
+
# Can you safely dup this object?
|
23
|
+
#
|
24
|
+
# False for method objects;
|
25
|
+
# true otherwise.
|
26
|
+
def duplicable?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Method
|
32
|
+
# Methods are not duplicable:
|
33
|
+
#
|
34
|
+
# method(:puts).duplicable? # => false
|
35
|
+
# method(:puts).dup # => TypeError: allocator undefined for Method
|
36
|
+
def duplicable?
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class UnboundMethod
|
42
|
+
# Unbound methods are not duplicable:
|
43
|
+
#
|
44
|
+
# method(:puts).unbind.duplicable? # => false
|
45
|
+
# method(:puts).unbind.dup # => TypeError: allocator undefined for UnboundMethod
|
46
|
+
def duplicable?
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
require "singleton"
|
52
|
+
|
53
|
+
module Singleton
|
54
|
+
# Singleton instances are not duplicable:
|
55
|
+
#
|
56
|
+
# Class.new.include(Singleton).instance.dup # TypeError (can't dup instance of singleton
|
57
|
+
def duplicable?
|
58
|
+
false
|
59
|
+
end
|
60
|
+
end
|
@@ -1,6 +1,19 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
# available settings
|
3
3
|
class << self
|
4
|
+
def add_client_option(key, value = nil)
|
5
|
+
self.class.attr_accessor(key)
|
6
|
+
send("#{key}=", value)
|
7
|
+
end
|
8
|
+
|
9
|
+
def client_init_class_names
|
10
|
+
@client_init_class_names ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_client_init_class_name(init_class_name)
|
14
|
+
client_init_class_names << init_class_name
|
15
|
+
end
|
16
|
+
|
4
17
|
def cached_channel_classes
|
5
18
|
@cached_channel_classes ||= {}
|
6
19
|
end
|
@@ -35,6 +48,28 @@ module Isomorfeus
|
|
35
48
|
add_client_option(:transport_init_class_names, [])
|
36
49
|
|
37
50
|
class << self
|
51
|
+
attr_accessor :zeitwerk
|
52
|
+
|
53
|
+
# server side env is set in isomorfeus-asset-manager
|
54
|
+
def env=(env_string)
|
55
|
+
@env = env_string ? env_string : 'development'
|
56
|
+
@development = (@env == 'development') ? true : false
|
57
|
+
@production = (@env == 'production') ? true : false
|
58
|
+
@test = (@env == 'test') ? true : false
|
59
|
+
end
|
60
|
+
|
61
|
+
def development?
|
62
|
+
@development
|
63
|
+
end
|
64
|
+
|
65
|
+
def production?
|
66
|
+
@production
|
67
|
+
end
|
68
|
+
|
69
|
+
def test?
|
70
|
+
@test
|
71
|
+
end
|
72
|
+
|
38
73
|
def valid_channel_class_name?(class_name)
|
39
74
|
cached_channel_class(class_name) # because of autoloader
|
40
75
|
valid_channel_class_names.include?(class_name)
|
@@ -51,6 +86,8 @@ module Isomorfeus
|
|
51
86
|
attr_accessor :api_websocket_path
|
52
87
|
attr_accessor :api_logout_path
|
53
88
|
attr_accessor :cookie_eater_path
|
89
|
+
attr_accessor :zeitwerk
|
90
|
+
attr_accessor :zeitwerk_lock
|
54
91
|
|
55
92
|
def valid_channel_class_name?(class_name)
|
56
93
|
valid_channel_class_names.include?(class_name)
|
@@ -3,13 +3,9 @@
|
|
3
3
|
module Isomorfeus
|
4
4
|
module Transport
|
5
5
|
class RackMiddleware
|
6
|
-
WS_RESPONSE = [0, {}, []]
|
6
|
+
WS_RESPONSE = [0, {}, []].freeze
|
7
7
|
|
8
|
-
def
|
9
|
-
@app = app
|
10
|
-
end
|
11
|
-
|
12
|
-
def user_from_env(env)
|
8
|
+
def self.user_from_env(env)
|
13
9
|
cookies = env['HTTP_COOKIE']
|
14
10
|
if cookies
|
15
11
|
cookies = cookies.split('; ')
|
@@ -25,11 +21,21 @@ module Isomorfeus
|
|
25
21
|
[Anonymous.new, nil]
|
26
22
|
end
|
27
23
|
|
24
|
+
def initialize(app)
|
25
|
+
@app = app
|
26
|
+
end
|
27
|
+
|
28
28
|
def call(env)
|
29
|
+
unless env['isomorfeus_store_initialized']
|
30
|
+
Isomorfeus.init_store
|
31
|
+
Isomorfeus.store.clear!
|
32
|
+
env['isomorfeus_store_initialized'] = true
|
33
|
+
end
|
34
|
+
|
29
35
|
case env['PATH_INFO']
|
30
36
|
when Isomorfeus.api_websocket_path
|
31
37
|
if env['rack.upgrade?'] == :websocket
|
32
|
-
user, session_id = user_from_env(env)
|
38
|
+
user, session_id = self.class.user_from_env(env)
|
33
39
|
env['rack.upgrade'] = Isomorfeus::Transport::ServerSocketProcessor.new(user, session_id)
|
34
40
|
end
|
35
41
|
WS_RESPONSE
|
@@ -46,7 +52,7 @@ module Isomorfeus
|
|
46
52
|
[404, {}, ["Must specify relative path!"]]
|
47
53
|
end
|
48
54
|
when Isomorfeus.api_logout_path
|
49
|
-
user, session_id = user_from_env(env)
|
55
|
+
user, session_id = self.class.user_from_env(env)
|
50
56
|
if user
|
51
57
|
begin
|
52
58
|
Isomorfeus.session_class&.remove(session_id: session_id)
|
@@ -59,7 +65,8 @@ module Isomorfeus
|
|
59
65
|
end
|
60
66
|
return [302, { 'Location' => '/', 'Set-Cookie' => cookie }, ["Tried to log out!"]]
|
61
67
|
else
|
62
|
-
|
68
|
+
env['isomorfeus_user_session'] = self.class.user_from_env(env) unless env.key?('isomorfeus_user_session')
|
69
|
+
user, session_id = env['isomorfeus_user_session']
|
63
70
|
if user
|
64
71
|
Thread.current[:isomorfeus_user] = user
|
65
72
|
Thread.current[:isomorfeus_session_id] = session_id
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module Transport
|
3
3
|
class ServerSocketProcessor
|
4
|
+
OJ_OBJ_RE = /"(\^c|\^o|\^u)":/
|
4
5
|
include Isomorfeus::Transport::ServerProcessor
|
5
6
|
|
6
7
|
def initialize(user, session_id)
|
@@ -20,8 +21,19 @@ module Isomorfeus
|
|
20
21
|
end
|
21
22
|
Isomorfeus.zeitwerk_lock.acquire_read_lock
|
22
23
|
end
|
23
|
-
|
24
|
+
Isomorfeus.init_store
|
25
|
+
Isomorfeus.store.clear!
|
26
|
+
if user.respond_to?(:reload)
|
27
|
+
cu = Thread.current[:isomorfeus_user]
|
28
|
+
Thread.current[:isomorfeus_user] = LocalSystem.new
|
29
|
+
begin
|
30
|
+
user.reload
|
31
|
+
ensure
|
32
|
+
Thread.current[:isomorfeus_user] = cu
|
33
|
+
end
|
34
|
+
end
|
24
35
|
Thread.current[:isomorfeus_user] = user
|
36
|
+
request_hash = Oj.load(data, mode: :strict)
|
25
37
|
unless request_hash.key?(:iso_ping)
|
26
38
|
handler_instance_cache = {}
|
27
39
|
response_agent_array = []
|
data/lib/isomorfeus/transport.rb
CHANGED
@@ -8,7 +8,9 @@ module Isomorfeus
|
|
8
8
|
|
9
9
|
def init
|
10
10
|
@socket = nil
|
11
|
-
|
11
|
+
@actions = []
|
12
|
+
@actions_promise = Promise.new
|
13
|
+
promise_connect
|
12
14
|
true
|
13
15
|
end
|
14
16
|
|
@@ -18,29 +20,22 @@ module Isomorfeus
|
|
18
20
|
promise.resolve(true)
|
19
21
|
return promise
|
20
22
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
ws_url = "#{Isomorfeus::TopLevel.transport_ws_url}"
|
27
|
-
end
|
23
|
+
|
24
|
+
window_protocol = `window.location.protocol`
|
25
|
+
ws_protocol = window_protocol == 'https:' ? 'wss:' : 'ws:'
|
26
|
+
ws_url = "#{ws_protocol}//#{`window.location.host`}#{Isomorfeus.api_websocket_path}"
|
27
|
+
|
28
28
|
headers = (session_id.nil? || session_id.empty?) ? nil : { 'Cookie': "session=#{session_id}" }
|
29
29
|
@socket = Isomorfeus::Transport::WebsocketClient.new(ws_url, nil, headers)
|
30
30
|
@socket.on_error do |error|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Isomorfeus::Transport.promise_connect(session_id, promise)
|
36
|
-
end
|
37
|
-
else
|
38
|
-
Isomorfeus.raise_error(message: error.JS[:message], stack: error.JS[:stack])
|
39
|
-
promise.reject
|
31
|
+
`console.warn('Isomorfeus::Transport: Will try again, but so far error connecting:', error)`
|
32
|
+
@socket.close
|
33
|
+
after 1000 do
|
34
|
+
Isomorfeus::Transport.promise_connect(session_id, promise)
|
40
35
|
end
|
41
36
|
end
|
42
37
|
@socket.on_message do |event|
|
43
|
-
json_hash =
|
38
|
+
json_hash = JSON.parse(`event.data`)
|
44
39
|
Isomorfeus::Transport::ClientProcessor.process(json_hash)
|
45
40
|
end
|
46
41
|
@socket.on_open do |event|
|
@@ -59,7 +54,7 @@ module Isomorfeus
|
|
59
54
|
open_promise.then { promise_send_request(request) } if agent && !agent.sent
|
60
55
|
end
|
61
56
|
open_promise.then { promise.resolve(true) }
|
62
|
-
keep_session_alive
|
57
|
+
keep_session_alive
|
63
58
|
end
|
64
59
|
promise
|
65
60
|
end
|
@@ -76,52 +71,64 @@ module Isomorfeus
|
|
76
71
|
@socket = nil
|
77
72
|
end
|
78
73
|
|
79
|
-
def promise_send_path(*path
|
74
|
+
def promise_send_path(*path)
|
80
75
|
request = {}
|
81
76
|
inject_path = path[0...-1]
|
82
77
|
last_inject_path_el = inject_path.last
|
83
78
|
last_path_el = path.last
|
84
79
|
inject_path.inject(request) do |memo, key|
|
85
80
|
if key == last_inject_path_el
|
86
|
-
|
81
|
+
if last_path_el.is_a?(Hash)
|
82
|
+
memo[key] = last_path_el
|
83
|
+
else
|
84
|
+
memo[key] = { last_path_el => nil }
|
85
|
+
end
|
87
86
|
else
|
88
87
|
memo[key] = {}
|
89
88
|
end
|
90
89
|
end
|
91
|
-
|
90
|
+
self.promise_send_request(request)
|
91
|
+
end
|
92
|
+
|
93
|
+
def promise_send_action(action)
|
94
|
+
@actions.push(action)
|
95
|
+
if @actions.length == 1
|
96
|
+
after(0) do
|
97
|
+
acts = @actions
|
98
|
+
@actions = []
|
99
|
+
pr = @actions_promise
|
100
|
+
@actions_promise = Promise.new
|
101
|
+
promise_send_request('Isomorfeus::Redux::Handler' => acts).then do |agnt|
|
102
|
+
pr.resolve(agnt)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
@actions_promise
|
92
107
|
end
|
93
108
|
|
94
|
-
def promise_send_request(request
|
109
|
+
def promise_send_request(request)
|
95
110
|
agent = if request_in_progress?(request)
|
96
111
|
get_agent_for_request_in_progress(request)
|
97
112
|
else
|
98
113
|
Isomorfeus::Transport::RequestAgent.new(request)
|
99
114
|
end
|
100
|
-
unless agent.sent
|
101
|
-
|
102
|
-
agent.promise.then do |response|
|
103
|
-
block.call(response)
|
104
|
-
end
|
105
|
-
end
|
115
|
+
unless agent.queued || agent.sent
|
116
|
+
agent.queued = true
|
106
117
|
register_request_in_progress(request, agent.id)
|
107
|
-
Isomorfeus.raise_error(message: 'No socket!') unless @socket
|
108
118
|
begin
|
109
|
-
|
119
|
+
Isomorfeus.raise_error(message: 'No socket!') unless @socket
|
120
|
+
@socket.send(JSON.dump({request: { agent_ids: { agent.id => request }}}))
|
110
121
|
agent.sent = true
|
111
|
-
after(
|
122
|
+
after(20000) do
|
112
123
|
unless agent.promise.realized?
|
113
124
|
agent.promise.reject({agent_response: { error: 'Request timeout!' }, full_response: {}})
|
114
125
|
end
|
115
126
|
end
|
116
127
|
rescue
|
117
128
|
@socket.close
|
118
|
-
after
|
129
|
+
after(3000) do
|
119
130
|
@reconnect = true
|
120
|
-
|
121
|
-
Isomorfeus::Transport.promise_connect
|
122
|
-
else
|
123
|
-
Isomorfeus.raise_error(message: 'Transport lost connection!')
|
124
|
-
end
|
131
|
+
Isomorfeus::Transport.promise_connect
|
125
132
|
end
|
126
133
|
end
|
127
134
|
end
|
data/lib/isomorfeus-transport.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
-
require 'isomorfeus
|
1
|
+
require 'isomorfeus/core_ext/kernel'
|
2
|
+
require 'isomorfeus/core_ext/object/duplicable'
|
3
|
+
require 'isomorfeus/core_ext/object/deep_dup'
|
4
|
+
require 'isomorfeus/core_ext/hash/deep_merge'
|
5
|
+
require 'active_support/core_ext/string'
|
6
|
+
|
7
|
+
require 'zeitwerk'
|
8
|
+
|
2
9
|
if RUBY_ENGINE == 'opal'
|
10
|
+
require 'native'
|
11
|
+
require 'promise'
|
3
12
|
require 'json'
|
4
13
|
require 'isomorfeus/transport/version'
|
5
14
|
require 'isomorfeus/transport/config'
|
@@ -8,8 +17,8 @@ if RUBY_ENGINE == 'opal'
|
|
8
17
|
require 'isomorfeus/transport/websocket_client'
|
9
18
|
require 'isomorfeus/transport'
|
10
19
|
|
11
|
-
require 'lucid_channel
|
12
|
-
|
20
|
+
require 'lucid_channel'
|
21
|
+
Isomorfeus.zeitwerk = Zeitwerk::Loader.new
|
13
22
|
Isomorfeus.zeitwerk.push_dir('channels')
|
14
23
|
Isomorfeus.add_client_init_class_name('Isomorfeus::Transport')
|
15
24
|
else
|
@@ -20,7 +29,6 @@ else
|
|
20
29
|
require 'fileutils'
|
21
30
|
require 'ostruct'
|
22
31
|
require 'socket'
|
23
|
-
require 'sorted_set'
|
24
32
|
require 'time'
|
25
33
|
require 'brotli'
|
26
34
|
require 'zlib'
|
@@ -29,7 +37,11 @@ else
|
|
29
37
|
require 'rack/body_proxy'
|
30
38
|
require 'rack/request'
|
31
39
|
require 'rack/utils'
|
40
|
+
require 'rackup'
|
32
41
|
require 'active_support'
|
42
|
+
require 'opal-activesupport'
|
43
|
+
require 'opal-zeitwerk'
|
44
|
+
|
33
45
|
require 'isomorfeus-asset-manager'
|
34
46
|
opal_path = Gem::Specification.find_by_name('opal').full_gem_path
|
35
47
|
promise_path = File.join(opal_path, 'stdlib', 'promise.rb')
|
@@ -37,6 +49,12 @@ else
|
|
37
49
|
require 'isomorfeus/transport/version'
|
38
50
|
require 'isomorfeus/transport/response_agent'
|
39
51
|
require 'isomorfeus/transport/config'
|
52
|
+
|
53
|
+
require 'concurrent/atomic/atomic_fixnum'
|
54
|
+
require 'concurrent/atomic/reentrant_read_write_lock'
|
55
|
+
Isomorfeus.zeitwerk = Zeitwerk::Loader.new
|
56
|
+
Isomorfeus.zeitwerk_lock = Concurrent::ReentrantReadWriteLock.new if Isomorfeus.development?
|
57
|
+
|
40
58
|
require 'isomorfeus/transport/middlewares'
|
41
59
|
require 'isomorfeus/transport/request_agent'
|
42
60
|
require 'isomorfeus/transport/server_processor'
|
@@ -51,26 +69,17 @@ else
|
|
51
69
|
Isomorfeus.add_middleware(Isomorfeus::Transport::CompressorRack)
|
52
70
|
Isomorfeus.add_middleware(Isomorfeus::Transport::RackMiddleware)
|
53
71
|
|
54
|
-
require 'lucid_handler
|
55
|
-
require '
|
56
|
-
require 'lucid_channel/mixin'
|
57
|
-
require 'lucid_channel/base'
|
58
|
-
|
59
|
-
require 'isomorfeus/transport/handler/authentication_handler'
|
72
|
+
require 'lucid_handler'
|
73
|
+
require 'lucid_channel'
|
60
74
|
|
61
75
|
require 'iso_opal'
|
62
76
|
Opal.append_path(__dir__.untaint) unless IsoOpal.paths_include?(__dir__.untaint)
|
63
77
|
|
78
|
+
|
64
79
|
%w[channels handlers server].each do |dir|
|
65
80
|
path = File.expand_path(File.join('app', dir))
|
66
81
|
if Dir.exist?(path)
|
67
82
|
Isomorfeus.zeitwerk.push_dir(path)
|
68
83
|
end
|
69
84
|
end
|
70
|
-
|
71
|
-
require 'isomorfeus-speednode'
|
72
|
-
Isomorfeus.node_paths << File.expand_path(File.join(File.dirname(__FILE__), '..', 'node_modules'))
|
73
|
-
|
74
|
-
require 'isomorfeus/transport/imports'
|
75
|
-
Isomorfeus::Transport::Imports.add
|
76
85
|
end
|