isomorfeus-transport 1.0.0.zeta11 → 1.0.0.zeta12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/isomorfeus-transport.rb +1 -1
- data/lib/isomorfeus/transport.rb +36 -18
- data/lib/isomorfeus/transport/request_agent.rb +3 -1
- data/lib/isomorfeus/transport/server_processor.rb +6 -12
- data/lib/isomorfeus/transport/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 429764404614628b8b9f1c62d36a496b57e173dc5c67720f4ba8a07fdac182d8
|
4
|
+
data.tar.gz: 8d125f4501ea5ebbbe32112a77e8a6163907e9fd252e9dbf29f4599fc81e3613
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ef22091cda95389354afd86d0131cb6395bc5d8207f8b310131063c2b2be4d29ea3bf224d702e4c32b9abba981646821ae45dcf98998a2f7ce9525ee27e2da3
|
7
|
+
data.tar.gz: 16395e5e7b942a3317cdacb114f03d97269d2f695dcc1d8b35fadf98acd309bc39e1afdff5551eecd93a43effb22537966d5ebe5fff288e617c08e62b0fc11e6
|
data/README.md
CHANGED
@@ -32,14 +32,16 @@ Server only:
|
|
32
32
|
|
33
33
|
## Authentication
|
34
34
|
|
35
|
-
For authentication in isomorfeus there is a class `Anonymous`, so whenever no user is logged in, the anonymous user is passed on to operations
|
35
|
+
For authentication in isomorfeus there is a class `Anonymous`, so whenever no user is logged in, the anonymous user is passed on to operations
|
36
|
+
or data loads. In my opinion it is more true than no user (nil), because in fact there probably is a user, just the user is unknown.
|
37
|
+
The Anonymous user has a default policy that denies everything, the user will respond to .authorized?(whatever) always with false by default.
|
36
38
|
Of course, the developer can add a Policy easily, to allow certain operations or data loads, or whatever or everything:
|
37
39
|
```ruby
|
38
|
-
class
|
39
|
-
policy_for Anonymous
|
40
|
+
class AnonymousPolicy < LucidPolicy::Base
|
40
41
|
allow all
|
41
42
|
end
|
42
43
|
```
|
44
|
+
For more information about policy see [the policy docs](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-policy/README.md).
|
43
45
|
|
44
46
|
A class representing a user should be a LucidNode and include LucidAuthentication::Mixin:
|
45
47
|
```ruby
|
data/lib/isomorfeus-transport.rb
CHANGED
@@ -50,7 +50,7 @@ else
|
|
50
50
|
Opal.append_path(__dir__.untaint) unless Opal.paths.include?(__dir__.untaint)
|
51
51
|
|
52
52
|
%w[channels handlers server].each do |dir|
|
53
|
-
path = File.expand_path(File.join('
|
53
|
+
path = File.expand_path(File.join('app', dir))
|
54
54
|
if Dir.exist?(path)
|
55
55
|
Isomorfeus.zeitwerk.push_dir(path)
|
56
56
|
end
|
data/lib/isomorfeus/transport.rb
CHANGED
@@ -5,12 +5,13 @@ module Isomorfeus
|
|
5
5
|
attr_accessor :socket
|
6
6
|
|
7
7
|
def delay(ms = 1000, &block)
|
8
|
-
`setTimeout(#{block.to_n}, ms)`
|
8
|
+
`setTimeout(#{block.to_n}, #{ms})`
|
9
9
|
end
|
10
10
|
|
11
11
|
def init
|
12
12
|
@requests_in_progress = { requests: {}, agent_ids: {} }
|
13
13
|
@socket = nil
|
14
|
+
@initialized = false
|
14
15
|
promise_connect if Isomorfeus.on_browser?
|
15
16
|
true
|
16
17
|
end
|
@@ -31,7 +32,7 @@ module Isomorfeus
|
|
31
32
|
@socket = Isomorfeus::Transport::Websocket.new(ws_url)
|
32
33
|
@socket.on_error do
|
33
34
|
@socket.close
|
34
|
-
delay do
|
35
|
+
delay 1000 do
|
35
36
|
Isomorfeus::Transport.promise_connect
|
36
37
|
end
|
37
38
|
end
|
@@ -40,15 +41,22 @@ module Isomorfeus
|
|
40
41
|
Isomorfeus::Transport::ClientProcessor.process(json_hash)
|
41
42
|
end
|
42
43
|
@socket.on_open do |event|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
if init_promises.size > 0
|
49
|
-
Promise.when(*init_promises).then { promise.resolve(true) }
|
50
|
-
else
|
44
|
+
if @initialized
|
45
|
+
requests_in_progress[:requests].each_key do |request|
|
46
|
+
agent = get_agent_for_request_in_progress(request)
|
47
|
+
promise_send_request(request) if agent && !agent.sent
|
48
|
+
end
|
51
49
|
promise.resolve(true)
|
50
|
+
else
|
51
|
+
@initialized = true
|
52
|
+
init_promises = []
|
53
|
+
Isomorfeus.transport_init_class_names.each do |constant|
|
54
|
+
result = constant.constantize.send(:init)
|
55
|
+
init_promises << result if result.class == Promise
|
56
|
+
end
|
57
|
+
if init_promises.size > 0
|
58
|
+
Promise.when(*init_promises).then { promise.resolve(true) }
|
59
|
+
end
|
52
60
|
end
|
53
61
|
end
|
54
62
|
promise
|
@@ -75,10 +83,12 @@ module Isomorfeus
|
|
75
83
|
end
|
76
84
|
|
77
85
|
def promise_send_request(request, &block)
|
78
|
-
if request_in_progress?(request)
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
agent = if request_in_progress?(request)
|
87
|
+
get_agent_for_request_in_progress(request)
|
88
|
+
else
|
89
|
+
Isomorfeus::Transport::RequestAgent.new(request)
|
90
|
+
end
|
91
|
+
unless agent.sent
|
82
92
|
if block_given?
|
83
93
|
agent.promise.then do |response|
|
84
94
|
block.call(response)
|
@@ -86,10 +96,18 @@ module Isomorfeus
|
|
86
96
|
end
|
87
97
|
register_request_in_progress(request, agent.id)
|
88
98
|
raise 'No socket!' unless @socket
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
99
|
+
begin
|
100
|
+
@socket.send(`JSON.stringify(#{{request: { agent_ids: { agent.id => request }}}.to_n})`)
|
101
|
+
agent.sent = true
|
102
|
+
delay(Isomorfeus.on_ssr? ? 8000 : 20000) do
|
103
|
+
unless agent.promise.realized?
|
104
|
+
agent.promise.reject({agent_response: { error: 'Request timeout!' }, full_response: {}})
|
105
|
+
end
|
106
|
+
end
|
107
|
+
rescue
|
108
|
+
@socket.close
|
109
|
+
delay 5000 do
|
110
|
+
Isomorfeus::Transport.promise_connect
|
93
111
|
end
|
94
112
|
end
|
95
113
|
end
|
@@ -17,6 +17,7 @@ module Isomorfeus
|
|
17
17
|
attr_accessor :result
|
18
18
|
attr_accessor :response
|
19
19
|
attr_accessor :full_response
|
20
|
+
attr_accessor :sent
|
20
21
|
attr_reader :id
|
21
22
|
attr_reader :promise
|
22
23
|
attr_reader :request
|
@@ -26,7 +27,8 @@ module Isomorfeus
|
|
26
27
|
self.class.agents[@id] = self
|
27
28
|
@promise = Promise.new
|
28
29
|
@request = request
|
30
|
+
@sent = false
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
|
-
end
|
34
|
+
end
|
@@ -24,9 +24,7 @@ module Isomorfeus
|
|
24
24
|
response_agent.error = { error: { handler_class_name => 'No such handler!'}}
|
25
25
|
end
|
26
26
|
rescue Exception => e
|
27
|
-
response_agent.error =
|
28
|
-
else { response: { error: "#{handler_class_name}: #{e.message}\n#{e.backtrace.join("\n")}" }}
|
29
|
-
end
|
27
|
+
response_agent.error = { response: { error: "#{handler_class_name}: #{e.message}\n#{e.backtrace.join("\n")}" }}
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
@@ -52,9 +50,7 @@ module Isomorfeus
|
|
52
50
|
rescue Exception => e
|
53
51
|
response_agent = OpenStruct.new
|
54
52
|
response_agent_array << response_agent
|
55
|
-
response_agent.result =
|
56
|
-
else { response: { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }}
|
57
|
-
end
|
53
|
+
response_agent.result = { response: { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }}
|
58
54
|
end
|
59
55
|
elsif request.key?('subscribe') && request['subscribe'].key?('agent_ids')
|
60
56
|
begin
|
@@ -75,9 +71,7 @@ module Isomorfeus
|
|
75
71
|
response_agent.error = { error: "No such thing!"}
|
76
72
|
end
|
77
73
|
rescue Exception => e
|
78
|
-
response_agent.error =
|
79
|
-
else { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }
|
80
|
-
end
|
74
|
+
response_agent.error = { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }
|
81
75
|
end
|
82
76
|
elsif request.key?('unsubscribe') && request['unsubscribe'].key?('agent_ids')
|
83
77
|
begin
|
@@ -98,10 +92,10 @@ module Isomorfeus
|
|
98
92
|
response_agent.error = { error: 'No such thing!'}
|
99
93
|
end
|
100
94
|
rescue Exception => e
|
101
|
-
response_agent.error =
|
102
|
-
else { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }
|
103
|
-
end
|
95
|
+
response_agent.error = { error: "Isomorfeus::Transport::ServerProcessor: #{e.message}\n#{e.backtrace.join("\n")}" }
|
104
96
|
end
|
97
|
+
else
|
98
|
+
response_agent.error = { error: "No such thing!" }
|
105
99
|
end
|
106
100
|
end
|
107
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: isomorfeus-transport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.zeta12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -72,42 +72,42 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 4.0.
|
75
|
+
version: 4.0.17
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 4.0.
|
82
|
+
version: 4.0.17
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: isomorfeus-react
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 16.12.
|
89
|
+
version: 16.12.9
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 16.12.
|
96
|
+
version: 16.12.9
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: isomorfeus-policy
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.0.0.
|
103
|
+
version: 1.0.0.zeta12
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.0.0.
|
110
|
+
version: 1.0.0.zeta12
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: websocket-driver
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - '='
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 1.0.0.
|
131
|
+
version: 1.0.0.zeta12
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - '='
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 1.0.0.
|
138
|
+
version: 1.0.0.zeta12
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: opal-webpack-loader
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|