isomorfeus-transport 2.5.5 → 22.9.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/isomorfeus/core_ext/hash/deep_merge.rb +34 -0
  3. data/lib/isomorfeus/core_ext/kernel.rb +56 -0
  4. data/lib/isomorfeus/core_ext/object/deep_dup.rb +53 -0
  5. data/lib/isomorfeus/core_ext/object/duplicable.rb +60 -0
  6. data/lib/isomorfeus/transport/compressor_rack.rb +1 -1
  7. data/lib/isomorfeus/transport/config.rb +37 -0
  8. data/lib/isomorfeus/transport/rack_middleware.rb +16 -9
  9. data/lib/isomorfeus/transport/request_agent.rb +1 -0
  10. data/lib/isomorfeus/transport/server_socket_processor.rb +13 -1
  11. data/lib/isomorfeus/transport/version.rb +1 -1
  12. data/lib/isomorfeus/transport.rb +45 -38
  13. data/lib/isomorfeus-transport.rb +25 -16
  14. data/lib/lucid_channel.rb +103 -0
  15. data/lib/lucid_handler.rb +25 -0
  16. metadata +40 -90
  17. data/lib/isomorfeus/transport/handler/authentication_handler.rb +0 -55
  18. data/lib/isomorfeus/transport/imports.rb +0 -10
  19. data/lib/isomorfeus/transport/ssr_login.rb +0 -30
  20. data/lib/lucid_channel/base.rb +0 -8
  21. data/lib/lucid_channel/mixin.rb +0 -105
  22. data/lib/lucid_handler/base.rb +0 -8
  23. data/lib/lucid_handler/mixin.rb +0 -27
  24. data/node_modules/.package-lock.json +0 -27
  25. data/node_modules/ws/LICENSE +0 -19
  26. data/node_modules/ws/README.md +0 -489
  27. data/node_modules/ws/browser.js +0 -8
  28. data/node_modules/ws/index.js +0 -13
  29. data/node_modules/ws/lib/buffer-util.js +0 -126
  30. data/node_modules/ws/lib/constants.js +0 -12
  31. data/node_modules/ws/lib/event-target.js +0 -266
  32. data/node_modules/ws/lib/extension.js +0 -203
  33. data/node_modules/ws/lib/limiter.js +0 -55
  34. data/node_modules/ws/lib/permessage-deflate.js +0 -511
  35. data/node_modules/ws/lib/receiver.js +0 -618
  36. data/node_modules/ws/lib/sender.js +0 -478
  37. data/node_modules/ws/lib/stream.js +0 -159
  38. data/node_modules/ws/lib/subprotocol.js +0 -62
  39. data/node_modules/ws/lib/validation.js +0 -124
  40. data/node_modules/ws/lib/websocket-server.js +0 -488
  41. data/node_modules/ws/lib/websocket.js +0 -1264
  42. data/node_modules/ws/package.json +0 -61
  43. data/node_modules/ws/wrapper.mjs +0 -8
  44. data/package.json +0 -6
