Sha256: ec117c2afac2d495141acc97fcbe9e10ec26c6452e82fcd866231d800bdd04f0

Contents?: true

Size: 1.69 KB

Versions: 40

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module RubyRabbitmqJanus
  module Tools
    module Replaces
      # Format message request with good data to HASH format for Handle request.
      # Manage sdp, handle_id, candidate or candidates.
      #
      # @author VAILLANT Jeremy <jeremy.vaillant@dazzl.tv>
      class Handle < Session
        private

        def replace_element_classic
          super
          replace_sdp if request.key?('jsep')
          replace_handle if request.key?('handle_id')
          replace_candidate \
            if request.key?('candidate') || request.key?('candidates')
        end

        def replace_handle
          request['handle_id'] = type.convert('handle_id', opts)
        rescue => exception
          ::Log.warn "Error handle replace : #{exception}"
        end

        def replace_candidate
          cdn = type.convert(determine_key_candidate, opts)
          request[cdn[0]] = cdn[1]
          delete_key_unless
        rescue => exception
          ::Log.warn "Error candidate replace : #{exception}"
        end

        def replace_sdp
          request['jsep']['sdp'] = type.convert('sdp', opts)
        rescue => exception
          ::Log.warn "Error sdp replace : #{exception}"
        end

        def determine_key_candidate
          if request.key?('candidate')
            'candidate'
          else
            'candidates'
          end
        end

        def delete_key_unless
          singular = request['candidate']
          plural = request['candidates']
          if singular.eql?('<array>')
            request.delete('candidate')
          elsif plural.eql?('candidates')
            request.delete['candidates']
          end
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
ruby_rabbitmq_janus-2.7.2.pre.306 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.2.pre.305 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.2.pre.302 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.2.pre.297 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.2.pre.296 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.2.pre.286 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.2.pre.285 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.2.pre.284 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.1 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.1.pre.274 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.0.pre.272 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.0 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.0.pre.269 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.7.0.pre.267 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.6.0 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.6.0.pre.263 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.6.0.pre.261 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.6.0.pre.260 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.6.0.pre.259 lib/rrj/tools/replaces/handle.rb
ruby_rabbitmq_janus-2.6.0.pre.258 lib/rrj/tools/replaces/handle.rb