isomorfeus-transport 1.0.0.zeta25 → 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 -35
- data/lib/isomorfeus/transport/config.rb +182 -166
- 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 -129
- 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 -196
- data/lib/isomorfeus-transport.rb +70 -61
- data/lib/lucid_authentication/mixin.rb +122 -122
- data/lib/lucid_channel/base.rb +8 -9
- data/lib/lucid_channel/mixin.rb +105 -105
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd6bcb0fc97804f50a51cfb715eaeedac9e58a48924a1a141b1eeee961992699
|
4
|
+
data.tar.gz: 36cce06dd43f7cfd57c4b30623f5ac914e291e98e957ad6a39787bf3504b5052
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb5c37666f091a021b5b167c317132eb3bf300c9fef46f3f42260c3a8d635d63ccf18ca3c2284fb484db8c4b90a3ca1ff1d93ddc63945a2de34ff586eb42a47e
|
7
|
+
data.tar.gz: 59c4b3927030fdfcf9383bd6296c4c4709b4425d875f26a8170d37f575be3622162e4a46c01c92d20ccf8f392542e56a5c25c95dcbea9b4b0ec15640ee2a8932
|
data/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2018, 2019 Jan Biedermann
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018, 2019 Jan Biedermann
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,36 +1,27 @@
|
|
1
|
-
# isomorfeus-transport
|
2
|
-
|
3
|
-
Transport and PubSub for Isomorfeus.
|
4
|
-
|
5
|
-
### Community and Support
|
6
|
-
At the [Isomorfeus Framework Project](http://isomorfeus.com)
|
7
|
-
|
8
|
-
## Installation
|
9
|
-
isomorfeus-transport is usually installed with the installer.
|
10
|
-
Otherwise add to your Gemfile:
|
11
|
-
```ruby
|
12
|
-
gem 'isomorfeus-transport'
|
13
|
-
```
|
14
|
-
and bundle install/update
|
15
|
-
|
16
|
-
##
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
- Isomorfeus.api_websocket_path - path for server side endpoint, default: `/isomorfeus/api/websocket`
|
29
|
-
|
30
|
-
Server only:
|
31
|
-
- Isomorfeus.middlewares - all the rack middlewares to load
|
32
|
-
|
33
|
-
## Usage
|
34
|
-
|
35
|
-
- [Authentication and Current User](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-transport/docs/authentication.md)
|
36
|
-
- [Channels (PubSub)](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-transport/docs/channels.md)
|
1
|
+
# isomorfeus-transport
|
2
|
+
|
3
|
+
Transport and PubSub for Isomorfeus.
|
4
|
+
|
5
|
+
### Community and Support
|
6
|
+
At the [Isomorfeus Framework Project](http://isomorfeus.com)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
isomorfeus-transport is usually installed with the installer.
|
10
|
+
Otherwise add to your Gemfile:
|
11
|
+
```ruby
|
12
|
+
gem 'isomorfeus-transport'
|
13
|
+
```
|
14
|
+
and bundle install/update
|
15
|
+
|
16
|
+
## Configuration options
|
17
|
+
|
18
|
+
Client and Server:
|
19
|
+
- Isomorfeus.api_websocket_path - path for server side endpoint, default: `/isomorfeus/api/websocket`
|
20
|
+
|
21
|
+
Server only:
|
22
|
+
- Isomorfeus.middlewares - all the rack middlewares to load
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
- [Authentication and Current User](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-transport/docs/authentication.md)
|
27
|
+
- [Channels (PubSub)](https://github.com/isomorfeus/isomorfeus-project/blob/master/ruby/isomorfeus-transport/docs/channels.md)
|
@@ -1,35 +1,35 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
module Transport
|
3
|
-
class ClientProcessor
|
4
|
-
def self.process(json_hash)
|
5
|
-
if json_hash.key?(:response)
|
6
|
-
process_response(json_hash)
|
7
|
-
elsif json_hash.key?(:notification)
|
8
|
-
process_message(json_hash)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.process_message(message_hash)
|
13
|
-
processor_class_name = message_hash[:notification][:class]
|
14
|
-
Isomorfeus.raise_error(message: "Not a valid channel class #{processor_class_name}!") unless Isomorfeus.valid_channel_class_name?(processor_class_name)
|
15
|
-
processor_class = Isomorfeus.cached_channel_class(processor_class_name)
|
16
|
-
unless processor_class.respond_to?(:process_message)
|
17
|
-
Isomorfeus.raise_error(message: "Cannot process message, #{processor_class} must be a Channel and must have the on_message block defined!")
|
18
|
-
end
|
19
|
-
processor_class.process_message(message_hash[:notification][:message], message_hash[:notification][:error], message_hash[:notification][:channel])
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.process_response(response_hash)
|
23
|
-
response_hash[:response][:agent_ids].keys.each do |agent_id|
|
24
|
-
agent = Isomorfeus::Transport::RequestAgent.get!(agent_id)
|
25
|
-
Isomorfeus::Transport.unregister_request_in_progress(agent_id)
|
26
|
-
unless agent.promise.realized?
|
27
|
-
agent.full_response = response_hash
|
28
|
-
agent.response = response_hash[:response][:agent_ids][agent_id]
|
29
|
-
agent.promise.resolve(agent)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
1
|
+
module Isomorfeus
|
2
|
+
module Transport
|
3
|
+
class ClientProcessor
|
4
|
+
def self.process(json_hash)
|
5
|
+
if json_hash.key?(:response)
|
6
|
+
process_response(json_hash)
|
7
|
+
elsif json_hash.key?(:notification)
|
8
|
+
process_message(json_hash)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.process_message(message_hash)
|
13
|
+
processor_class_name = message_hash[:notification][:class]
|
14
|
+
Isomorfeus.raise_error(message: "Not a valid channel class #{processor_class_name}!") unless Isomorfeus.valid_channel_class_name?(processor_class_name)
|
15
|
+
processor_class = Isomorfeus.cached_channel_class(processor_class_name)
|
16
|
+
unless processor_class.respond_to?(:process_message)
|
17
|
+
Isomorfeus.raise_error(message: "Cannot process message, #{processor_class} must be a Channel and must have the on_message block defined!")
|
18
|
+
end
|
19
|
+
processor_class.process_message(message_hash[:notification][:message], message_hash[:notification][:error], message_hash[:notification][:channel])
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.process_response(response_hash)
|
23
|
+
response_hash[:response][:agent_ids].keys.each do |agent_id|
|
24
|
+
agent = Isomorfeus::Transport::RequestAgent.get!(agent_id)
|
25
|
+
Isomorfeus::Transport.unregister_request_in_progress(agent_id)
|
26
|
+
unless agent.promise.realized?
|
27
|
+
agent.full_response = response_hash
|
28
|
+
agent.response = response_hash[:response][:agent_ids][agent_id]
|
29
|
+
agent.promise.resolve(agent)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,166 +1,182 @@
|
|
1
|
-
module Isomorfeus
|
2
|
-
# available settings
|
3
|
-
class << self
|
4
|
-
def cached_channel_classes
|
5
|
-
@cached_channel_classes ||= {}
|
6
|
-
end
|
7
|
-
|
8
|
-
def cached_channel_class(class_name)
|
9
|
-
return "::#{class_name}".constantize if Isomorfeus.development?
|
10
|
-
return cached_channel_classes[class_name] if cached_channel_classes.key?(class_name)
|
11
|
-
cached_channel_classes[class_name] = "::#{class_name}".constantize
|
12
|
-
end
|
13
|
-
|
14
|
-
def valid_channel_class_names
|
15
|
-
@valid_channel_class_names ||= Set.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def add_valid_channel_class(klass)
|
19
|
-
valid_channel_class_names << raw_class_name(klass)
|
20
|
-
end
|
21
|
-
|
22
|
-
def raw_class_name(klass)
|
23
|
-
class_name = klass.name
|
24
|
-
class_name = class_name.split('>::').last if class_name.start_with?('#<')
|
25
|
-
class_name
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
if RUBY_ENGINE == 'opal'
|
30
|
-
add_client_option(:
|
31
|
-
add_client_option(:
|
32
|
-
add_client_option(:
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
attr_accessor :
|
70
|
-
attr_accessor :
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
1
|
+
module Isomorfeus
|
2
|
+
# available settings
|
3
|
+
class << self
|
4
|
+
def cached_channel_classes
|
5
|
+
@cached_channel_classes ||= {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def cached_channel_class(class_name)
|
9
|
+
return "::#{class_name}".constantize if Isomorfeus.development?
|
10
|
+
return cached_channel_classes[class_name] if cached_channel_classes.key?(class_name)
|
11
|
+
cached_channel_classes[class_name] = "::#{class_name}".constantize
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid_channel_class_names
|
15
|
+
@valid_channel_class_names ||= Set.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_valid_channel_class(klass)
|
19
|
+
valid_channel_class_names << raw_class_name(klass)
|
20
|
+
end
|
21
|
+
|
22
|
+
def raw_class_name(klass)
|
23
|
+
class_name = klass.name
|
24
|
+
class_name = class_name.split('>::').last if class_name.start_with?('#<')
|
25
|
+
class_name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if RUBY_ENGINE == 'opal'
|
30
|
+
add_client_option(:api_websocket_host)
|
31
|
+
add_client_option(:api_websocket_port)
|
32
|
+
add_client_option(:api_websocket_path)
|
33
|
+
add_client_option(:cookie_eater_path)
|
34
|
+
add_client_option(:transport_init_class_names, [])
|
35
|
+
|
36
|
+
class << self
|
37
|
+
def valid_channel_class_name?(class_name)
|
38
|
+
cached_channel_class(class_name) # because of autoloader
|
39
|
+
valid_channel_class_names.include?(class_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_transport_init_class_name(init_class_name)
|
43
|
+
transport_init_class_names << init_class_name
|
44
|
+
end
|
45
|
+
|
46
|
+
def current_user
|
47
|
+
@current_user ||= init_current_user
|
48
|
+
end
|
49
|
+
|
50
|
+
def init_current_user
|
51
|
+
if Isomorfeus.current_user_sid
|
52
|
+
Isomorfeus.instance_from_sid(Isomorfeus.current_user_sid)
|
53
|
+
else
|
54
|
+
Anonymous.new
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_current_user(user)
|
59
|
+
if user
|
60
|
+
@current_user = user
|
61
|
+
Isomorfeus.current_user_sid = user.sid
|
62
|
+
else
|
63
|
+
@current_user = Anonymous.new
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
else
|
68
|
+
class << self
|
69
|
+
attr_accessor :api_websocket_host
|
70
|
+
attr_accessor :api_websocket_port
|
71
|
+
attr_accessor :api_websocket_path
|
72
|
+
attr_accessor :cookie_eater_path
|
73
|
+
attr_reader :session_store
|
74
|
+
|
75
|
+
def valid_channel_class_name?(class_name)
|
76
|
+
valid_channel_class_names.include?(class_name)
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_middleware(middleware)
|
80
|
+
Isomorfeus.middlewares << middleware
|
81
|
+
end
|
82
|
+
|
83
|
+
def insert_middleware_after(existing_middleware, new_middleware)
|
84
|
+
index_of_existing = Isomorfeus.middlewares.index(existing_middleware)
|
85
|
+
unless Isomorfeus.middlewares.include?(new_middleware)
|
86
|
+
if index_of_existing
|
87
|
+
Isomorfeus.middlewares.insert(index_of_existing + 1, new_middleware)
|
88
|
+
else
|
89
|
+
Isomorfeus.middlewares << new_middleware
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def insert_middleware_before(existing_middleware, new_middleware)
|
95
|
+
index_of_existing = Isomorfeus.middlewares.index(existing_middleware)
|
96
|
+
unless Isomorfeus.middlewares.include?(new_middleware)
|
97
|
+
if index_of_existing
|
98
|
+
Isomorfeus.middlewares.insert(index_of_existing, new_middleware)
|
99
|
+
else
|
100
|
+
Isomorfeus.middlewares << new_middleware
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def middlewares
|
106
|
+
@middlewares ||= Set.new
|
107
|
+
end
|
108
|
+
|
109
|
+
def valid_handler_class_names
|
110
|
+
@valid_handler_class_names ||= Set.new
|
111
|
+
end
|
112
|
+
|
113
|
+
def valid_handler_class_name?(class_name)
|
114
|
+
valid_handler_class_names.include?(class_name)
|
115
|
+
end
|
116
|
+
|
117
|
+
def add_valid_handler_class(klass)
|
118
|
+
valid_handler_class_names << raw_class_name(klass)
|
119
|
+
end
|
120
|
+
|
121
|
+
def cached_handler_classes
|
122
|
+
@cached_handler_classes ||= {}
|
123
|
+
end
|
124
|
+
|
125
|
+
def cached_handler_class(class_name)
|
126
|
+
return "::#{class_name}".constantize if Isomorfeus.development?
|
127
|
+
return cached_handler_classes[class_name] if cached_handler_classes.key?(class_name)
|
128
|
+
cached_handler_classes[class_name] = "::#{class_name}".constantize
|
129
|
+
end
|
130
|
+
|
131
|
+
def valid_user_class_names
|
132
|
+
@valid_user_class_names ||= Set.new
|
133
|
+
end
|
134
|
+
|
135
|
+
def valid_user_class_name?(class_name)
|
136
|
+
valid_user_class_names.include?(class_name)
|
137
|
+
end
|
138
|
+
|
139
|
+
def add_valid_user_class(klass)
|
140
|
+
valid_user_class_names << raw_class_name(klass)
|
141
|
+
end
|
142
|
+
|
143
|
+
def cached_user_classes
|
144
|
+
@cached_user_classes ||= {}
|
145
|
+
end
|
146
|
+
|
147
|
+
def cached_user_class(class_name)
|
148
|
+
return "::#{class_name}".constantize if Isomorfeus.development?
|
149
|
+
return cached_user_classes[class_name] if cached_user_classes.key?(class_name)
|
150
|
+
cached_user_classes[class_name] = "::#{class_name}".constantize
|
151
|
+
end
|
152
|
+
|
153
|
+
def current_user
|
154
|
+
Thread.current[:isomorfeus_user]
|
155
|
+
end
|
156
|
+
|
157
|
+
def pub_sub_client
|
158
|
+
Thread.current[:isomorfeus_pub_sub_client]
|
159
|
+
end
|
160
|
+
|
161
|
+
def session_store
|
162
|
+
@session_store ||= @session_store_init.call
|
163
|
+
end
|
164
|
+
|
165
|
+
def session_store_init(&block)
|
166
|
+
@session_store_init = block
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
self.session_store_init do
|
171
|
+
store_path = File.expand_path(File.join(Isomorfeus.root, 'data', Isomorfeus.env), 'session_store')
|
172
|
+
Isomorfeus::Transport::HamsterSessionStore.new(store_path) # dont use this one, but we keep it here to have at least something
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# defaults
|
177
|
+
self.api_websocket_host = 'localhost'
|
178
|
+
self.api_websocket_port = '5000'
|
179
|
+
self.api_websocket_path = '/isomorfeus/api/websocket'
|
180
|
+
|
181
|
+
self.cookie_eater_path = '/isomorfeus/cookie/eat'
|
182
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Isomorfeus
|
2
|
+
module Transport
|
3
|
+
class HamsterSessionStore
|
4
|
+
class << self
|
5
|
+
def environment
|
6
|
+
@environment
|
7
|
+
end
|
8
|
+
|
9
|
+
def environment=(env)
|
10
|
+
@environment = env
|
11
|
+
end
|
12
|
+
|
13
|
+
def ref
|
14
|
+
@ref ||= 0
|
15
|
+
end
|
16
|
+
|
17
|
+
def ref=(val)
|
18
|
+
@ref = val
|
19
|
+
end
|
20
|
+
|
21
|
+
def refa
|
22
|
+
self.ref += 1
|
23
|
+
end
|
24
|
+
|
25
|
+
def refs
|
26
|
+
self.ref -= 1 if self.ref > 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def finalize(cls)
|
30
|
+
proc do
|
31
|
+
cls.refs
|
32
|
+
if cls.ref == 0
|
33
|
+
cls.environment.close rescue nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(cookie_hamster_path)
|
40
|
+
@cookie_hamster_path = cookie_hamster_path
|
41
|
+
open_environment
|
42
|
+
@db = self.class.environment.database('cookies', create: true)
|
43
|
+
ObjectSpace.define_finalizer(self, self.class.finalize(self.class))
|
44
|
+
end
|
45
|
+
|
46
|
+
def add(session_id:, cookie:, user:, accessor:)
|
47
|
+
@db.env.transaction do
|
48
|
+
@db.put(session_id, Oj.dump([user.class.to_s, user.key], mode: :strict))
|
49
|
+
@db.put(accessor, cookie)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def take_cookie(accessor:)
|
54
|
+
@db.env.transaction do
|
55
|
+
cookie = @db.get(accessor)
|
56
|
+
if cookie
|
57
|
+
session_info = cookie.split('; ').first
|
58
|
+
session_id = session_info.split('=').last.strip
|
59
|
+
@db.put("eaten_#{accessor}", session_id)
|
60
|
+
@db.delete(accessor)
|
61
|
+
else
|
62
|
+
# asked for the same cookie a second time
|
63
|
+
# can probably only be due to session hijacking
|
64
|
+
# so delete all sessions associated with that accessor
|
65
|
+
session_id = @db.get("eaten_#{accessor}")
|
66
|
+
@db.delete(session_id) if session_id
|
67
|
+
end
|
68
|
+
cookie
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def get_user(session_id:)
|
73
|
+
json = @db.get(session_id)
|
74
|
+
if json
|
75
|
+
user_info = Oj.load(json, mode: :strict)
|
76
|
+
user_info[0].constantize.load(key: user_info[1]) if user_info
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def remove(session_id:)
|
81
|
+
@db.env.transaction do
|
82
|
+
@db.delete(session_id)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def open_environment
|
89
|
+
return self.class.refa if self.class.environment
|
90
|
+
FileUtils.mkdir_p(@cookie_hamster_path) unless Dir.exist?(@cookie_hamster_path)
|
91
|
+
self.class.environment = Isomorfeus::Hamster.new(@cookie_hamster_path)
|
92
|
+
self.class.refa
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|