ruby-utcp 1.1.2 → 1.1.3
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/CHANGELOG.md +7 -0
- data/examples/servers/webrtc_server.rb +3 -3
- data/lib/utcp/code_mode/client.rb +30 -0
- data/lib/utcp/code_mode/control_flow.rb +97 -0
- data/lib/utcp/code_mode/evaluator.rb +176 -0
- data/lib/utcp/code_mode/expressions.rb +217 -0
- data/lib/utcp/code_mode/interface_generator.rb +84 -0
- data/lib/utcp/code_mode/runtime.rb +70 -0
- data/lib/utcp/code_mode/value_limits.rb +93 -0
- data/lib/utcp/code_mode/value_methods.rb +204 -0
- data/lib/utcp/code_mode.rb +9 -913
- data/lib/utcp/protocols/webrtc.rb +18 -13
- data/lib/utcp/protocols/websocket.rb +3 -0
- data/lib/utcp/version.rb +1 -1
- metadata +9 -1
|
@@ -11,7 +11,8 @@ module UTCP
|
|
|
11
11
|
@condition = ConditionVariable.new
|
|
12
12
|
@responses = {}
|
|
13
13
|
@candidates = []
|
|
14
|
-
configuration =
|
|
14
|
+
configuration = { disable_auto_negotiation: true }
|
|
15
|
+
configuration[:ice_servers] = template.ice_servers unless template.ice_servers.empty?
|
|
15
16
|
@connection = WebRTC::RTCPeerConnection.new(configuration)
|
|
16
17
|
install_candidate_handler
|
|
17
18
|
@channel = @connection.create_data_channel(template.data_channel_name)
|
|
@@ -23,9 +24,9 @@ module UTCP
|
|
|
23
24
|
|
|
24
25
|
def connect
|
|
25
26
|
offer = @connection.create_offer.await
|
|
26
|
-
|
|
27
|
+
# webrtc-ruby creates and installs the local offer in one native operation.
|
|
27
28
|
wait_for_ice_gathering
|
|
28
|
-
response = post_json("connect", "peer_id" => @template.peer_id, "sdp" =>
|
|
29
|
+
response = post_json("connect", "peer_id" => @template.peer_id, "sdp" => offer.sdp)
|
|
29
30
|
answer = WebRTC::RTCSessionDescription.new(type: :answer, sdp: response.fetch("sdp"))
|
|
30
31
|
@connection.set_remote_description(answer).await
|
|
31
32
|
Array(response["candidates"]).each do |candidate|
|
|
@@ -157,7 +158,7 @@ module UTCP
|
|
|
157
158
|
|
|
158
159
|
def register_manual(client, template)
|
|
159
160
|
assert_webrtc_template!(template)
|
|
160
|
-
response = peer_for(template).connect
|
|
161
|
+
response = peer_for(client, template).connect
|
|
161
162
|
payload = if response.is_a?(Hash) && response.key?("tools") && !response.key?("utcp_version")
|
|
162
163
|
{
|
|
163
164
|
"utcp_version" => VERSION,
|
|
@@ -169,20 +170,24 @@ module UTCP
|
|
|
169
170
|
end
|
|
170
171
|
success(template, manual_from_payload(template, payload, source: "WebRTC signaling response"))
|
|
171
172
|
rescue StandardError => error
|
|
173
|
+
deregister_manual(client, template)
|
|
172
174
|
client.logger.warn("Unable to register WebRTC manual #{template.name.inspect}: #{error.message}")
|
|
173
175
|
failure(template, error)
|
|
174
176
|
end
|
|
175
177
|
|
|
176
|
-
def deregister_manual(
|
|
177
|
-
|
|
178
|
-
|
|
178
|
+
def deregister_manual(client, template)
|
|
179
|
+
peers = @mutex.synchronize do
|
|
180
|
+
keys = @peers.keys.select { |owner, name, *_rest| owner.equal?(client) && name == template.name }
|
|
181
|
+
keys.map { |key| @peers.delete(key) }
|
|
182
|
+
end
|
|
183
|
+
peers.each(&:close)
|
|
179
184
|
nil
|
|
180
185
|
end
|
|
181
186
|
|
|
182
|
-
def call_tool(
|
|
187
|
+
def call_tool(client, tool_name, tool_args, template)
|
|
183
188
|
assert_webrtc_template!(template)
|
|
184
189
|
identifier = SecureRandom.uuid
|
|
185
|
-
peer_for(template).request(
|
|
190
|
+
peer_for(client, template).request(
|
|
186
191
|
{
|
|
187
192
|
"id" => identifier,
|
|
188
193
|
"tool" => tool_name.to_s.split(".").last,
|
|
@@ -204,12 +209,12 @@ module UTCP
|
|
|
204
209
|
raise ValidationError, "WebRTC protocol requires a WebRtcCallTemplate"
|
|
205
210
|
end
|
|
206
211
|
|
|
207
|
-
def peer_for(template)
|
|
208
|
-
@mutex.synchronize { @peers[peer_key(template)] ||= @peer_factory.call(template) }
|
|
212
|
+
def peer_for(client, template)
|
|
213
|
+
@mutex.synchronize { @peers[peer_key(client, template)] ||= @peer_factory.call(template) }
|
|
209
214
|
end
|
|
210
215
|
|
|
211
|
-
def peer_key(template)
|
|
212
|
-
[template.name, template.signaling_server, template.peer_id, template.data_channel_name]
|
|
216
|
+
def peer_key(client, template)
|
|
217
|
+
[client, template.name, template.signaling_server, template.peer_id, template.data_channel_name]
|
|
213
218
|
end
|
|
214
219
|
end
|
|
215
220
|
WebrtcCommunicationProtocol = WebRTCProtocol
|
data/lib/utcp/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-utcp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ruby-utcp contributors
|
|
@@ -155,6 +155,14 @@ files:
|
|
|
155
155
|
- lib/utcp.rb
|
|
156
156
|
- lib/utcp/client.rb
|
|
157
157
|
- lib/utcp/code_mode.rb
|
|
158
|
+
- lib/utcp/code_mode/client.rb
|
|
159
|
+
- lib/utcp/code_mode/control_flow.rb
|
|
160
|
+
- lib/utcp/code_mode/evaluator.rb
|
|
161
|
+
- lib/utcp/code_mode/expressions.rb
|
|
162
|
+
- lib/utcp/code_mode/interface_generator.rb
|
|
163
|
+
- lib/utcp/code_mode/runtime.rb
|
|
164
|
+
- lib/utcp/code_mode/value_limits.rb
|
|
165
|
+
- lib/utcp/code_mode/value_methods.rb
|
|
158
166
|
- lib/utcp/config.rb
|
|
159
167
|
- lib/utcp/errors.rb
|
|
160
168
|
- lib/utcp/migration.rb
|