@@ -0,0 +1,103 @@
1
+ class LucidChannel
2
+ class << self
3
+ def inherited(base)
4
+ Isomorfeus.add_valid_channel_class(base)
5
+ end
6
+
7
+ def subscription_channels
8
+ @subscription_channels ||= {}
9
+ end
10
+
11
+ def channel(name, options = {})
12
+ subscription_channels[name.to_s] = options
13
+ end
14
+
15
+ def valid_channel?(name)
16
+ name = name.to_s
17
+ subscription_channels.key?(name) || name == self.name
18
+ end
19
+
20
+ def process_message(message, error, channel = nil)
21
+ channel = self.name unless channel
22
+ channel = channel.to_s
23
+ unless valid_channel?(channel)
24
+ Isomorfeus.raise_error(message: "No such channel '#{channel}' declared for #{self.name}! Cannot process message")
25
+ end
26
+ block = subscription_channels[channel][:block]
27
+ Isomorfeus.raise_error(message: "#{self} received: #{channel} #{message}, but no 'on_message' block defined!") unless block
28
+ block.call(message, error)
29
+ nil
30
+ end
31
+
32
+ def on_message(channel = nil, &block)
33
+ channel = self.name unless channel
34
+ channel = channel.to_s
35
+ unless valid_channel?(channel)
36
+ Isomorfeus.raise_error(message: "No such channel #{channel} declared, please declare it first!")
37
+ end
38
+ subscription_channels[channel] = {} unless subscription_channels.key?(channel)
39
+ subscription_channels[channel][:block] = block
40
+ end
41
+
42
+ def send_message(message, channel = nil)
43
+ channel = self.name unless channel
44
+ unless valid_channel?(channel)
45
+ Isomorfeus.raise_error(message: "No such channel '#{channel}' declared for #{self.name}! Cannot send message")
46
+ end
47
+ Isomorfeus::Transport.send_message(self, channel, message)
48
+ end
49
+
50
+ def subscribe(channel = nil)
51
+ promise_subscribe(channel)
52
+ nil
53
+ end
54
+
55
+ def promise_subscribe(channel = nil)
56
+ channel = channel ? channel : self.name
57
+ Isomorfeus::Transport.promise_subscribe(self.name, channel)
58
+ end
59
+
60
+ def unsubscribe(channel = nil)
61
+ promise_unsubscribe(channel)
62
+ nil
63
+ end
64
+
65
+ def promise_unsubscribe(channel = nil)
66
+ channel = channel ? channel : self.name
67
+ Isomorfeus::Transport.promise_unsubscribe(self.name, channel)
68
+ end
69
+
70
+ if RUBY_ENGINE == 'opal'
71
+ def server_subscription_channels; end
72
+ def server_process_message(message, channel = nil); end
73
+ def server_on_message(channel = nil, &block); end
74
+ else
75
+ def server_is_processing_messages?(channel)
76
+ return false if server_subscription_channels.empty?
77
+ return true if server_subscription_channels.key?(channel) && server_subscription_channels[channel].key?(:block)
78
+ false
79
+ end
80
+
81
+ def server_subscription_channels
82
+ @server_subscription_channels ||= {}
83
+ end
84
+
85
+ def server_process_message(message, channel = nil)
86
+ channel = self.name unless channel
87
+ channel = channel.to_s
88
+ block = server_subscription_channels[channel][:block]
89
+ block.call(message)
90
+ end
91
+
92
+ def server_on_message(channel = nil, &block)
93
+ channel = self.name unless channel
94
+ channel = channel.to_s
95
+ unless valid_channel?(channel)
96
+ Isomorfeus.raise_error(message: "No such channel #{channel} declared, please declare it first!")
97
+ end
98
+ server_subscription_channels[channel] = {} unless server_subscription_channels.key?(channel)
99
+ server_subscription_channels[channel][:block] = block
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,25 @@
1
+ class LucidHandler
2
+ class << self
3
+ def inherited(base)
4
+ Isomorfeus.add_valid_handler_class(base)
5
+ end
6
+
7
+ def on_request(&block)
8
+ define_method :process_request do |*args|
9
+ instance_exec(*args, &block)
10
+ end
11
+ end
12
+ end
13
+
14
+ def resolving?
15
+ false
16
+ end
17
+
18
+ def current_user
19
+ Isomorfeus.current_user
20
+ end
21
+
22
+ def pub_sub_client
23
+ Isomorfeus.pub_sub_client
24
+ end
25
+ 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: 2.5.5
4
+ version: 22.9.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.2
19
+ version: 7.0.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 7.0.2
26
+ version: 7.0.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bcrypt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.1.16
33
+ version: 3.1.18
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.1.16
40
+ version: 3.1.18
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: brotli
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -53,145 +53,117 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.4.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: isomorfeus-iodine
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.7.50
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.7.50
69
- - !ruby/object:Gem::Dependency
70
- name: oj
56
+ name: concurrent-ruby
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - "~>"
74
60
  - !ruby/object:Gem::Version
