lib/livekit/utils.rb in livekit-server-sdk-0.6.5 vs lib/livekit/utils.rb in livekit-server-sdk-0.7.0
- old
+ new
@@ -1,35 +1,26 @@
# frozen_string_literal: true
-unless Hash.method_defined?(:stringify_keys)
- class Hash
- # via https://stackoverflow.com/a/25835016/2257038
- def stringify_keys
- h = self.map do |k, v|
- v_str = if v.instance_of? Hash
- v.stringify_keys
- else
- v
- end
-
- [k.to_s, v_str]
- end
- Hash[h]
- end
- end
-end
-
module LiveKit
module Utils
+ # Utility function to convert WebSocket URLs to HTTP URLs
def to_http_url(url)
if url.start_with?("ws")
- # replace ws prefix to http
- return url.sub(/^ws/, "http")
+ # Replace 'ws' prefix with 'http'
+ url.sub(/^ws/, "http")
else
- return url
+ url
end
end
-
module_function :to_http_url
+
+ module StringifyKeysRefinement
+ refine Hash do
+ def stringify_keys
+ transform_keys(&:to_s).transform_values do |value|
+ value.is_a?(Hash) ? value.stringify_keys : value
+ end
+ end
+ end
+ end
end
-end
-# convert websocket urls to http
+end
\ No newline at end of file