lib/livekit/utils.rb in livekit-server-sdk-0.6.4 vs lib/livekit/utils.rb in livekit-server-sdk-0.6.5

- old
+ new

@@ -1,39 +1,35 @@ -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 +# frozen_string_literal: true - [k.to_s, v_str] +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 - Hash[h] end +end - # via https://stackoverflow.com/a/25835016/2257038 - def symbol_keys - h = self.map do |k, v| - v_sym = if v.instance_of? Hash - v.symbol_keys - else - v - end - - [k.to_sym, v_sym] +module LiveKit + module Utils + def to_http_url(url) + if url.start_with?("ws") + # replace ws prefix to http + return url.sub(/^ws/, "http") + else + return url + end end - Hash[h] + + module_function :to_http_url end end - # convert websocket urls to http -def to_http_url(url) - if url.start_with?("ws") - # replace ws prefix to http - return url.sub(/^ws/, "http") - else - return url - end -end \ No newline at end of file