75
- version: 3.13.13
61
+ version: 1.1.10
76
62
  type: :runtime
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
66
  - - "~>"
81
67
  - !ruby/object:Gem::Version
82
- version: 3.13.13
68
+ version: 1.1.10
83
69
  - !ruby/object:Gem::Dependency
84
- name: opal
70
+ name: isomorfeus-iodine
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: 1.5.0
75
+ version: 0.8.0
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: 1.5.0
82
+ version: 0.8.0
97
83
  - !ruby/object:Gem::Dependency
98
- name: isomorfeus-asset-manager
84
+ name: oj
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - "~>"
102
88
  - !ruby/object:Gem::Version
103
- version: 0.14.24
89
+ version: 3.13.21
104
90
  type: :runtime
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - "~>"
109
95
  - !ruby/object:Gem::Version
110
- version: 0.14.24
96
+ version: 3.13.21
111
97
  - !ruby/object:Gem::Dependency
112
- name: isomorfeus-preact
98
+ name: opal
113
99
  requirement: !ruby/object:Gem::Requirement
114
100
  requirements:
115
101
  - - "~>"
116
102
  - !ruby/object:Gem::Version
117
- version: 10.7.2
103
+ version: 1.5.1
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
107
  requirements:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
- version: 10.7.2
125
- - !ruby/object:Gem::Dependency
126
- name: isomorfeus-policy
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '='
130
- - !ruby/object:Gem::Version
131
- version: 2.5.5
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '='
137
- - !ruby/object:Gem::Version
138
- version: 2.5.5
110
+ version: 1.5.1
139
111
  - !ruby/object:Gem::Dependency
140
- name: isomorfeus-redux
112
+ name: opal-zeitwerk
141
113
  requirement: !ruby/object:Gem::Requirement
142
114
  requirements:
143
115
  - - "~>"
144
116
  - !ruby/object:Gem::Version
145
- version: 4.2.0
117
+ version: 0.4.1
146
118
  type: :runtime
147
119
  prerelease: false
148
120
  version_requirements: !ruby/object:Gem::Requirement
149
121
  requirements:
150
122
  - - "~>"
151
123
  - !ruby/object:Gem::Version
152
- version: 4.2.0
124
+ version: 0.4.1
153
125
  - !ruby/object:Gem::Dependency
154
- name: isomorfeus-speednode
126
+ name: rack
155
127
  requirement: !ruby/object:Gem::Requirement
156
128
  requirements:
157
129
  - - "~>"
158
130
  - !ruby/object:Gem::Version
159
- version: 0.5.3
131
+ version: 3.0.0
160
132
  type: :runtime
161
133
  prerelease: false
162
134
  version_requirements: !ruby/object:Gem::Requirement
163
135
  requirements:
164
136
  - - "~>"
165
137
  - !ruby/object:Gem::Version
166
- version: 0.5.3
138
+ version: 3.0.0
167
139
  - !ruby/object:Gem::Dependency
168
- name: rack
140
+ name: rackup
169
141
  requirement: !ruby/object:Gem::Requirement
170
142
  requirements:
171
143
  - - "~>"
172
144
  - !ruby/object:Gem::Version
173
- version: 2.2.3
145
+ version: 0.2.2
174
146
  type: :runtime
175
147
  prerelease: false
176
148
  version_requirements: !ruby/object:Gem::Requirement
177
149
  requirements:
178
150
  - - "~>"
179
151
  - !ruby/object:Gem::Version
180
- version: 2.2.3
152
+ version: 0.2.2
181
153
  - !ruby/object:Gem::Dependency
182
- name: sorted_set
154
+ name: zeitwerk
183
155
  requirement: !ruby/object:Gem::Requirement
184
156
  requirements:
185
157
  - - "~>"
186
158
  - !ruby/object:Gem::Version
187
- version: 1.0.3
159
+ version: 2.5.4
188
160
  type: :runtime
189
161
  prerelease: false
190
162
  version_requirements: !ruby/object:Gem::Requirement
191
163
  requirements:
192
164
  - - "~>"
193
165
  - !ruby/object:Gem::Version
