interfacets 0.9.99 → 0.99999
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE +9 -17
- data/lib/interfacets/client/actor.rb +2 -1
- data/lib/interfacets/client/assets.rb +77 -64
- data/lib/interfacets/client/bus.rb +28 -9
- data/lib/interfacets/client/channels/api.rb +138 -39
- data/lib/interfacets/client/channels/audio.rb +13 -10
- data/lib/interfacets/client/channels/base.rb +2 -2
- data/lib/interfacets/client/channels/pubsub.rb +69 -0
- data/lib/interfacets/client/channels/react/builder.rb +42 -72
- data/lib/interfacets/client/channels/react/channel.rb +7 -5
- data/lib/interfacets/client/channels/react/evaluator.rb +6 -4
- data/lib/interfacets/client/channels/timer.rb +8 -7
- data/lib/interfacets/client/channels/url.rb +39 -6
- data/lib/interfacets/client/registry.rb +3 -2
- data/lib/interfacets/client/slots.rb +45 -0
- data/lib/interfacets/client/system.rb +20 -15
- data/lib/interfacets/client/template.rb +90 -0
- data/lib/interfacets/client/utils/mruby_patches.rb +7 -3
- data/lib/interfacets/client/utils/open_struct.rb +2 -4
- data/lib/interfacets/component_registry.rb +34 -29
- data/lib/interfacets/component_schema_parser.rb +8 -4
- data/lib/interfacets/mruby/build_config.rb +8 -4
- data/lib/interfacets/mruby/entrypoint.rb +2 -2
- data/lib/interfacets/server/api.rb +44 -7
- data/lib/interfacets/server/assets.rb +58 -23
- data/lib/interfacets/server/basic_router.rb +29 -19
- data/lib/interfacets/server/bus.rb +5 -6
- data/lib/interfacets/server/registry.rb +17 -10
- data/lib/interfacets/shared/basic_routable.rb +7 -4
- data/lib/interfacets/shared/entities/bus.rb +619 -185
- data/lib/interfacets/shared/entities/changeset.rb +432 -0
- data/lib/interfacets/shared/entities/collection_proxy.rb +132 -72
- data/lib/interfacets/shared/entities/specs/handlers.rb +58 -37
- data/lib/interfacets/shared/entities/specs.rb +184 -18
- data/lib/interfacets/shared/entity.rb +113 -23
- data/lib/interfacets/shared/entity_dsl.rb +138 -20
- data/lib/interfacets/shared/facet.rb +128 -68
- data/lib/interfacets/shared/generated_store.rb +69 -34
- data/lib/interfacets/shared/refreshable.rb +85 -0
- data/lib/interfacets/shared/utils.rb +36 -32
- data/lib/interfacets/shared/validations.rb +746 -26
- data/lib/interfacets/shared/view.rb +74 -28
- data/lib/interfacets/test/component_registry.rb +31 -12
- data/lib/interfacets/test/js/inline_bus.rb +51 -25
- data/lib/interfacets/test/js/nodo_bus.rb +21 -10
- data/lib/interfacets/test/js/receivers/api.rb +14 -12
- data/lib/interfacets/test/js/receivers/audio.rb +61 -0
- data/lib/interfacets/test/js/receivers/pubsub.rb +50 -0
- data/lib/interfacets/test/js/receivers/react/node/xml_parser.rb +33 -5
- data/lib/interfacets/test/js/receivers/react/node.rb +69 -15
- data/lib/interfacets/test/js/receivers/react.rb +13 -4
- data/lib/interfacets/test/js/receivers/timer.rb +12 -8
- data/lib/interfacets/test/js/receivers/url.rb +47 -11
- data/lib/interfacets/test/ui_simulator.rb +88 -18
- data/lib/interfacets/test/validation_engine.rb +82 -49
- data/lib/interfacets/test.rb +1 -3
- data/lib/interfacets/version.rb +1 -1
- data/lib/interfacets.rb +11 -3
- metadata +31 -28
- data/.rubocop.yml +0 -180
- data/.tmp +0 -5
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -14
- data/lib/interfacets/client/channels/page_visibility.rb +0 -21
- data/lib/interfacets/client/channels/react/dom.rb +0 -91
- data/lib/interfacets/client/channels/speech_to_text.rb +0 -100
- data/lib/interfacets/client/config.rb +0 -22
- data/lib/interfacets/client/delegator.rb +0 -37
- data/lib/interfacets/server/assets/facet.rb +0 -63
- data/lib/interfacets/server/config.rb +0 -87
- data/lib/interfacets/server/facets/deserializer.rb +0 -25
- data/lib/interfacets/server/facets/schema/serializer.rb +0 -54
- data/lib/interfacets/server/facets/serializer.rb +0 -50
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52bd4a99690ce6f212752999a91842bb2ecf0ad9dc73ad5955658fe81ee36b1e
|
|
4
|
+
data.tar.gz: e085343e3610e42bf4fa3db6f6c5fb719ae82abf06ea3570b3b7fec643658e9d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a921f109d60132d1f19148bd5810021d879eeb0f0149a22c6fe50cdea1847c85163d3cd93aae75419354484998316ffbad282ab25943539d7d66b7d2001db15b
|
|
7
|
+
data.tar.gz: 4aa1c6368fb8d778228702637f7a4f2d89e66842542a3c5ef7429cad33fd2cee8d0c76464e7171b4941f982475bfc841dd92c39d80ec000aa6b1022f61e60483
|
data/LICENSE
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
2
|
+
Version 2, December 2004
|
|
2
3
|
|
|
3
|
-
Copyright (
|
|
4
|
+
Copyright (C) 2024 Pete Kinnecom
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
of this
|
|
7
|
-
|
|
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:
|
|
6
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
|
7
|
+
copies of this license document, and changing it is allowed as long
|
|
8
|
+
as the name is changed.
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
11
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
14
12
|
|
|
15
|
-
|
|
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.
|
|
13
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
# rubocop:disable Style/MissingRespondToMissing
|
|
4
3
|
original_verbose = $VERBOSE
|
|
5
4
|
$VERBOSE = nil
|
|
6
5
|
|
|
@@ -20,20 +19,20 @@ class InterfacetsLogger
|
|
|
20
19
|
warn: 2,
|
|
21
20
|
error: 3,
|
|
22
21
|
fatal: 4
|
|
23
|
-
}
|
|
22
|
+
}
|
|
24
23
|
|
|
25
|
-
attr_accessor
|
|
24
|
+
attr_accessor(:level)
|
|
26
25
|
def initialize(level: :info)
|
|
27
26
|
@level = LEVELS[level] || LEVELS[:info]
|
|
28
27
|
end
|
|
29
28
|
|
|
30
|
-
# Meta-program the logging methods
|
|
31
29
|
LEVELS.each do |method_name, level_value|
|
|
32
30
|
define_method(method_name) do |message|
|
|
33
|
-
puts
|
|
31
|
+
puts(
|
|
32
|
+
"#{method_name.to_s.upcase}: #{message}"
|
|
33
|
+
) if level_value >= level
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
|
-
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
$VERBOSE = original_verbose
|
|
@@ -42,7 +41,7 @@ module Interfacets
|
|
|
42
41
|
module Client
|
|
43
42
|
module Assets
|
|
44
43
|
class << self
|
|
45
|
-
attr_reader
|
|
44
|
+
attr_reader(:loader)
|
|
46
45
|
|
|
47
46
|
def logger
|
|
48
47
|
$asset_logger ||= InterfacetsLogger.main
|
|
@@ -58,31 +57,48 @@ module Interfacets
|
|
|
58
57
|
.join("\n")
|
|
59
58
|
.then { TOP_LEVEL_BINDING.eval(_1) }
|
|
60
59
|
|
|
60
|
+
@loader.done_bootstrapping!
|
|
61
61
|
Assets.logger.debug("done bootstrapping")
|
|
62
62
|
|
|
63
63
|
assets.fetch("fs_map").each_key do |path|
|
|
64
64
|
Assets.logger.debug("planned load: #{path}")
|
|
65
65
|
@loader.load_path(path)
|
|
66
66
|
end
|
|
67
|
+
|
|
68
|
+
@loader.replay_all_inherited_hooks
|
|
67
69
|
end
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
class Loader
|
|
71
|
-
attr_reader
|
|
73
|
+
attr_reader(
|
|
74
|
+
:assets,
|
|
75
|
+
:loaded_classes,
|
|
76
|
+
:loaded_paths,
|
|
77
|
+
:bootstrapping
|
|
78
|
+
)
|
|
72
79
|
def initialize(assets)
|
|
73
80
|
@assets = assets
|
|
74
81
|
@loaded_classes = {}
|
|
75
82
|
@loaded_paths = {}
|
|
83
|
+
@bootstrapping = true
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def done_bootstrapping!
|
|
87
|
+
@bootstrapping = false
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def bootstrapping?
|
|
91
|
+
@bootstrapping
|
|
76
92
|
end
|
|
77
93
|
|
|
78
94
|
def path_loaded?(path)
|
|
79
|
-
|
|
95
|
+
loaded_paths.key?(path)
|
|
80
96
|
end
|
|
81
97
|
|
|
82
98
|
def load_path(path)
|
|
83
|
-
return if
|
|
99
|
+
return if path_loaded?(path)
|
|
84
100
|
|
|
85
|
-
|
|
101
|
+
loaded_paths[path] = true
|
|
86
102
|
|
|
87
103
|
Assets.logger.debug("loading: #{path}")
|
|
88
104
|
|
|
@@ -91,13 +107,14 @@ module Interfacets
|
|
|
91
107
|
end
|
|
92
108
|
|
|
93
109
|
def loaded?(klass)
|
|
94
|
-
|
|
110
|
+
loaded_classes.key?(klass)
|
|
95
111
|
end
|
|
96
112
|
|
|
97
113
|
def load(klass)
|
|
114
|
+
return if bootstrapping?
|
|
98
115
|
return if loaded?(klass)
|
|
99
116
|
|
|
100
|
-
|
|
117
|
+
loaded_classes[klass] = true
|
|
101
118
|
|
|
102
119
|
return if klass.name.nil?
|
|
103
120
|
|
|
@@ -111,12 +128,39 @@ module Interfacets
|
|
|
111
128
|
}
|
|
112
129
|
end
|
|
113
130
|
|
|
114
|
-
|
|
131
|
+
def replay_all_inherited_hooks
|
|
132
|
+
classes = []
|
|
133
|
+
|
|
134
|
+
Object.constants.each do |const_name|
|
|
135
|
+
begin
|
|
136
|
+
const = Object.const_get(const_name)
|
|
137
|
+
classes << const if const.is_a?(Class)
|
|
138
|
+
rescue NameError
|
|
139
|
+
nil
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
const_map.each_key do |klass_name|
|
|
144
|
+
begin
|
|
145
|
+
const = Object.const_get(klass_name)
|
|
146
|
+
classes << const if const.is_a?(Class)
|
|
147
|
+
rescue NameError
|
|
148
|
+
nil
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Every file is loaded by now. Marking the classes loaded stops
|
|
153
|
+
# AutoloadHook#inherited from re-dispatching (and so running the
|
|
154
|
+
# hook a second time) when it sees a class it has not loaded yet.
|
|
155
|
+
classes.uniq!
|
|
156
|
+
classes.each { loaded_classes[_1] = true }
|
|
115
157
|
|
|
116
|
-
|
|
117
|
-
|
|
158
|
+
# MRI runs `inherited` once per direct subclass, parents first.
|
|
159
|
+
classes.sort_by { _1.ancestors.size }.each { _1.superclass&.send(:inherited, _1) }
|
|
118
160
|
end
|
|
119
161
|
|
|
162
|
+
private
|
|
163
|
+
|
|
120
164
|
def fs_map
|
|
121
165
|
@fs_map ||= assets.fetch("fs_map")
|
|
122
166
|
end
|
|
@@ -128,7 +172,7 @@ module Interfacets
|
|
|
128
172
|
|
|
129
173
|
module AutoloadHook
|
|
130
174
|
def extend_object(o)
|
|
131
|
-
if Assets.loader.loaded?(self)
|
|
175
|
+
if Assets.loader.nil? || Assets.loader.bootstrapping? || Assets.loader.loaded?(self)
|
|
132
176
|
super
|
|
133
177
|
else
|
|
134
178
|
Assets.loader.load(self)
|
|
@@ -137,7 +181,7 @@ module Interfacets
|
|
|
137
181
|
end
|
|
138
182
|
|
|
139
183
|
def inherited(mod)
|
|
140
|
-
if Assets.loader.loaded?(self)
|
|
184
|
+
if Assets.loader.nil? || Assets.loader.bootstrapping? || Assets.loader.loaded?(self)
|
|
141
185
|
super
|
|
142
186
|
else
|
|
143
187
|
Assets.loader.load(self)
|
|
@@ -146,7 +190,7 @@ module Interfacets
|
|
|
146
190
|
end
|
|
147
191
|
|
|
148
192
|
def append_features(mod)
|
|
149
|
-
if Assets.loader.loaded?(self)
|
|
193
|
+
if Assets.loader.nil? || Assets.loader.bootstrapping? || Assets.loader.loaded?(self)
|
|
150
194
|
super
|
|
151
195
|
else
|
|
152
196
|
Assets.loader.load(self)
|
|
@@ -154,57 +198,26 @@ module Interfacets
|
|
|
154
198
|
end
|
|
155
199
|
end
|
|
156
200
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
# unless Assets.loader.loaded?(self)
|
|
170
|
-
# Assets.logger.debug("loaded: #{self}, now extending")
|
|
171
|
-
# Assets.loader.load(self)
|
|
172
|
-
# send(:extended, mod)
|
|
173
|
-
# else
|
|
174
|
-
# Assets.logger.debug("already loaded: #{self}, not extending")
|
|
175
|
-
# super
|
|
176
|
-
# end
|
|
177
|
-
# end
|
|
178
|
-
|
|
179
|
-
# def prepended(mod)
|
|
180
|
-
# unless Assets.loader.loaded?(self)
|
|
181
|
-
# Assets.loader.load(self)
|
|
182
|
-
# send(:prepended, mod)
|
|
183
|
-
# else
|
|
184
|
-
# super
|
|
185
|
-
# end
|
|
186
|
-
# end
|
|
187
|
-
|
|
188
|
-
# don't think this is needed
|
|
189
|
-
# def const_missing(const_name)
|
|
190
|
-
# if Assets.loader.loaded?(self)
|
|
191
|
-
# super
|
|
192
|
-
# else
|
|
193
|
-
# Assets.loader.load(self)
|
|
194
|
-
# const_get(const_name)
|
|
195
|
-
# end
|
|
196
|
-
# end
|
|
197
|
-
|
|
198
|
-
def method_missing(meth, *a, **p, &)
|
|
199
|
-
if Assets.loader.loaded?(self)
|
|
201
|
+
def const_missing(const_name)
|
|
202
|
+
if Assets.loader.nil? || Assets.loader.bootstrapping? || Assets.loader.loaded?(self)
|
|
203
|
+
super
|
|
204
|
+
else
|
|
205
|
+
Assets.loader.load(self)
|
|
206
|
+
const_get(const_name)
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
# rubocop:disable Style/ArgumentsForwarding, Naming/BlockForwarding
|
|
211
|
+
def method_missing(meth, *args, **opts, &block)
|
|
212
|
+
if Assets.loader.nil? || Assets.loader.bootstrapping? || Assets.loader.loaded?(self)
|
|
200
213
|
super
|
|
201
214
|
else
|
|
202
215
|
Assets.loader.load(self)
|
|
203
|
-
send(meth, *
|
|
216
|
+
send(meth, *args, **opts, &block)
|
|
204
217
|
end
|
|
205
218
|
end
|
|
219
|
+
# rubocop:enable Style/ArgumentsForwarding, Naming/BlockForwarding
|
|
206
220
|
end
|
|
207
221
|
end
|
|
208
222
|
end
|
|
209
223
|
end
|
|
210
|
-
# rubocop:enable Style/MissingRespondToMissing
|
|
@@ -6,15 +6,14 @@
|
|
|
6
6
|
module Interfacets
|
|
7
7
|
module Client
|
|
8
8
|
class Bus
|
|
9
|
+
attr_reader(:entity)
|
|
9
10
|
attr_reader(
|
|
10
11
|
:id,
|
|
11
12
|
:channels,
|
|
12
13
|
:channel_index,
|
|
13
14
|
:registry,
|
|
14
|
-
:
|
|
15
|
-
:root_url,
|
|
15
|
+
:root_url
|
|
16
16
|
)
|
|
17
|
-
|
|
18
17
|
def initialize(
|
|
19
18
|
id:,
|
|
20
19
|
channels:,
|
|
@@ -37,27 +36,47 @@ module Interfacets
|
|
|
37
36
|
end
|
|
38
37
|
|
|
39
38
|
def channel(name)
|
|
40
|
-
|
|
39
|
+
key = name.to_s
|
|
40
|
+
channel_index[key] ||
|
|
41
|
+
(channel_index["url"] if key == "interfacets:url") ||
|
|
42
|
+
channel_index.fetch(key) {
|
|
43
|
+
raise(
|
|
44
|
+
KeyError.new(
|
|
45
|
+
"channel #{key.inspect} is not registered; " \
|
|
46
|
+
"add it to the channels passed to initBus " \
|
|
47
|
+
"(registered: #{channel_index.keys.join(", ")})"
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
}
|
|
41
51
|
end
|
|
42
52
|
|
|
43
53
|
def handle(event)
|
|
44
54
|
channel_id = event.dig("destination", "channel")
|
|
45
|
-
raise(
|
|
55
|
+
raise(
|
|
56
|
+
"unknown event: #{event.inspect}"
|
|
57
|
+
) unless channel_id
|
|
46
58
|
channel = channel_index.fetch(channel_id)
|
|
47
59
|
|
|
48
60
|
channel.handle(
|
|
49
|
-
entity
|
|
61
|
+
entity:,
|
|
50
62
|
event: event.fetch("payload"),
|
|
51
63
|
build_entity: ->(name, id) {
|
|
52
64
|
@entity = registry.build(name, id)
|
|
53
|
-
channel_index.values.each { _1.prepare(
|
|
54
|
-
|
|
65
|
+
channel_index.values.each { _1.prepare(entity) }
|
|
66
|
+
entity
|
|
55
67
|
}
|
|
56
68
|
)
|
|
57
69
|
|
|
58
70
|
channel_index.values.each { _1.prepare(entity) }
|
|
59
71
|
|
|
60
|
-
entity
|
|
72
|
+
entity
|
|
73
|
+
.class
|
|
74
|
+
.view
|
|
75
|
+
.new
|
|
76
|
+
.render(
|
|
77
|
+
entity:,
|
|
78
|
+
channels: channel_index
|
|
79
|
+
)
|
|
61
80
|
|
|
62
81
|
{
|
|
63
82
|
type: "interfacets:bus:render",
|
|
@@ -4,31 +4,32 @@ module Interfacets
|
|
|
4
4
|
module Client
|
|
5
5
|
module Channels
|
|
6
6
|
class Api
|
|
7
|
-
include
|
|
7
|
+
include(Channels::Base)
|
|
8
8
|
|
|
9
9
|
class Builder
|
|
10
|
-
attr_accessor
|
|
11
|
-
|
|
12
|
-
def render(path)
|
|
13
|
-
raise("only one submission per action") if request
|
|
14
|
-
|
|
15
|
-
System.logger.debug("Getting #{path}")
|
|
16
|
-
|
|
17
|
-
request_id = SecureRandom.uuid
|
|
18
|
-
|
|
19
|
-
self.request = {
|
|
20
|
-
url: Client::System.current_bus.url_for(path),
|
|
21
|
-
method: "get",
|
|
22
|
-
}
|
|
23
|
-
end
|
|
10
|
+
attr_accessor(:request, :entity, :pending)
|
|
24
11
|
|
|
25
12
|
def submit(meth, nesting: )
|
|
26
|
-
raise(
|
|
13
|
+
raise(
|
|
14
|
+
"only one submission per action"
|
|
15
|
+
) if request
|
|
27
16
|
|
|
28
17
|
System.logger.debug("submitting #{meth}")
|
|
29
18
|
|
|
30
19
|
request_id = SecureRandom.uuid
|
|
31
20
|
|
|
21
|
+
# The server replies with the id of this serialized event as `in_reply_to`.
|
|
22
|
+
payload = (
|
|
23
|
+
Shared::Entities::Bus
|
|
24
|
+
.new(entity:)
|
|
25
|
+
.serialize(
|
|
26
|
+
to: "server",
|
|
27
|
+
action: meth,
|
|
28
|
+
nesting:
|
|
29
|
+
)
|
|
30
|
+
)
|
|
31
|
+
pending[payload.fetch(:id)] = nesting
|
|
32
|
+
|
|
32
33
|
self.request = {
|
|
33
34
|
url: (
|
|
34
35
|
if entity.respond_to?(:api_path)
|
|
@@ -40,15 +41,7 @@ module Interfacets
|
|
|
40
41
|
event: {
|
|
41
42
|
id: request_id,
|
|
42
43
|
type: "interfacets:api:submit",
|
|
43
|
-
payload:
|
|
44
|
-
Shared::Entities::Bus
|
|
45
|
-
.new(entity:)
|
|
46
|
-
.serialize(
|
|
47
|
-
to: "server" ,
|
|
48
|
-
action: meth,
|
|
49
|
-
nesting:
|
|
50
|
-
)
|
|
51
|
-
)
|
|
44
|
+
payload: payload,
|
|
52
45
|
},
|
|
53
46
|
},
|
|
54
47
|
}
|
|
@@ -63,8 +56,19 @@ module Interfacets
|
|
|
63
56
|
# builder. Because the bus calls "handle" before
|
|
64
57
|
# the "prepare" call. Perhaps these should be
|
|
65
58
|
# reversed?
|
|
66
|
-
@builder ||= Builder.new
|
|
67
|
-
|
|
59
|
+
@builder ||= Builder.new.tap { _1.pending = pending }
|
|
60
|
+
builder.entity = entity
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Request id -> nesting of the entity the request was sent from. A reply
|
|
64
|
+
# is only processed if it answers a pending request; the entry is
|
|
65
|
+
# consumed by the reply. The page's own hydrate is registered at boot.
|
|
66
|
+
def pending
|
|
67
|
+
@pending ||= {}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def expect_reply(id, nesting: ["root"])
|
|
71
|
+
pending[id] = nesting
|
|
68
72
|
end
|
|
69
73
|
|
|
70
74
|
def builder(stream = "default")
|
|
@@ -74,27 +78,122 @@ module Interfacets
|
|
|
74
78
|
def result
|
|
75
79
|
{
|
|
76
80
|
streams: {
|
|
77
|
-
default:
|
|
81
|
+
default: builder.request,
|
|
78
82
|
},
|
|
79
|
-
}.tap {
|
|
83
|
+
}.tap { builder.request = nil }
|
|
80
84
|
end
|
|
81
85
|
|
|
82
86
|
def handle(event:, entity:, build_entity:)
|
|
83
87
|
facet_name = event.fetch("facet")
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
action = event["action"] || event.dig("payload", "action")
|
|
89
|
+
extracted_nesting = event["nesting"] || event.dig("payload", "nesting") || ["root"]
|
|
90
|
+
in_reply_to = event["in_reply_to"] || event.dig("payload", "in_reply_to")
|
|
91
|
+
|
|
92
|
+
if in_reply_to
|
|
93
|
+
request_nesting = pending.delete(in_reply_to)
|
|
94
|
+
if request_nesting.nil?
|
|
95
|
+
System.logger.debug(
|
|
96
|
+
"ignoring reply to unknown request #{in_reply_to}"
|
|
97
|
+
)
|
|
98
|
+
return
|
|
99
|
+
end
|
|
100
|
+
if entity && entity.entity_at(request_nesting).nil?
|
|
101
|
+
System.logger.debug(
|
|
102
|
+
"ignoring reply to #{in_reply_to}: its entity no longer exists"
|
|
103
|
+
)
|
|
104
|
+
return
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
if patch_action?(
|
|
109
|
+
entity,
|
|
110
|
+
action,
|
|
111
|
+
extracted_nesting,
|
|
112
|
+
reply: !in_reply_to.nil?
|
|
89
113
|
)
|
|
114
|
+
patch_event = build_patch_event(
|
|
115
|
+
event,
|
|
116
|
+
entity:,
|
|
117
|
+
action:,
|
|
118
|
+
nesting: extracted_nesting,
|
|
90
119
|
|
|
91
|
-
|
|
120
|
+
in_reply_to:
|
|
121
|
+
)
|
|
92
122
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
123
|
+
Shared::Entities::Bus
|
|
124
|
+
.new(entity:)
|
|
125
|
+
.handle(event: patch_event)
|
|
126
|
+
else
|
|
127
|
+
# The root's id is echoed in `root_id`; server-initiated events carry
|
|
128
|
+
# it as the root's own attribute instead.
|
|
129
|
+
id = event.dig("payload", "root_id") ||
|
|
130
|
+
event.dig(
|
|
131
|
+
"payload",
|
|
132
|
+
"payload",
|
|
133
|
+
"attributes",
|
|
134
|
+
"internal_entity_id"
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
entity = build_entity.call(facet_name, id)
|
|
138
|
+
|
|
139
|
+
Shared::Entities::Bus
|
|
140
|
+
.new(entity:)
|
|
141
|
+
.handle(
|
|
142
|
+
event: event.fetch("payload")
|
|
143
|
+
)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
private
|
|
148
|
+
|
|
149
|
+
# Patch-like events are applied to the live entity, so that its
|
|
150
|
+
# local (dirty) state survives.
|
|
151
|
+
def build_patch_event(event, entity:, action:, nesting:, in_reply_to:)
|
|
152
|
+
payload = event["payload"]
|
|
153
|
+
|
|
154
|
+
if payload.is_a?(Hash) && payload.key?("attributes")
|
|
155
|
+
wrap_patch(
|
|
156
|
+
event,
|
|
157
|
+
entity:,
|
|
158
|
+
action:,
|
|
159
|
+
nesting:,
|
|
160
|
+
in_reply_to:,
|
|
161
|
+
payload:
|
|
162
|
+
)
|
|
163
|
+
elsif payload.is_a?(Hash) && payload.key?("payload")
|
|
164
|
+
payload
|
|
165
|
+
else
|
|
166
|
+
wrap_patch(
|
|
167
|
+
event,
|
|
168
|
+
entity:,
|
|
169
|
+
action:,
|
|
170
|
+
nesting:,
|
|
171
|
+
in_reply_to:,
|
|
172
|
+
|
|
173
|
+
payload: { "attributes" => payload || {} }
|
|
97
174
|
)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def wrap_patch(event, entity:, action:, nesting:, in_reply_to:, payload:)
|
|
179
|
+
{
|
|
180
|
+
"id" => SecureRandom.uuid,
|
|
181
|
+
"from" => event["from"] || "server",
|
|
182
|
+
"to" => event["to"] || entity.entity_role.to_s,
|
|
183
|
+
"nesting" => nesting,
|
|
184
|
+
"action" => action,
|
|
185
|
+
"in_reply_to" => in_reply_to,
|
|
186
|
+
"payload" => payload,
|
|
187
|
+
}.compact
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def patch_action?(entity, action, nesting, reply:)
|
|
191
|
+
return false unless entity
|
|
192
|
+
|
|
193
|
+
target = (nesting.is_a?(Array) && entity.entity_at(nesting)) || entity
|
|
194
|
+
spec = target.class.actions[action.to_s]
|
|
195
|
+
spec = spec.for_reply if reply && spec
|
|
196
|
+
spec&.patch? || false
|
|
98
197
|
end
|
|
99
198
|
end
|
|
100
199
|
end
|
|
@@ -4,21 +4,21 @@ module Interfacets
|
|
|
4
4
|
module Client
|
|
5
5
|
module Channels
|
|
6
6
|
class Audio
|
|
7
|
-
include
|
|
7
|
+
include(Channels::Base)
|
|
8
8
|
|
|
9
9
|
type("interfacets:audio")
|
|
10
10
|
|
|
11
11
|
class Builder
|
|
12
|
-
|
|
13
|
-
attr_accessor :entity
|
|
12
|
+
attr_accessor(:entity)
|
|
14
13
|
|
|
14
|
+
attr_reader(:event, :callbacks)
|
|
15
15
|
def initialize
|
|
16
16
|
@event = {}
|
|
17
17
|
@callbacks = {}
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def flush_event
|
|
21
|
-
|
|
21
|
+
event.tap { @event = {} }
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def play(sounds, reset_offset: false)
|
|
@@ -33,12 +33,12 @@ module Interfacets
|
|
|
33
33
|
type: "load",
|
|
34
34
|
payload: audios,
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
callbacks[id] = block
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
def request_mic(&block)
|
|
40
40
|
id = SecureRandom.uuid
|
|
41
|
-
|
|
41
|
+
callbacks[id] = block
|
|
42
42
|
@event = {
|
|
43
43
|
id:,
|
|
44
44
|
type: "request-mic",
|
|
@@ -48,7 +48,7 @@ module Interfacets
|
|
|
48
48
|
|
|
49
49
|
def start_recording(&block)
|
|
50
50
|
id = SecureRandom.uuid
|
|
51
|
-
|
|
51
|
+
callbacks[id] = block
|
|
52
52
|
@event = {
|
|
53
53
|
id:,
|
|
54
54
|
type: "start-record",
|
|
@@ -58,7 +58,7 @@ module Interfacets
|
|
|
58
58
|
|
|
59
59
|
def stop_recording(&block)
|
|
60
60
|
id = SecureRandom.uuid
|
|
61
|
-
|
|
61
|
+
callbacks[id] = block
|
|
62
62
|
@event = {
|
|
63
63
|
id:,
|
|
64
64
|
type: "stop-record",
|
|
@@ -88,12 +88,15 @@ module Interfacets
|
|
|
88
88
|
if event["payload"].nil? || event["payload"].empty?
|
|
89
89
|
entity.instance_exec(&callback) if callback
|
|
90
90
|
elsif callback
|
|
91
|
-
entity.instance_exec(
|
|
91
|
+
entity.instance_exec(
|
|
92
|
+
event.fetch("payload"),
|
|
93
|
+
&callback
|
|
94
|
+
)
|
|
92
95
|
end
|
|
93
96
|
end
|
|
94
97
|
|
|
95
98
|
def result
|
|
96
|
-
{ streams: { default:
|
|
99
|
+
{ streams: { default: builder.flush_event } }
|
|
97
100
|
end
|
|
98
101
|
end
|
|
99
102
|
end
|