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.
@@ -11,7 +11,8 @@ module UTCP
11
11
  @condition = ConditionVariable.new
12
12
  @responses = {}
13
13
  @candidates = []
14
- configuration = template.ice_servers.empty? ? nil : { ice_servers: template.ice_servers }
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
- @connection.set_local_description(offer).await
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" => @connection.local_description.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(_client, template)
177
- peer = @mutex.synchronize { @peers.delete(peer_key(template)) }
178
- peer&.close
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(_client, tool_name, tool_args, template)
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].join("\0")
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
@@ -36,6 +36,9 @@ module UTCP
36
36
  @closed = false
37
37
  open_socket
38
38
  handshake(headers, protocol)
39
+ rescue StandardError
40
+ @socket.close if @socket && !@socket.closed?
41
+ raise
39
42
  end
40
43
 
41
44
  def closed?
data/lib/utcp/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UTCP
4
- VERSION = "1.1.2"
4
+ VERSION = "1.1.3"
5
5
  end
6
6
 
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.2
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