194
- version: 1.0.3
166
+ version: 2.5.4
195
167
  - !ruby/object:Gem::Dependency
196
168
  name: zlib
197
169
  requirement: !ruby/object:Gem::Requirement
@@ -212,14 +184,14 @@ dependencies:
212
184
  requirements:
213
185
  - - '='
214
186
  - !ruby/object:Gem::Version
215
- version: 2.5.5
187
+ version: 22.9.0.rc2
216
188
  type: :development
217
189
  prerelease: false
218
190
  version_requirements: !ruby/object:Gem::Requirement
219
191
  requirements:
220
192
  - - '='
221
193
  - !ruby/object:Gem::Version
222
- version: 2.5.5
194
+ version: 22.9.0.rc2
223
195
  - !ruby/object:Gem::Dependency
224
196
  name: rake
225
197
  requirement: !ruby/object:Gem::Requirement
@@ -257,46 +229,24 @@ files:
257
229
  - LICENSE
258
230
  - README.md
259
231
  - lib/isomorfeus-transport.rb
232
+ - lib/isomorfeus/core_ext/hash/deep_merge.rb
233
+ - lib/isomorfeus/core_ext/kernel.rb
234
+ - lib/isomorfeus/core_ext/object/deep_dup.rb
235
+ - lib/isomorfeus/core_ext/object/duplicable.rb
260
236
  - lib/isomorfeus/transport.rb
261
237
  - lib/isomorfeus/transport/client_processor.rb
262
238
  - lib/isomorfeus/transport/compressor_rack.rb
263
239
  - lib/isomorfeus/transport/config.rb
264
- - lib/isomorfeus/transport/handler/authentication_handler.rb
265
- - lib/isomorfeus/transport/imports.rb
266
240
  - lib/isomorfeus/transport/middlewares.rb
267
241
  - lib/isomorfeus/transport/rack_middleware.rb
268
242
  - lib/isomorfeus/transport/request_agent.rb
269
243
  - lib/isomorfeus/transport/response_agent.rb
270
244
  - lib/isomorfeus/transport/server_processor.rb
271
245
  - lib/isomorfeus/transport/server_socket_processor.rb
272
- - lib/isomorfeus/transport/ssr_login.rb
273
246
  - lib/isomorfeus/transport/version.rb
274
247
  - lib/isomorfeus/transport/websocket_client.rb
275
- - lib/lucid_channel/base.rb
276
- - lib/lucid_channel/mixin.rb
277
- - lib/lucid_handler/base.rb
278
- - lib/lucid_handler/mixin.rb
279
- - node_modules/.package-lock.json
280
- - node_modules/ws/LICENSE
281
- - node_modules/ws/README.md
282
- - node_modules/ws/browser.js
283
- - node_modules/ws/index.js
284
- - node_modules/ws/lib/buffer-util.js
285
- - node_modules/ws/lib/constants.js
286
- - node_modules/ws/lib/event-target.js
287
- - node_modules/ws/lib/extension.js
288
- - node_modules/ws/lib/limiter.js
289
- - node_modules/ws/lib/permessage-deflate.js
290
- - node_modules/ws/lib/receiver.js
291
- - node_modules/ws/lib/sender.js
292
- - node_modules/ws/lib/stream.js
293
- - node_modules/ws/lib/subprotocol.js
294
- - node_modules/ws/lib/validation.js
295
- - node_modules/ws/lib/websocket-server.js
296
- - node_modules/ws/lib/websocket.js
297
- - node_modules/ws/package.json
298
- - node_modules/ws/wrapper.mjs
299
- - package.json
248
+ - lib/lucid_channel.rb
249
+ - lib/lucid_handler.rb
300
250
  homepage: https://isomorfeus.com
301
251
  licenses:
302
252
  - MIT
@@ -314,9 +264,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
314
264
  version: '0'
315
265
  required_rubygems_version: !ruby/object:Gem::Requirement
316
266
  requirements:
317
- - - ">="
267
+ - - ">"
318
268
  - !ruby/object:Gem::Version
