isomorfeus-transport 1.0.0.zeta22 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -21
- data/README.md +27 -36
- data/lib/isomorfeus/transport/client_processor.rb +35 -30
- data/lib/isomorfeus/transport/config.rb +182 -158
- data/lib/isomorfeus/transport/hamster_session_store.rb +96 -0
- data/lib/isomorfeus/transport/handler/authentication_handler.rb +70 -70
- data/lib/isomorfeus/transport/imports.rb +9 -0
- data/lib/isomorfeus/transport/middlewares.rb +13 -13
- data/lib/isomorfeus/transport/rack_middleware.rb +59 -55
- data/lib/isomorfeus/transport/request_agent.rb +34 -34
- data/lib/isomorfeus/transport/response_agent.rb +23 -23
- data/lib/isomorfeus/transport/server_processor.rb +129 -101
- data/lib/isomorfeus/transport/server_socket_processor.rb +54 -54
- data/lib/isomorfeus/transport/ssr_login.rb +28 -28
- data/lib/isomorfeus/transport/version.rb +5 -5
- data/lib/isomorfeus/transport/{websocket.rb → websocket_client.rb} +123 -123
- data/lib/isomorfeus/transport.rb +200 -213
- data/lib/isomorfeus-transport.rb +70 -64
- data/lib/lucid_authentication/mixin.rb +122 -124
- data/lib/lucid_channel/base.rb +8 -11
- data/lib/lucid_channel/mixin.rb +105 -50
- data/lib/lucid_handler/base.rb +8 -9
- data/lib/lucid_handler/mixin.rb +27 -27
- data/node_modules/.package-lock.json +27 -0
- data/node_modules/ws/LICENSE +19 -0
- data/node_modules/ws/README.md +496 -0
- data/node_modules/ws/browser.js +8 -0
- data/node_modules/ws/index.js +13 -0
- data/node_modules/ws/lib/buffer-util.js +126 -0
- data/node_modules/ws/lib/constants.js +12 -0
- data/node_modules/ws/lib/event-target.js +266 -0
- data/node_modules/ws/lib/extension.js +203 -0
- data/node_modules/ws/lib/limiter.js +55 -0
- data/node_modules/ws/lib/permessage-deflate.js +511 -0
- data/node_modules/ws/lib/receiver.js +612 -0
- data/node_modules/ws/lib/sender.js +414 -0
- data/node_modules/ws/lib/stream.js +180 -0
- data/node_modules/ws/lib/subprotocol.js +62 -0
- data/node_modules/ws/lib/validation.js +124 -0
- data/node_modules/ws/lib/websocket-server.js +485 -0
- data/node_modules/ws/lib/websocket.js +1144 -0
- data/node_modules/ws/package.json +61 -0
- data/node_modules/ws/wrapper.mjs +8 -0
- data/package.json +6 -0
- metadata +82 -46
- data/lib/isomorfeus/transport/dbm_session_store.rb +0 -51
@@ -1,54 +1,54 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
module Transport
|
3
|
-
class ServerSocketProcessor
|
4
|
-
include Isomorfeus::Transport::ServerProcessor
|
5
|
-
|
6
|
-
def on_message(client, data)
|
7
|
-
if Isomorfeus.development?
|
8
|
-
write_lock = Isomorfeus.zeitwerk_lock.try_write_lock
|
9
|
-
if write_lock
|
10
|
-
Isomorfeus.zeitwerk.reload
|
11
|
-
Isomorfeus.zeitwerk_lock.release_write_lock
|
12
|
-
end
|
13
|
-
Isomorfeus.zeitwerk_lock.acquire_read_lock
|
14
|
-
end
|
15
|
-
request_hash = Oj.load(data, mode: :strict)
|
16
|
-
handler_instance_cache = {}
|
17
|
-
response_agent_array = []
|
18
|
-
Thread.current[:isomorfeus_user] = user(client)
|
19
|
-
Thread.current[:isomorfeus_pub_sub_client] = client
|
20
|
-
process_request(request_hash, handler_instance_cache, response_agent_array)
|
21
|
-
handler_instance_cache.each_value do |handler|
|
22
|
-
handler.resolve if handler.resolving?
|
23
|
-
end
|
24
|
-
result = {}
|
25
|
-
response_agent_array.each do |response_agent|
|
26
|
-
result.deep_merge!(response_agent.result)
|
27
|
-
end
|
28
|
-
client.write Oj.dump(result, mode: :strict)
|
29
|
-
ensure
|
30
|
-
Thread.current[:isomorfeus_user] = nil
|
31
|
-
Thread.current[:isomorfeus_pub_sub_client] = nil
|
32
|
-
Isomorfeus.zeitwerk_lock.release_read_lock if Isomorfeus.development?
|
33
|
-
end
|
34
|
-
|
35
|
-
def on_close(client)
|
36
|
-
# nothing for now
|
37
|
-
end
|
38
|
-
|
39
|
-
def on_open(client)
|
40
|
-
# nothing for now
|
41
|
-
end
|
42
|
-
|
43
|
-
def on_shutdown(client)
|
44
|
-
# nothing for now
|
45
|
-
end
|
46
|
-
|
47
|
-
def user(client)
|
48
|
-
current_user = client.instance_variable_get(:@isomorfeus_user)
|
49
|
-
return current_user if current_user
|
50
|
-
Anonymous.new
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
1
|
+
module Isomorfeus
|
2
|
+
module Transport
|
3
|
+
class ServerSocketProcessor
|
4
|
+
include Isomorfeus::Transport::ServerProcessor
|
5
|
+
|
6
|
+
def on_message(client, data)
|
7
|
+
if Isomorfeus.development?
|
8
|
+
write_lock = Isomorfeus.zeitwerk_lock.try_write_lock
|
9
|
+
if write_lock
|
10
|
+
Isomorfeus.zeitwerk.reload
|
11
|
+
Isomorfeus.zeitwerk_lock.release_write_lock
|
12
|
+
end
|
13
|
+
Isomorfeus.zeitwerk_lock.acquire_read_lock
|
14
|
+
end
|
15
|
+
request_hash = Oj.load(data, mode: :strict)
|
16
|
+
handler_instance_cache = {}
|
17
|
+
response_agent_array = []
|
18
|
+
Thread.current[:isomorfeus_user] = user(client)
|
19
|
+
Thread.current[:isomorfeus_pub_sub_client] = client
|
20
|
+
process_request(request_hash, handler_instance_cache, response_agent_array)
|
21
|
+
handler_instance_cache.each_value do |handler|
|
22
|
+
handler.resolve if handler.resolving?
|
23
|
+
end
|
24
|
+
result = {}
|
25
|
+
response_agent_array.each do |response_agent|
|
26
|
+
result.deep_merge!(response_agent.result)
|
27
|
+
end
|
28
|
+
client.write Oj.dump(result, mode: :strict) unless result.empty?
|
29
|
+
ensure
|
30
|
+
Thread.current[:isomorfeus_user] = nil
|
31
|
+
Thread.current[:isomorfeus_pub_sub_client] = nil
|
32
|
+
Isomorfeus.zeitwerk_lock.release_read_lock if Isomorfeus.development?
|
33
|
+
end
|
34
|
+
|
35
|
+
def on_close(client)
|
36
|
+
# nothing for now
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_open(client)
|
40
|
+
# nothing for now
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_shutdown(client)
|
44
|
+
# nothing for now
|
45
|
+
end
|
46
|
+
|
47
|
+
def user(client)
|
48
|
+
current_user = client.instance_variable_get(:@isomorfeus_user)
|
49
|
+
return current_user if current_user
|
50
|
+
Anonymous.new
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,28 +1,28 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
module Transport
|
3
|
-
class SsrLogin
|
4
|
-
def self.init
|
5
|
-
session_id = `global.IsomorfeusSessionId`
|
6
|
-
if session_id && session_id.size > 0
|
7
|
-
Isomorfeus::Transport.promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'ssr_login', session_id).then do |agent|
|
8
|
-
if agent.processed
|
9
|
-
agent.result
|
10
|
-
else
|
11
|
-
agent.processed = true
|
12
|
-
if agent.response.key?(:success)
|
13
|
-
Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.response[:data])
|
14
|
-
class_name = agent.response[:data].keys.first
|
15
|
-
key = agent.response[:data][class_name].keys.first
|
16
|
-
logged_in_user = Isomorfeus.cached_data_class(class_name).new(key: key)
|
17
|
-
Isomorfeus.set_current_user(logged_in_user)
|
18
|
-
else
|
19
|
-
error = agent.response[:error]
|
20
|
-
Isomorfeus.raise_error(message: "SSR Login failed, #{error}!") # triggers .fail
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module Isomorfeus
|
2
|
+
module Transport
|
3
|
+
class SsrLogin
|
4
|
+
def self.init
|
5
|
+
session_id = `global.IsomorfeusSessionId`
|
6
|
+
if session_id && session_id.size > 0
|
7
|
+
Isomorfeus::Transport.promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'ssr_login', session_id).then do |agent|
|
8
|
+
if agent.processed
|
9
|
+
agent.result
|
10
|
+
else
|
11
|
+
agent.processed = true
|
12
|
+
if agent.response.key?(:success)
|
13
|
+
Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.response[:data])
|
14
|
+
class_name = agent.response[:data].keys.first
|
15
|
+
key = agent.response[:data][class_name].keys.first
|
16
|
+
logged_in_user = Isomorfeus.cached_data_class(class_name).new(key: key)
|
17
|
+
Isomorfeus.set_current_user(logged_in_user)
|
18
|
+
else
|
19
|
+
error = agent.response[:error]
|
20
|
+
Isomorfeus.raise_error(message: "SSR Login failed, #{error}!") # triggers .fail
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
module Transport
|
3
|
-
VERSION = '
|
4
|
-
end
|
5
|
-
end
|
1
|
+
module Isomorfeus
|
2
|
+
module Transport
|
3
|
+
VERSION = '2.0.0.rc1'
|
4
|
+
end
|
5
|
+
end
|
@@ -1,123 +1,123 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
module Transport
|
3
|
-
class
|
4
|
-
attr_reader :url
|
5
|
-
|
6
|
-
if RUBY_ENGINE == 'opal'
|
7
|
-
CONNECTING = 0
|
8
|
-
OPEN = 1
|
9
|
-
CLOSING = 2
|
10
|
-
CLOSED = 3
|
11
|
-
|
12
|
-
class SendError < StandardError; end
|
13
|
-
|
14
|
-
def initialize(url, protocols = nil)
|
15
|
-
@url = url
|
16
|
-
@native_websocket = if protocols
|
17
|
-
`new Opal.global.WebSocket(url, protocols)`
|
18
|
-
else
|
19
|
-
`new Opal.global.WebSocket(url)`
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def close
|
24
|
-
@native_websocket.JS.close
|
25
|
-
nil
|
26
|
-
end
|
27
|
-
|
28
|
-
def on_close(&block)
|
29
|
-
@native_websocket.JS[:onclose] = `function(event) { block.$call(event); }`
|
30
|
-
end
|
31
|
-
|
32
|
-
def on_error(&block)
|
33
|
-
@native_websocket.JS[:onerror] = `function(event) { block.$call(event); }`
|
34
|
-
end
|
35
|
-
|
36
|
-
def on_message(&block)
|
37
|
-
@native_websocket.JS[:onmessage] = `function(event) { block.$call(event); }`
|
38
|
-
end
|
39
|
-
|
40
|
-
def on_open(&block)
|
41
|
-
@native_websocket.JS[:onopen] = `function(event) { block.$call(event); }`
|
42
|
-
end
|
43
|
-
|
44
|
-
def protocol
|
45
|
-
@native_websocket.JS[:protocol]
|
46
|
-
end
|
47
|
-
|
48
|
-
def send(data)
|
49
|
-
case ready_state
|
50
|
-
when OPEN then @native_websocket.JS.send(data)
|
51
|
-
when CONNECTING then
|
52
|
-
when CLOSING then Isomorfeus.raise_error(error_class: SendError, message: 'Cant send, connection is closing!')
|
53
|
-
when CLOSED then Isomorfeus.raise_error(error_class: SendError.new, message: 'Cant send, connection is closed!')
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
def ready_state
|
60
|
-
@native_websocket.JS[:readyState]
|
61
|
-
end
|
62
|
-
else
|
63
|
-
def initialize(url, protocols = nil)
|
64
|
-
@url = url
|
65
|
-
parsed_url = URI.parse(url)
|
66
|
-
host = parsed_url.host
|
67
|
-
port = parsed_url.port
|
68
|
-
@socket = TCPSocket.new(host, port)
|
69
|
-
@driver = ::WebSocket::Driver.client(self)
|
70
|
-
@driver.on(:close, &method(:internal_on_close))
|
71
|
-
|
72
|
-
@thread = Thread.new do
|
73
|
-
begin
|
74
|
-
while data = @sock.readpartial(512)
|
75
|
-
@driver.parse(data)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
@driver.start
|
81
|
-
end
|
82
|
-
|
83
|
-
def close
|
84
|
-
@driver.close
|
85
|
-
@thread.kill
|
86
|
-
end
|
87
|
-
|
88
|
-
def on_close(&block)
|
89
|
-
@on_close_block = block
|
90
|
-
end
|
91
|
-
|
92
|
-
def on_error(&block)
|
93
|
-
@driver.on(:error, block)
|
94
|
-
end
|
95
|
-
|
96
|
-
def on_message(&block)
|
97
|
-
@on_message_block = block
|
98
|
-
end
|
99
|
-
|
100
|
-
def on_open(&block)
|
101
|
-
@driver.on(:open, block)
|
102
|
-
end
|
103
|
-
|
104
|
-
def protocol
|
105
|
-
@driver.protocol
|
106
|
-
end
|
107
|
-
|
108
|
-
def send(data)
|
109
|
-
@socket.write(data)
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
def internal_on_close(event)
|
115
|
-
@on_close_block.call(event)
|
116
|
-
@thread.kill
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
alias_method :write, :send
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
1
|
+
module Isomorfeus
|
2
|
+
module Transport
|
3
|
+
class WebsocketClient
|
4
|
+
attr_reader :url
|
5
|
+
|
6
|
+
if RUBY_ENGINE == 'opal'
|
7
|
+
CONNECTING = 0
|
8
|
+
OPEN = 1
|
9
|
+
CLOSING = 2
|
10
|
+
CLOSED = 3
|
11
|
+
|
12
|
+
class SendError < StandardError; end
|
13
|
+
|
14
|
+
def initialize(url, protocols = nil)
|
15
|
+
@url = url
|
16
|
+
@native_websocket = if protocols
|
17
|
+
`new Opal.global.WebSocket(url, protocols)`
|
18
|
+
else
|
19
|
+
`new Opal.global.WebSocket(url)`
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def close
|
24
|
+
@native_websocket.JS.close
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_close(&block)
|
29
|
+
@native_websocket.JS[:onclose] = `function(event) { block.$call(event); }`
|
30
|
+
end
|
31
|
+
|
32
|
+
def on_error(&block)
|
33
|
+
@native_websocket.JS[:onerror] = `function(event) { block.$call(event); }`
|
34
|
+
end
|
35
|
+
|
36
|
+
def on_message(&block)
|
37
|
+
@native_websocket.JS[:onmessage] = `function(event) { block.$call(event); }`
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_open(&block)
|
41
|
+
@native_websocket.JS[:onopen] = `function(event) { block.$call(event); }`
|
42
|
+
end
|
43
|
+
|
44
|
+
def protocol
|
45
|
+
@native_websocket.JS[:protocol]
|
46
|
+
end
|
47
|
+
|
48
|
+
def send(data)
|
49
|
+
case ready_state
|
50
|
+
when OPEN then @native_websocket.JS.send(data)
|
51
|
+
when CONNECTING then after(50) { send(data) }
|
52
|
+
when CLOSING then Isomorfeus.raise_error(error_class: SendError, message: 'Cant send, connection is closing!')
|
53
|
+
when CLOSED then Isomorfeus.raise_error(error_class: SendError.new, message: 'Cant send, connection is closed!')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def ready_state
|
60
|
+
@native_websocket.JS[:readyState]
|
61
|
+
end
|
62
|
+
else
|
63
|
+
def initialize(url, protocols = nil)
|
64
|
+
@url = url
|
65
|
+
parsed_url = URI.parse(url)
|
66
|
+
host = parsed_url.host
|
67
|
+
port = parsed_url.port
|
68
|
+
@socket = TCPSocket.new(host, port)
|
69
|
+
@driver = ::WebSocket::Driver.client(self)
|
70
|
+
@driver.on(:close, &method(:internal_on_close))
|
71
|
+
|
72
|
+
@thread = Thread.new do
|
73
|
+
begin
|
74
|
+
while data = @sock.readpartial(512)
|
75
|
+
@driver.parse(data)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
@driver.start
|
81
|
+
end
|
82
|
+
|
83
|
+
def close
|
84
|
+
@driver.close
|
85
|
+
@thread.kill
|
86
|
+
end
|
87
|
+
|
88
|
+
def on_close(&block)
|
89
|
+
@on_close_block = block
|
90
|
+
end
|
91
|
+
|
92
|
+
def on_error(&block)
|
93
|
+
@driver.on(:error, block)
|
94
|
+
end
|
95
|
+
|
96
|
+
def on_message(&block)
|
97
|
+
@on_message_block = block
|
98
|
+
end
|
99
|
+
|
100
|
+
def on_open(&block)
|
101
|
+
@driver.on(:open, block)
|
102
|
+
end
|
103
|
+
|
104
|
+
def protocol
|
105
|
+
@driver.protocol
|
106
|
+
end
|
107
|
+
|
108
|
+
def send(data)
|
109
|
+
@socket.write(data)
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def internal_on_close(event)
|
115
|
+
@on_close_block.call(event)
|
116
|
+
@thread.kill
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
alias_method :write, :send
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|