Sha256: a4fa0a487ee17f6cc7bd290c4422c17111ee16ad1d12bda2d563c33f69415976

Contents?: true

Size: 1.62 KB

Versions: 170

Compression:

Stored size: 1.62 KB

Contents

module Browser
  class Element
    element :video, :audio do
      def buffered
        TimeRanges.new(`#@native.buffered`)
      end

      def played
        TimeRanges.new(`#@native.played`)
      end

      def seekable
        TimeRanges.new(`#@native.seekable`)
      end

      def network_state
        case `#@native.networkState`
        when `HTMLMediaElement.NETWORK_EMPTY` then :no_data
        when `HTMLMediaElement.NETWORK_IDLE` then :idle
        when `HTMLMediaElement.NETWORK_LOADING` then :loading
        when `HTMLMediaElement.NETWORK_NO_SOURCE` then :no_source
        end
      end
    end

    element :video do
      def fullscreen
        fullscreen = %w(
          requestFullScreen
          requestFullscreen
          webkitRequestFullScreen
          webkitRequestFullscreen
          mozRequestFullScreen
          msRequestFullscreen
        ).find { |prop| `!!#@native[prop]` }

        if fullscreen
          `#@native[fullscreen]()`
        else
          warn "[#{self.class}] Cannot determine the method to full-screen a video"
          super
        end
      end
      alias request_fullscreen fullscreen
    end

    class TimeRanges
      include Enumerable

      def initialize native
        @native = native
      end

      def to_n
        @native
      end

      def each
        `#@native.length`.times do |i|
          yield TimeRange.new(`#@native.start(i)`, `#@native.end(i)`)
        end

        self
      end
    end

    class TimeRange
      attr_reader :start, :end

      def initialize start, _end
        @start = start
        @end = _end
      end

      alias begin start
    end
  end
end

Version data entries

170 entries across 170 versions & 2 rubygems

Version Path
isomorfeus-preact-22.9.0.rc3 lib/browser/element/media.rb
isomorfeus-preact-22.9.0.rc2 lib/browser/element/media.rb
isomorfeus-preact-22.9.0.rc1 lib/browser/element/media.rb
isomorfeus-preact-10.9.0 lib/browser/element/media.rb
isomorfeus-preact-10.8.2 lib/browser/element/media.rb
isomorfeus-preact-10.8.1 lib/browser/element/media.rb
isomorfeus-preact-10.8.0 lib/browser/element/media.rb
isomorfeus-preact-10.7.3 lib/browser/element/media.rb
isomorfeus-preact-10.7.2 lib/browser/element/media.rb
isomorfeus-preact-10.7.1 lib/browser/element/media.rb
isomorfeus-react-16.13.12 lib/browser/element/media.rb
isomorfeus-preact-10.7.0 lib/browser/element/media.rb
isomorfeus-preact-10.6.62 lib/browser/element/media.rb
isomorfeus-preact-10.6.61 lib/browser/element/media.rb
isomorfeus-preact-10.6.60 lib/browser/element/media.rb
isomorfeus-preact-10.6.59 lib/browser/element/media.rb
isomorfeus-preact-10.6.58 lib/browser/element/media.rb
isomorfeus-preact-10.6.57 lib/browser/element/media.rb
isomorfeus-preact-10.6.56 lib/browser/element/media.rb
isomorfeus-preact-10.6.55 lib/browser/element/media.rb