319
- version: '0'
269
+ version: 1.3.1
320
270
  requirements: []
321
271
  rubygems_version: 3.3.7
322
272
  signing_key:
@@ -1,55 +0,0 @@
1
- module Isomorfeus
2
- module Transport
3
- module Handler
4
- class AuthenticationHandler < LucidHandler::Base
5
- TIMEOUT = 30
6
-
7
- on_request do |response_agent|
8
- # promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'login', user_class_name, user_identifier, user_password)
9
- response_agent.request.each_key do |login_or_ssr_login|
10
- if login_or_ssr_login == 'login'
11
- response_agent.agent_result = { error: 'Authentication failed' }
12
- tries = pub_sub_client.instance_variable_get(:@isomorfeus_authentication_tries)
13
- tries = 0 unless tries
14
- tries += 1
15
- sleep(5) if tries > 3 # TODO, this needs a better solution (store data in user/session)
16
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, tries)
17
- response_agent.request['login'].each_key do |user_class_name|
18
- user = nil
19
- if Isomorfeus.valid_user_class_name?(user_class_name)
20
- user_class = Isomorfeus.cached_user_class(user_class_name)
21
- user_identifier = response_agent.request['login'][user_class_name].keys.first
22
- promise = user_class.promise_login(user: user_identifier, pass: response_agent.request['login'][user_class_name][user_identifier])
23
- unless promise.realized?
24
- start = Time.now
25
- until promise.realized?
26
- break if (Time.now - start) > TIMEOUT
27
- sleep 0.01
28
- end
29
- end
30
- user = promise.value
31
- end
32
- if user
33
- session_id = SecureRandom.uuid
34
- session_cookie = "session=#{session_id}; SameSite=Strict; HttpOnly; Path=/; Max-Age=2592000#{'; Secure' if Isomorfeus.production?}"
35
- session_cookie_accessor = SecureRandom.uuid
36
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
37
- Isomorfeus.session_class.add(session_id: session_id, cookie: session_cookie, user: user, accessor: session_cookie_accessor)
38
- response_agent.agent_result = { success: 'ok', data: user.to_transport, session_cookie_accessor: session_cookie_accessor }
39
- end
40
- end
41
- elsif login_or_ssr_login == 'ssr_login'
42
- response_agent.agent_result = { error: 'Authentication failed' }
43
- session_id = response_agent.request['ssr_login']
44
- user = Isomorfeus.session_class.get_user(session_id: session_id)
45
- if user
46
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
47
- response_agent.agent_result = { success: 'ok', data: user.to_transport }
48
- end
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,10 +0,0 @@
1
- module Isomorfeus
2
- module Transport
3
- module Imports
4
- def self.add
5
- Isomorfeus.add_ssr_js_import('ws', 'WebSocket')
6
- Isomorfeus.add_ssr_ruby_import('isomorfeus/transport/ssr_login')
7
- end
8
- end
9
- end
10
- end
@@ -1,30 +0,0 @@
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
29
-
30
- Isomorfeus.add_transport_init_class_name('Isomorfeus::Transport::SsrLogin')
@@ -1,8 +0,0 @@
1
- module LucidChannel
2
- class Base
3
- def self.inherited(base)
4
- base.include LucidChannel::Mixin
5
- Isomorfeus.add_valid_channel_class(base)
6
- end
7
- end
8
- end
@@ -1,105 +0,0 @@
1
- module LucidChannel
2
- module Mixin
3
- def self.included(base)
4
- Isomorfeus.add_valid_channel_class(base) unless base == LucidChannel::Base
5
-
6
- base.instance_exec do
7
- def subscription_channels
8
- @subscription_channels ||= {}
9
- end
10
-
11
- def channel(name, options = {})
12
- subscription_channels[name.to_s] = options
13
- end
14
-
15
- def valid_channel?(name)
16
- name = name.to_s
17
- subscription_channels.key?(name) || name == self.name
18
- end
19
-
20
- def process_message(message, error, channel = nil)
21
- channel = self.name unless channel
22
- channel = channel.to_s
23
- unless valid_channel?(channel)
24
- Isomorfeus.raise_error(message: "No such channel '#{channel}' declared for #{self.name}! Cannot process message")
25
- end
26
- block = subscription_channels[channel][:block]
27
- Isomorfeus.raise_error(message: "#{self} received: #{channel} #{message}, but no 'on_message' block defined!") unless block
28
- block.call(message, error)
29
- nil
30
- end
31
-
32
- def on_message(channel = nil, &block)
33
- channel = self.name unless channel
34
- channel = channel.to_s
35
- unless valid_channel?(channel)
36
- Isomorfeus.raise_error(message: "No such channel #{channel} declared, please declare it first!")
37
- end
38
- subscription_channels[channel] = {} unless subscription_channels.key?(channel)
39
- subscription_channels[channel][:block] = block
40
- end
41
-
42
- def send_message(message, channel = nil)
43
- channel = self.name unless channel
44
- unless valid_channel?(channel)
45
- Isomorfeus.raise_error(message: "No such channel '#{channel}' declared for #{self.name}! Cannot send message")
46
- end
47
- Isomorfeus::Transport.send_message(self, channel, message)
48
- end
49
-
50
- def subscribe(channel = nil)
51
- promise_subscribe(channel)
52
- nil
53
- end
54
-
55
- def promise_subscribe(channel = nil)
56
- channel = channel ? channel : self.name
57
- Isomorfeus::Transport.promise_subscribe(self.name, channel)
58
- end
59
-
60
- def unsubscribe(channel = nil)
61
- promise_unsubscribe(channel)
62
- nil
63
- end
64
-
65
- def promise_unsubscribe(channel = nil)
66
- channel = channel ? channel : self.name
67
- Isomorfeus::Transport.promise_unsubscribe(self.name, channel)
68
- end
69
-
70
- if RUBY_ENGINE == 'opal'
71
- def server_subscription_channels; end
72
- def server_process_message(message, channel = nil); end
73
- def server_on_message(channel = nil, &block); end
74
- else
75
- def server_is_processing_messages?(channel)
76
- return false if server_subscription_channels.empty?
77
- return true if server_subscription_channels.key?(channel) && server_subscription_channels[channel].key?(:block)
78
- false
79
- end
80
-
81
- def server_subscription_channels
82
- @server_subscription_channels ||= {}
83
- end
84
-
85
- def server_process_message(message, channel = nil)
86
- channel = self.name unless channel
87
- channel = channel.to_s
88
- block = server_subscription_channels[channel][:block]
89
- block.call(message)
90
- end
91
-
92
- def server_on_message(channel = nil, &block)
93
- channel = self.name unless channel
94
- channel = channel.to_s
95
- unless valid_channel?(channel)
96
- Isomorfeus.raise_error(message: "No such channel #{channel} declared, please declare it first!")
97
- end
98
- server_subscription_channels[channel] = {} unless server_subscription_channels.key?(channel)
99
- server_subscription_channels[channel][:block] = block
100
- end
101
- end
102
- end
103
- end
104
- end
105
- end
@@ -1,8 +0,0 @@
1
- module LucidHandler
2
- class Base
3
- def self.inherited(base)
4
- base.include LucidHandler::Mixin
5
- Isomorfeus.add_valid_handler_class(base)
6
- end
7
- end
8
- end
@@ -1,27 +0,0 @@
1
- module LucidHandler
2
- module Mixin
3
- def self.included(base)
4
- Isomorfeus.add_valid_handler_class(base) unless base == LucidHandler::Base
5
-
6
- base.instance_exec do
7
- def on_request(&block)
8
- define_method :process_request do |*args|
9
- instance_exec(*args, &block)
10
- end
11
- end
12
- end
13
- end
14
-
15
- def resolving?
16
- false
17
- end
18
-
19
- def current_user
20
- Isomorfeus.current_user
21
- end
22
-
23
- def pub_sub_client
24
- Isomorfeus.pub_sub_client
25
- end
26
- end
27
- end