isomorfeus-transport 1.0.0.delta8 → 1.0.0.delta9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/lib/isomorfeus/transport/client_processor.rb +4 -2
- data/lib/isomorfeus/transport/config.rb +38 -1
- data/lib/isomorfeus/transport/server_processor.rb +47 -24
- data/lib/isomorfeus/transport/version.rb +1 -1
- data/lib/isomorfeus/transport/websocket.rb +2 -2
- data/lib/isomorfeus/transport.rb +139 -113
- data/lib/isomorfeus-transport.rb +26 -7
- data/lib/lucid_channel/base.rb +6 -0
- data/lib/lucid_channel/mixin.rb +25 -10
- data/lib/lucid_handler/base.rb +9 -0
- data/lib/lucid_handler/mixin.rb +15 -0
- metadata +12 -11
- data/lib/isomorfeus/handler.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1453febd89db3eba65151c490dacc155691317bced9a9f8bc00a6dff0b6500fb
|
4
|
+
data.tar.gz: 3b12ba839819d379f30be025154fdf44f57fd976af9c1c3cb8b3515483aabb2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b3cdb69387da257343607955a37ff372b154ea02a4af0ca528d716d357b0e0bb4bb24c62460e93da2db236c6d5554c4a6f7e0b26b3f1d53983c8df502acfa15
|
7
|
+
data.tar.gz: 6c8cc28a458254fd0e7ef5754d1daf90f658fa58f5e613cf898628cc57ee2b3b526f2a5ae795d8b74c3fbf9008f3328ef36e42de9f02ce52ea4c9a9816952474
|
data/LICENSE
CHANGED
@@ -11,14 +11,16 @@ module Isomorfeus
|
|
11
11
|
|
12
12
|
def self.process_notification(notification_hash)
|
13
13
|
processor_class = "::#{notification_hash[:notification][:class]}".constantize
|
14
|
-
processor_class.process_message(notification_hash[:notification][:message])
|
14
|
+
processor_class.process_message(notification_hash[:notification][:channel], notification_hash[:notification][:message])
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.process_response(response_hash)
|
18
18
|
response_hash[:response][:agent_ids].keys.each do |agent_id|
|
19
19
|
agent = Isomorfeus::Transport::RequestAgent.get!(agent_id)
|
20
20
|
Isomorfeus::Transport.unregister_request_in_progress(agent_id)
|
21
|
-
agent.promise.
|
21
|
+
unless agent.promise.realized?
|
22
|
+
agent.promise.resolve(agent_response: response_hash[:response][:agent_ids][agent_id], full_response: response_hash)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -4,7 +4,6 @@ module Isomorfeus
|
|
4
4
|
if RUBY_ENGINE == 'opal'
|
5
5
|
add_client_option(:api_websocket_path)
|
6
6
|
else
|
7
|
-
# defaults
|
8
7
|
class << self
|
9
8
|
attr_accessor :api_websocket_path
|
10
9
|
attr_accessor :middlewares
|
@@ -34,9 +33,47 @@ module Isomorfeus
|
|
34
33
|
end
|
35
34
|
end
|
36
35
|
end
|
36
|
+
|
37
|
+
def valid_channel_class_names
|
38
|
+
@valid_channel_class_names ||= Set.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid_channel_class_name?(class_name)
|
42
|
+
valid_channel_class_names.include?(class_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_valid_channel_class(klass)
|
46
|
+
class_name = klass.name
|
47
|
+
class_name = class_name.split('>::').last if class_name.start_with?('#<')
|
48
|
+
valid_channel_class_names << class_name
|
49
|
+
end
|
50
|
+
|
51
|
+
def valid_handler_class_names
|
52
|
+
@valid_handler_class_names ||= Set.new
|
53
|
+
end
|
54
|
+
|
55
|
+
def valid_handler_class_name?(class_name)
|
56
|
+
valid_handler_class_names.include?(class_name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_valid_handler_class(klass)
|
60
|
+
class_name = klass.name
|
61
|
+
class_name = class_name.split('>::').last if class_name.start_with?('#<')
|
62
|
+
valid_handler_class_names << class_name
|
63
|
+
end
|
64
|
+
|
65
|
+
def cached_handler_classes
|
66
|
+
@cached_handler_classes ||= {}
|
67
|
+
end
|
68
|
+
|
69
|
+
def cached_handler_class(class_name)
|
70
|
+
return cached_handler_classes[class_name] if cached_handler_classes.key?(class_name)
|
71
|
+
cached_handler_classes[class_name] = "::#{class_name}".constantize
|
72
|
+
end
|
37
73
|
end
|
38
74
|
self.middlewares = Set.new
|
39
75
|
end
|
40
76
|
|
77
|
+
# defaults
|
41
78
|
self.api_websocket_path = '/isomorfeus/api/websocket'
|
42
79
|
end
|
@@ -4,45 +4,68 @@ module Isomorfeus
|
|
4
4
|
module Transport
|
5
5
|
module ServerProcessor
|
6
6
|
def process_request(client, session_id, current_user, request)
|
7
|
+
Thread.current[:isomorfeus_pub_sub_client] = client
|
8
|
+
|
7
9
|
response = { response: { agent_ids: {}} }
|
8
10
|
|
9
11
|
if request.key?('request') && request['request'].key?('agent_ids')
|
10
12
|
request['request']['agent_ids'].keys.each do |agent_id|
|
11
|
-
request['request']['agent_ids'][agent_id].keys.each do |
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
request['request']['agent_ids'][agent_id].keys.each do |handler_class_name|
|
14
|
+
begin
|
15
|
+
handler = Isomorfeus.cached_handler_class(handler_class_name) if Isomorfeus.valid_handler_class_name?(handler_class_name)
|
16
|
+
if handler
|
17
|
+
result = handler.new.process_request(client, session_id, current_user, request['request']['agent_ids'][agent_id][handler_class_name], response)
|
18
|
+
response[:response][:agent_ids][agent_id] = result
|
19
|
+
else
|
20
|
+
response[:response][:agent_ids][agent_id] = { error: { handler_class_name => 'No such handler!'}}
|
21
|
+
end
|
22
|
+
rescue
|
23
|
+
response[:response][:agent_ids][agent_id] = { error: { handler_class_name => 'No such handler!'}}
|
17
24
|
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
elsif request.key?('notification')
|
21
|
-
|
22
|
-
|
23
|
-
|
28
|
+
begin
|
29
|
+
channel = request['notification']['channel']
|
30
|
+
class_name = request['notification']['class']
|
31
|
+
if Isomorfeus.valid_channel_class_name?(class_name) && channel
|
32
|
+
client.publish(request['notification']['channel'], Oj.dump({ 'notification' => request['notification'] }, mode: :strict))
|
33
|
+
else
|
34
|
+
response[:response] = 'No such thing!'
|
35
|
+
end
|
36
|
+
rescue
|
24
37
|
response[:response] = 'No such thing!'
|
25
38
|
end
|
26
39
|
elsif request.key?('subscribe') && request['subscribe'].key?('agent_ids')
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
40
|
+
begin
|
41
|
+
agent_id = request['subscribe']['agent_ids'].keys.first
|
42
|
+
channel = request['subscribe']['agent_ids'][agent_id]['channel']
|
43
|
+
class_name = request['subscribe']['agent_ids'][agent_id]['class']
|
44
|
+
if Isomorfeus.valid_channel_class_name?(class_name) && channel
|
45
|
+
client.subscribe(channel)
|
46
|
+
response[:response][:agent_ids][agent_id] = { success: channel }
|
47
|
+
else
|
48
|
+
response[:response][:agent_ids][agent_id] = { error: "No such thing!"}
|
49
|
+
end
|
50
|
+
rescue
|
51
|
+
response[:response][:agent_ids][agent_id] = { error: { key => 'No such handler!'}}
|
34
52
|
end
|
35
53
|
elsif request.key?('unsubscribe') && request['unsubscribe'].key?('agent_ids')
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
54
|
+
begin
|
55
|
+
agent_id = request['unsubscribe']['agent_ids'].keys.first
|
56
|
+
channel = request['unsubscribe']['agent_ids'][agent_id]['channel']
|
57
|
+
class_name = request['unsubscribe']['agent_ids'][agent_id]['class']
|
58
|
+
if Isomorfeus.valid_channel_class_name?(class_name) && channel
|
59
|
+
client.unsubscribe(channel)
|
60
|
+
response[:response][:agent_ids][agent_id] = { success: channel }
|
61
|
+
else
|
62
|
+
response[:response][:agent_ids][agent_id] = { error: 'No such thing!'}
|
63
|
+
end
|
64
|
+
rescue
|
65
|
+
response[:response][:agent_ids][agent_id] = { error: { key => 'No such handler!'}}
|
43
66
|
end
|
44
67
|
else
|
45
|
-
response[:response] = 'No such thing!'
|
68
|
+
response[:response] = { error: 'No such thing!'}
|
46
69
|
end
|
47
70
|
response
|
48
71
|
end
|
@@ -45,7 +45,6 @@ module Isomorfeus
|
|
45
45
|
when CLOSED then raise SendError.new('Cant send, connection is closed!')
|
46
46
|
end
|
47
47
|
end
|
48
|
-
alias_method :write, :send
|
49
48
|
|
50
49
|
private
|
51
50
|
|
@@ -101,7 +100,6 @@ module Isomorfeus
|
|
101
100
|
def send(data)
|
102
101
|
@socket.write(data)
|
103
102
|
end
|
104
|
-
alias_method :write, :send
|
105
103
|
|
106
104
|
private
|
107
105
|
|
@@ -110,6 +108,8 @@ module Isomorfeus
|
|
110
108
|
@thread.kill
|
111
109
|
end
|
112
110
|
end
|
111
|
+
|
112
|
+
alias_method :write, :send
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
data/lib/isomorfeus/transport.rb
CHANGED
@@ -1,141 +1,167 @@
|
|
1
1
|
module Isomorfeus
|
2
2
|
module Transport
|
3
3
|
class << self
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@socket = Isomorfeus::Transport::Websocket.new(ws_url)
|
26
|
-
@socket.on_error do
|
27
|
-
@socket.close
|
28
|
-
delay do
|
29
|
-
Isomorfeus::Transport.connect
|
4
|
+
if RUBY_ENGINE == 'opal'
|
5
|
+
attr_accessor :socket
|
6
|
+
|
7
|
+
def delay(ms = 1000, &block)
|
8
|
+
`setTimeout(#{block.to_n}, ms)`
|
9
|
+
end
|
10
|
+
|
11
|
+
def init!
|
12
|
+
@requests_in_progress = { requests: {}, agent_ids: {} }
|
13
|
+
@socket = nil
|
14
|
+
connect if Isomorfeus.on_browser?
|
15
|
+
end
|
16
|
+
|
17
|
+
def connect
|
18
|
+
return if @socket && @socket.ready_state < 2
|
19
|
+
if Isomorfeus.on_browser?
|
20
|
+
window_protocol = `window.location.protocol`
|
21
|
+
ws_protocol = window_protocol == 'https:' ? 'wss:' : 'ws:'
|
22
|
+
ws_url = "#{ws_protocol}#{`window.location.host`}#{Isomorfeus.api_websocket_path}"
|
23
|
+
else
|
24
|
+
ws_url = Isomorfeus::TopLevel.transport_ws_url
|
30
25
|
end
|
26
|
+
@socket = Isomorfeus::Transport::Websocket.new(ws_url)
|
27
|
+
@socket.on_error do
|
28
|
+
@socket.close
|
29
|
+
delay do
|
30
|
+
Isomorfeus::Transport.connect
|
31
|
+
end
|
32
|
+
end
|
33
|
+
@socket.on_message do |event|
|
34
|
+
json_hash = `Opal.Hash.$new(JSON.parse(event.data))`
|
35
|
+
Isomorfeus::Transport::ClientProcessor.process(json_hash)
|
36
|
+
end
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def disconnect
|
41
|
+
@socket.close if @socket
|
42
|
+
@socket = nil
|
31
43
|
end
|
32
|
-
|
33
|
-
|
34
|
-
|
44
|
+
|
45
|
+
def promise_send_path(*path, &block)
|
46
|
+
request = {}
|
47
|
+
path.inject(request) do |memo, key|
|
48
|
+
memo[key] = {}
|
49
|
+
end
|
50
|
+
Isomorfeus::Transport.promise_send_request(request, &block)
|
35
51
|
end
|
36
|
-
true
|
37
|
-
end
|
38
52
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
53
|
+
def promise_send_request(request, &block)
|
54
|
+
if request_in_progress?(request)
|
55
|
+
agent = get_agent_for_request_in_progress(request)
|
56
|
+
else
|
57
|
+
agent = Isomorfeus::Transport::RequestAgent.new(request)
|
58
|
+
if block_given?
|
59
|
+
agent.promise.then do |response|
|
60
|
+
block.call(response)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
register_request_in_progress(request, agent.id)
|
64
|
+
@socket.send(`JSON.stringify(#{{request: { agent_ids: { agent.id => request }}}.to_n})`)
|
65
|
+
delay(Isomorfeus.on_ssr? ? 8000 : 20000) do
|
66
|
+
unless agent.promise.realized?
|
67
|
+
agent.promise.reject({agent_response: { error: 'Request timeout!' }, full_response: {}})
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
agent.promise
|
72
|
+
end
|
43
73
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
memo[key] = {}
|
74
|
+
def send_notification(channel_class, channel, message)
|
75
|
+
@socket.send(`JSON.stringify(#{{notification: { class: channel_class.name, channel: channel, message: message}}.to_n})`)
|
76
|
+
true
|
48
77
|
end
|
49
|
-
Isomorfeus::Transport.promise_send_request(request, &block)
|
50
|
-
end
|
51
78
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
79
|
+
def subscribe(channel_class, channel, &block)
|
80
|
+
request = { subscribe: true, class: channel_class.name, channel: channel }
|
81
|
+
if request_in_progress?(request)
|
82
|
+
agent = get_agent_for_request_in_progress(request)
|
83
|
+
else
|
84
|
+
agent = Isomorfeus::Transport::RequestAgent.new(request)
|
85
|
+
register_request_in_progress(request, agent.id)
|
86
|
+
@socket.send(`JSON.stringify(#{{subscribe: { agent_ids: { agent.id => request }}}.to_n})`)
|
87
|
+
end
|
88
|
+
result_promise = agent.promise.then do |response|
|
89
|
+
response[:agent_response]
|
90
|
+
end
|
57
91
|
if block_given?
|
58
|
-
|
92
|
+
result_promise = result_promise.then do |response|
|
59
93
|
block.call(response)
|
60
94
|
end
|
61
95
|
end
|
62
|
-
|
63
|
-
@socket.send(`JSON.stringify(#{{request: { agent_ids: { agent.id => request }}}.to_n})`)
|
64
|
-
end
|
65
|
-
agent.promise
|
66
|
-
end
|
67
|
-
|
68
|
-
def send_notification(processor_class, message)
|
69
|
-
@socket.send(`JSON.stringify(#{{notification: { class: processor_class.to_s, message: message}}.to_n})`)
|
70
|
-
true
|
71
|
-
end
|
72
|
-
|
73
|
-
def subscribe(processor_class, &block)
|
74
|
-
request = { subscribe: true, class: processor_class.to_s }
|
75
|
-
if request_in_progress?(request)
|
76
|
-
agent = get_agent_for_request_in_progress(request)
|
77
|
-
else
|
78
|
-
agent = Isomorfeus::Transport::RequestAgent.new(request)
|
79
|
-
register_request_in_progress(request, agent.id)
|
80
|
-
@socket.send(`JSON.stringify(#{{subscribe: { agent_ids: { agent.id => request }}}.to_n})`)
|
81
|
-
end
|
82
|
-
result_promise = agent.promise.then do |response|
|
83
|
-
response[:agent_response]
|
84
|
-
end
|
85
|
-
if block_given?
|
86
|
-
result_promise = result_promise.then do |response|
|
87
|
-
block.call(response)
|
88
|
-
end
|
96
|
+
result_promise
|
89
97
|
end
|
90
|
-
result_promise
|
91
|
-
end
|
92
98
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
99
|
+
def unsubscribe(channel_class, channel, &block)
|
100
|
+
request = { unsubscribe: true, class: channel_class.name, channel: channel }
|
101
|
+
if request_in_progress?(request)
|
102
|
+
agent = get_agent_for_request_in_progress(request)
|
103
|
+
else
|
104
|
+
agent = Isomorfeus::Transport::RequestAgent.new(request)
|
105
|
+
register_request_in_progress(request, agent.id)
|
106
|
+
@socket.send(`JSON.stringify(#{{unsubscribe: { agent_ids: { agent.id => request }}}.to_n})`)
|
107
|
+
end
|
108
|
+
result_promise = agent.promise.then do |response|
|
109
|
+
response[:agent_response]
|
110
|
+
end
|
111
|
+
if block_given?
|
112
|
+
result_promise = result_promise.then do |response|
|
113
|
+
block.call(response)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
result_promise
|
101
117
|
end
|
102
|
-
|
103
|
-
|
118
|
+
|
119
|
+
def busy?
|
120
|
+
@requests_in_progress[:requests].size != 0
|
104
121
|
end
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
122
|
+
|
123
|
+
def requests_in_progress
|
124
|
+
@requests_in_progress
|
109
125
|
end
|
110
|
-
result_promise
|
111
|
-
end
|
112
126
|
|
113
|
-
|
114
|
-
|
115
|
-
|
127
|
+
def request_in_progress?(request)
|
128
|
+
@requests_in_progress[:requests].key?(request)
|
129
|
+
end
|
116
130
|
|
117
|
-
|
118
|
-
|
119
|
-
|
131
|
+
def get_agent_for_request_in_progress(request)
|
132
|
+
agent_id = @requests_in_progress[:requests][request]
|
133
|
+
Isomorfeus::Transport::RequestAgent.get(agent_id)
|
134
|
+
end
|
120
135
|
|
121
|
-
|
122
|
-
|
123
|
-
|
136
|
+
def register_request_in_progress(request, agent_id)
|
137
|
+
@requests_in_progress[:requests][request] = agent_id
|
138
|
+
@requests_in_progress[:agent_ids][agent_id] = request
|
139
|
+
end
|
124
140
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
141
|
+
def unregister_request_in_progress(agent_id)
|
142
|
+
request = @requests_in_progress[:agent_ids].delete(agent_id)
|
143
|
+
@requests_in_progress[:requests].delete(request)
|
144
|
+
end
|
145
|
+
else # RUBY_ENGINE
|
146
|
+
def send_notification(channel_class, channel, message)
|
147
|
+
Thread.current[:isomorfeus_pub_sub_client].publish(Oj.dump({notification: { class: channel_class.name, channel: channel, message: message}}, mode: :strict))
|
148
|
+
true
|
149
|
+
end
|
129
150
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
151
|
+
def subscribe(channel_class, channel, &block)
|
152
|
+
Thread.current[:isomorfeus_pub_sub_client].subscribe(channel)
|
153
|
+
result_promise = Promise.new
|
154
|
+
result_promise.resolve({ success: channel })
|
155
|
+
result_promise
|
156
|
+
end
|
134
157
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
158
|
+
def unsubscribe(channel_class, channel, &block)
|
159
|
+
Thread.current[:isomorfeus_pub_sub_client].unsubscribe(channel)
|
160
|
+
result_promise = Promise.new
|
161
|
+
result_promise.resolve({ success: channel })
|
162
|
+
result_promise
|
163
|
+
end
|
164
|
+
end # RUBY_ENGINE
|
139
165
|
end
|
140
166
|
end
|
141
167
|
end
|
data/lib/isomorfeus-transport.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'opal'
|
2
|
+
require 'opal-autoloader'
|
3
|
+
require 'opal-activesupport'
|
1
4
|
if RUBY_ENGINE == 'opal'
|
2
5
|
require 'json'
|
3
6
|
require 'isomorfeus/config'
|
@@ -10,6 +13,7 @@ if RUBY_ENGINE == 'opal'
|
|
10
13
|
require 'isomorfeus/transport'
|
11
14
|
require 'lucid_channel/mixin'
|
12
15
|
require 'lucid_channel/base'
|
16
|
+
Opal::Autoloader.add_load_path('channels')
|
13
17
|
Isomorfeus::Transport.init!
|
14
18
|
else
|
15
19
|
require 'base64'
|
@@ -28,17 +32,32 @@ else
|
|
28
32
|
require 'isomorfeus/transport/server_processor'
|
29
33
|
require 'isomorfeus/transport/server_socket_processor'
|
30
34
|
require 'isomorfeus/transport/websocket'
|
31
|
-
require 'isomorfeus/handler'
|
32
35
|
require 'isomorfeus/transport/rack_middleware'
|
33
|
-
Opal.append_path(__dir__.untaint) unless Opal.paths.include?(__dir__.untaint)
|
34
|
-
|
35
36
|
require 'isomorfeus/transport/middlewares'
|
36
37
|
|
37
38
|
Isomorfeus.add_middleware(Isomorfeus::Transport::RackMiddleware)
|
39
|
+
Isomorfeus.valid_channel_class_names
|
40
|
+
|
41
|
+
require 'lucid_handler/mixin'
|
42
|
+
require 'lucid_handler/base'
|
43
|
+
require 'lucid_channel/mixin'
|
44
|
+
require 'lucid_channel/base'
|
45
|
+
|
46
|
+
Opal.append_path(__dir__.untaint) unless Opal.paths.include?(__dir__.untaint)
|
47
|
+
|
48
|
+
require 'active_support'
|
49
|
+
require 'active_support/dependencies'
|
38
50
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
51
|
+
%w[channels handlers].each do |dir|
|
52
|
+
path = if Dir.exist?(File.join('app', 'isomorfeus'))
|
53
|
+
File.expand_path(File.join('app', 'isomorfeus', dir))
|
54
|
+
elsif Dir.exist?(File.join('isomorfeus'))
|
55
|
+
File.expand_path(File.join('isomorfeus', dir))
|
56
|
+
end
|
57
|
+
ActiveSupport::Dependencies.autoload_paths << path if path
|
58
|
+
# we also need to require them all, so classes are registered accordingly
|
59
|
+
Dir.glob("#{path}/**/*.rb").each do |file|
|
60
|
+
require file
|
61
|
+
end
|
43
62
|
end
|
44
63
|
end
|
data/lib/lucid_channel/base.rb
CHANGED
data/lib/lucid_channel/mixin.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
1
|
module LucidChannel
|
2
2
|
module Mixin
|
3
3
|
def self.included(base)
|
4
|
+
|
5
|
+
if RUBY_ENGINE != 'opal'
|
6
|
+
Isomorfeus.add_valid_channel_class(base) unless base == LucidChannel::Base
|
7
|
+
end
|
8
|
+
|
4
9
|
base.instance_exec do
|
5
|
-
def process_message(message)
|
10
|
+
def process_message(channel, message = nil)
|
6
11
|
if @message_processor
|
7
|
-
|
12
|
+
if channel == self.name
|
13
|
+
@message_processor.call(message)
|
14
|
+
else
|
15
|
+
@message_processor.call(channel, message)
|
16
|
+
end
|
8
17
|
else
|
9
|
-
puts "#{self} received: #{message}, but no
|
18
|
+
puts "#{self} received: #{channel} #{message}, but no 'on_message' block defined!"
|
10
19
|
end
|
11
20
|
end
|
12
21
|
|
@@ -14,18 +23,24 @@ module LucidChannel
|
|
14
23
|
@message_processor = block
|
15
24
|
end
|
16
25
|
|
17
|
-
def send_message(message)
|
18
|
-
|
26
|
+
def send_message(channel, message = nil)
|
27
|
+
unless message
|
28
|
+
message = channel
|
29
|
+
channel = self.name
|
30
|
+
end
|
31
|
+
Isomorfeus::Transport.send_notification(self, channel, message)
|
19
32
|
end
|
20
33
|
|
21
|
-
def subscribe
|
22
|
-
|
34
|
+
def subscribe(channel = nil)
|
35
|
+
channel = channel ? channel : self.name
|
36
|
+
Isomorfeus::Transport.subscribe(self, channel)
|
23
37
|
end
|
24
38
|
|
25
|
-
def unsubscribe
|
26
|
-
|
39
|
+
def unsubscribe(channel = nil)
|
40
|
+
channel = channel ? channel : self.name
|
41
|
+
Isomorfeus::Transport.unsubscribe(self, channel)
|
27
42
|
end
|
28
43
|
end
|
29
44
|
end
|
30
45
|
end
|
31
|
-
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
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
|
+
block.call(*args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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.delta9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-26 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: '5.
|
19
|
+
version: '5.2'
|
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: '5.
|
26
|
+
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: iodine
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.7.
|
33
|
+
version: 0.7.33
|
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: 0.7.
|
40
|
+
version: 0.7.33
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: oj
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,28 +72,28 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 4.0.
|
75
|
+
version: 4.0.8
|
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.8
|
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.8.
|
89
|
+
version: 16.8.8
|
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.8.
|
96
|
+
version: 16.8.8
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: websocket-driver
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,7 +117,6 @@ files:
|
|
117
117
|
- LICENSE
|
118
118
|
- README.md
|
119
119
|
- lib/isomorfeus-transport.rb
|
120
|
-
- lib/isomorfeus/handler.rb
|
121
120
|
- lib/isomorfeus/transport.rb
|
122
121
|
- lib/isomorfeus/transport/client_processor.rb
|
123
122
|
- lib/isomorfeus/transport/config.rb
|
@@ -130,6 +129,8 @@ files:
|
|
130
129
|
- lib/isomorfeus/transport/websocket.rb
|
131
130
|
- lib/lucid_channel/base.rb
|
132
131
|
- lib/lucid_channel/mixin.rb
|
132
|
+
- lib/lucid_handler/base.rb
|
133
|
+
- lib/lucid_handler/mixin.rb
|
133
134
|
homepage: http://isomorfeus.com
|
134
135
|
licenses:
|
135
136
|
- MIT
|