isomorfeus-transport 1.0.0.zeta24 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +27 -36
  4. data/lib/isomorfeus/transport/client_processor.rb +35 -35
  5. data/lib/isomorfeus/transport/config.rb +182 -166
  6. data/lib/isomorfeus/transport/hamster_session_store.rb +96 -0
  7. data/lib/isomorfeus/transport/handler/authentication_handler.rb +70 -70
  8. data/lib/isomorfeus/transport/imports.rb +9 -0
  9. data/lib/isomorfeus/transport/middlewares.rb +13 -13
  10. data/lib/isomorfeus/transport/rack_middleware.rb +59 -55
  11. data/lib/isomorfeus/transport/request_agent.rb +34 -34
  12. data/lib/isomorfeus/transport/response_agent.rb +23 -23
  13. data/lib/isomorfeus/transport/server_processor.rb +129 -129
  14. data/lib/isomorfeus/transport/server_socket_processor.rb +54 -54
  15. data/lib/isomorfeus/transport/ssr_login.rb +28 -28
  16. data/lib/isomorfeus/transport/version.rb +5 -5
  17. data/lib/isomorfeus/transport/{websocket.rb → websocket_client.rb} +123 -123
  18. data/lib/isomorfeus/transport.rb +200 -196
  19. data/lib/isomorfeus-transport.rb +70 -61
  20. data/lib/lucid_authentication/mixin.rb +122 -122
  21. data/lib/lucid_channel/base.rb +8 -9
  22. data/lib/lucid_channel/mixin.rb +105 -105
  23. data/lib/lucid_handler/base.rb +8 -9
  24. data/lib/lucid_handler/mixin.rb +27 -27
  25. data/node_modules/.package-lock.json +27 -0
  26. data/node_modules/ws/LICENSE +19 -0
  27. data/node_modules/ws/README.md +496 -0
  28. data/node_modules/ws/browser.js +8 -0
  29. data/node_modules/ws/index.js +13 -0
  30. data/node_modules/ws/lib/buffer-util.js +126 -0
  31. data/node_modules/ws/lib/constants.js +12 -0
  32. data/node_modules/ws/lib/event-target.js +266 -0
  33. data/node_modules/ws/lib/extension.js +203 -0
  34. data/node_modules/ws/lib/limiter.js +55 -0
  35. data/node_modules/ws/lib/permessage-deflate.js +511 -0
  36. data/node_modules/ws/lib/receiver.js +612 -0
  37. data/node_modules/ws/lib/sender.js +414 -0
  38. data/node_modules/ws/lib/stream.js +180 -0
  39. data/node_modules/ws/lib/subprotocol.js +62 -0
  40. data/node_modules/ws/lib/validation.js +124 -0
  41. data/node_modules/ws/lib/websocket-server.js +485 -0
  42. data/node_modules/ws/lib/websocket.js +1144 -0
  43. data/node_modules/ws/package.json +61 -0
  44. data/node_modules/ws/wrapper.mjs +8 -0
  45. data/package.json +6 -0
  46. metadata +76 -54
  47. data/lib/isomorfeus/transport/dbm_session_store.rb +0 -51
@@ -1,61 +1,70 @@
1
- require 'isomorfeus-policy'
2
- require 'lucid_authentication/mixin'
3
- if RUBY_ENGINE == 'opal'
4
- require 'json'
5
- require 'isomorfeus/transport/version'
6
- require 'isomorfeus/transport/config'
7
- require 'isomorfeus/transport/request_agent'
8
- require 'isomorfeus/transport/client_processor'
9
- require 'isomorfeus/transport/websocket'
10
- require 'isomorfeus/transport'
11
- require 'isomorfeus/transport/ssr_login'
12
- require 'lucid_channel/mixin'
13
- require 'lucid_channel/base'
14
- Isomorfeus.zeitwerk.push_dir('channels')
15
- Isomorfeus.add_client_init_class_name('Isomorfeus::Transport')
16
- Isomorfeus.add_transport_init_class_name('Isomorfeus::Transport::SsrLogin') if Isomorfeus.on_ssr?
17
- else
18
- require 'base64'
19
- require 'digest'
20
- require 'bcrypt'
21
- require 'ostruct'
22
- require 'socket'
23
- require 'oj'
24
- require 'websocket/driver'
25
- require 'active_support'
26
- require 'iodine'
27
- require 'dbm'
28
- require 'isomorfeus/transport/dbm_session_store'
29
- opal_path = Gem::Specification.find_by_name('opal').full_gem_path
30
- promise_path = File.join(opal_path, 'stdlib', 'promise.rb')
31
- require promise_path
32
- require 'isomorfeus/transport/version'
33
- require 'isomorfeus/transport/response_agent'
34
- require 'isomorfeus/transport/config'
35
- require 'isomorfeus/transport/middlewares'
36
- require 'isomorfeus/transport/request_agent'
37
- require 'isomorfeus/transport/server_processor'
38
- require 'isomorfeus/transport/server_socket_processor'
39
- require 'isomorfeus/transport/websocket'
40
- require 'isomorfeus/transport'
41
- require 'isomorfeus/transport/rack_middleware'
42
- require 'isomorfeus/transport/middlewares'
43
-
44
- Isomorfeus.add_middleware(Isomorfeus::Transport::RackMiddleware)
45
-
46
- require 'lucid_handler/mixin'
47
- require 'lucid_handler/base'
48
- require 'lucid_channel/mixin'
49
- require 'lucid_channel/base'
50
-
51
- require 'isomorfeus/transport/handler/authentication_handler'
52
-
53
- Opal.append_path(__dir__.untaint) unless Opal.paths.include?(__dir__.untaint)
54
-
55
- %w[channels handlers server].each do |dir|
56
- path = File.expand_path(File.join('app', dir))
57
- if Dir.exist?(path)
58
- Isomorfeus.zeitwerk.push_dir(path)
59
- end
60
- end
61
- end
1
+ require 'isomorfeus-policy'
2
+ require 'lucid_authentication/mixin'
3
+ if RUBY_ENGINE == 'opal'
4
+ require 'json'
5
+ require 'isomorfeus/transport/version'
6
+ require 'isomorfeus/transport/config'
7
+ require 'isomorfeus/transport/request_agent'
8
+ require 'isomorfeus/transport/client_processor'
9
+ require 'isomorfeus/transport/websocket_client'
10
+ require 'isomorfeus/transport'
11
+ require 'isomorfeus/transport/ssr_login'
12
+ require 'lucid_channel/mixin'
13
+ require 'lucid_channel/base'
14
+ Isomorfeus.zeitwerk.push_dir('channels')
15
+ Isomorfeus.add_client_init_class_name('Isomorfeus::Transport')
16
+ Isomorfeus.add_transport_init_class_name('Isomorfeus::Transport::SsrLogin') if Isomorfeus.on_ssr?
17
+ else
18
+ require 'base64'
19
+ require 'digest'
20
+ require 'bcrypt'
21
+ require 'securerandom'
22
+ require 'fileutils'
23
+ require 'ostruct'
24
+ require 'socket'
25
+ require 'sorted_set'
26
+ require 'oj'
27
+ require 'active_support'
28
+ require 'isomorfeus-asset-manager'
29
+ require 'isomorfeus/transport/hamster_session_store'
30
+ opal_path = Gem::Specification.find_by_name('opal').full_gem_path
31
+ promise_path = File.join(opal_path, 'stdlib', 'promise.rb')
32
+ require promise_path
33
+ require 'isomorfeus/transport/version'
34
+ require 'isomorfeus/transport/response_agent'
35
+ require 'isomorfeus/transport/config'
36
+ require 'isomorfeus/transport/middlewares'
37
+ require 'isomorfeus/transport/request_agent'
38
+ require 'isomorfeus/transport/server_processor'
39
+ require 'isomorfeus/transport/server_socket_processor'
40
+ require 'isomorfeus/transport/websocket_client'
41
+ require 'isomorfeus/transport'
42
+ require 'isomorfeus/transport/rack_middleware'
43
+ require 'isomorfeus/transport/middlewares'
44
+
45
+ Isomorfeus.add_middleware(Isomorfeus::Transport::RackMiddleware)
46
+ Isomorfeus.add_middleware(Isomorfeus::AssetManager::RackMiddleware)
47
+
48
+ require 'lucid_handler/mixin'
49
+ require 'lucid_handler/base'
50
+ require 'lucid_channel/mixin'
51
+ require 'lucid_channel/base'
52
+
53
+ require 'isomorfeus/transport/handler/authentication_handler'
54
+
55
+ require 'iso_opal'
56
+ Opal.append_path(__dir__.untaint) unless IsoOpal.paths_include?(__dir__.untaint)
57
+
58
+ %w[channels handlers server].each do |dir|
59
+ path = File.expand_path(File.join('app', dir))
60
+ if Dir.exist?(path)
61
+ Isomorfeus.zeitwerk.push_dir(path)
62
+ end
63
+ end
64
+
65
+ require 'isomorfeus-speednode'
66
+ Isomorfeus.node_paths << File.expand_path(File.join(File.dirname(__FILE__), '..', 'node_modules'))
67
+
68
+ require 'isomorfeus/transport/imports'
69
+ Isomorfeus::Transport::Imports.add
70
+ end
@@ -1,122 +1,122 @@
1
- module LucidAuthentication
2
- module Mixin
3
- def anonymous?
4
- self.class == Anonymous
5
- end
6
-
7
- if RUBY_ENGINE == 'opal'
8
- def self.included(base)
9
- base.instance_exec do
10
- def execute_login(&block)
11
- end
12
-
13
- def promise_login(user: nil, pass: nil, scheme: :isomorfeus, &block)
14
- send("promise_authentication_with_#{scheme}", user: user, pass: pass, &block)
15
- end
16
-
17
- def promise_authentication_with_isomorfeus(user: nil, pass: nil, &block)
18
- if Isomorfeus.production?
19
- Isomorfeus.raise_error(message: "Connection not secure, can't login!") unless Isomorfeus::Transport.socket.url.start_with?('wss:')
20
- else
21
- `console.warn("Connection not secure, ensure a secure connection in production, otherwise login will fail!")` unless Isomorfeus::Transport.socket.url.start_with?('wss:')
22
- end
23
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'login', self.name, user, pass).then do |agent|
24
- if agent.processed
25
- agent.result
26
- else
27
- agent.processed = true
28
- if agent.response.key?(:success)
29
- Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.response[:data])
30
- class_name = agent.response[:data].keys.first
31
- key = agent.response[:data][class_name].keys.first
32
- logged_in_user = Isomorfeus.cached_data_class(class_name).new(key: key)
33
- cookie_accessor = agent.response[:session_cookie_accessor]
34
- begin
35
- target = if block_given?
36
- block.call(logged_in_user)
37
- else
38
- `window.location.pathname`
39
- end
40
- unless target.class == String && target.start_with?('/')
41
- Isomorfeus.raise_error(message: "A path must be returned as string starting with '/', returned was #{target}!")
42
- end
43
- rescue
44
- target = `window.location.pathname`
45
- end
46
- cookie_query = "#{Isomorfeus.cookie_eater_path}?#{cookie_accessor}=#{target}"
47
- `window.location = cookie_query` # doing page load and redirect
48
- nil
49
- else
50
- Isomorfeus.raise_error(message: "Login failed with '#{agent.response[:error]}'!") # triggers .fail
51
- end
52
- end
53
- end
54
- end
55
- end
56
- end
57
-
58
- def promise_logout(scheme: :isomorfeus)
59
- send("promise_deauthentication_with_#{scheme}")
60
- end
61
-
62
- def promise_deauthentication_with_isomorfeus
63
- Isomorfeus::Transport.promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'logout', 'logout').then do |agent|
64
- `document.cookie = "session="`
65
- Isomorfeus.set_current_user(nil)
66
- Isomorfeus.force_init_store!
67
- agent.processed = true
68
- agent.response.key?(:success) ? true : raise('Logout failed!')
69
- end
70
- end
71
- else
72
- def self.included(base)
73
- Isomorfeus.add_valid_user_class(base)
74
-
75
- base.instance_exec do
76
- def execute_login(&block)
77
- @execute_login_block = block
78
- end
79
-
80
- def promise_login(user: nil, pass: nil, scheme: :isomorfeus, &block)
81
- send("promise_authentication_with_#{scheme}", user: user, pass: pass, &block)
82
- end
83
-
84
- def promise_authentication_with_isomorfeus(user: nil, pass: nil, &block)
85
- promise_or_user = @execute_login_block.call(user: user, pass: pass)
86
- if promise_or_user.class == Promise
87
- if block_given?
88
- promise_or_user.then do |user|
89
- block.call(user)
90
- user
91
- end
92
- else
93
- promise_or_user
94
- end
95
- else
96
- block.call(user) if block_given?
97
- Promise.new.resolve(promise_or_user)
98
- end
99
- end
100
- end
101
- end
102
-
103
- def encrypt_password(password, password_confirmation)
104
- raise "Password and confirmation don't match!" unless password == password_confirmation
105
- BCrypt::Password.create(password).to_s
106
- end
107
-
108
- def passwords_match?(encrypted_password, given_password)
109
- bcrypt_pass = BCrypt::Password.new(encrypted_password)
110
- bcrypt_pass == given_password
111
- end
112
-
113
- def promise_logout(scheme: :isomorfeus)
114
- send("promise_deauthentication_with_#{scheme}")
115
- end
116
-
117
- def promise_deauthentication_with_isomorfeus
118
- Promise.new.resolve(true)
119
- end
120
- end
121
- end
122
- end
1
+ module LucidAuthentication
2
+ module Mixin
3
+ def anonymous?
4
+ self.class == Anonymous
5
+ end
6
+
7
+ if RUBY_ENGINE == 'opal'
8
+ def self.included(base)
9
+ base.instance_exec do
10
+ def execute_login(&block)
11
+ end
12
+
13
+ def promise_login(user: nil, pass: nil, scheme: :isomorfeus, &block)
14
+ send("promise_authentication_with_#{scheme}", user: user, pass: pass, &block)
15
+ end
16
+
17
+ def promise_authentication_with_isomorfeus(user: nil, pass: nil, &block)
18
+ if Isomorfeus.production?
19
+ Isomorfeus.raise_error(message: "Connection not secure, can't login!") unless Isomorfeus::Transport.socket.url.start_with?('wss:')
20
+ else
21
+ `console.warn("Connection not secure, ensure a secure connection in production, otherwise login will fail!")` unless Isomorfeus::Transport.socket.url.start_with?('wss:')
22
+ end
23
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'login', self.name, user, pass).then do |agent|
24
+ if agent.processed
25
+ agent.result
26
+ else
27
+ agent.processed = true
28
+ if agent.response.key?(:success)
29
+ Isomorfeus.store.dispatch(type: 'DATA_LOAD', data: agent.response[:data])
30
+ class_name = agent.response[:data].keys.first
31
+ key = agent.response[:data][class_name].keys.first
32
+ logged_in_user = Isomorfeus.cached_data_class(class_name).new(key: key)
33
+ cookie_accessor = agent.response[:session_cookie_accessor]
34
+ begin
35
+ target = if block_given?
36
+ block.call(logged_in_user)
37
+ else
38
+ `window.location.pathname`
39
+ end
40
+ unless target.class == String && target.start_with?('/')
41
+ Isomorfeus.raise_error(message: "A path must be returned as string starting with '/', returned was #{target}!")
42
+ end
43
+ rescue
44
+ target = `window.location.pathname`
45
+ end
46
+ cookie_query = "#{Isomorfeus.cookie_eater_path}?#{cookie_accessor}=#{target}"
47
+ `window.location = cookie_query` # doing page load and redirect
48
+ nil
49
+ else
50
+ Isomorfeus.raise_error(message: "Login failed with '#{agent.response[:error]}'!") # triggers .fail
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ def promise_logout(scheme: :isomorfeus)
59
+ send("promise_deauthentication_with_#{scheme}")
60
+ end
61
+
62
+ def promise_deauthentication_with_isomorfeus
63
+ Isomorfeus::Transport.promise_send_path('Isomorfeus::Transport::Handler::AuthenticationHandler', 'logout', 'logout').then do |agent|
64
+ `document.cookie = "session="`
65
+ Isomorfeus.set_current_user(nil)
66
+ Isomorfeus.force_init_store!
67
+ agent.processed = true
68
+ agent.response.key?(:success) ? true : raise('Logout failed!')
69
+ end
70
+ end
71
+ else
72
+ def self.included(base)
73
+ Isomorfeus.add_valid_user_class(base)
74
+
75
+ base.instance_exec do
76
+ def execute_login(&block)
77
+ @execute_login_block = block
78
+ end
79
+
80
+ def promise_login(user: nil, pass: nil, scheme: :isomorfeus, &block)
81
+ send("promise_authentication_with_#{scheme}", user: user, pass: pass, &block)
82
+ end
83
+
84
+ def promise_authentication_with_isomorfeus(user: nil, pass: nil, &block)
85
+ promise_or_user = @execute_login_block.call(user: user, pass: pass)
86
+ if promise_or_user.class == Promise
87
+ if block_given?
88
+ promise_or_user.then do |user|
89
+ block.call(user)
90
+ user
91
+ end
92
+ else
93
+ promise_or_user
94
+ end
95
+ else
96
+ block.call(user) if block_given?
97
+ Promise.new.resolve(promise_or_user)
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ def encrypt_password(password, password_confirmation)
104
+ raise "Password and confirmation don't match!" unless password == password_confirmation
105
+ BCrypt::Password.create(password).to_s
106
+ end
107
+
108
+ def passwords_match?(encrypted_password, given_password)
109
+ bcrypt_pass = BCrypt::Password.new(encrypted_password)
110
+ bcrypt_pass == given_password
111
+ end
112
+
113
+ def promise_logout(scheme: :isomorfeus)
114
+ send("promise_deauthentication_with_#{scheme}")
115
+ end
116
+
117
+ def promise_deauthentication_with_isomorfeus
118
+ Promise.new.resolve(true)
119
+ end
120
+ end
121
+ end
122
+ end
@@ -1,9 +1,8 @@
1
- module LucidChannel
2
- class Base
3
- def self.inherited(base)
4
- Isomorfeus.add_valid_channel_class(base)
5
- end
6
-
7
- include LucidChannel::Mixin
8
- end
9
- end
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 +1,105 @@
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
+ 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,9 +1,8 @@
1
- module LucidHandler
2
- class Base
3
- def self.inherited(base)
4
- Isomorfeus.add_valid_handler_class(base)
5
- end
6
-
7
- include LucidHandler::Mixin
8
- end
9
- end
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