Class: Puppeteer::ScreenRecorder
- Inherits:
-
Object
- Object
- Puppeteer::ScreenRecorder
- Defined in:
- lib/puppeteer/screen_recorder.rb,
sig/puppeteer/screen_recorder.rbs
Constant Summary collapse
- DEFAULT_FPS =
30- DEFAULT_QUALITY =
30- STOP =
Object.new.freeze
Class Method Summary collapse
Instance Method Summary collapse
Constructor Details
#initialize(page, width, height, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/puppeteer/screen_recorder.rb', line 28 def initialize(page, width, height, = {}) @page = page @fps = .fetch(:fps, DEFAULT_FPS) @format = ([:format] || 'webm').to_s @path = [:path] @stopped = false @stop_mutex = Mutex.new @finished = false @finish_mutex = Mutex.new @frame_queue = Queue.new @output = +''.b @last_buffer = ''.b @last_written_at = monotonic_time @start_timestamp = nil @previous_timestamp = nil @previous_buffer = nil ensure_output_directory command = build_command(width, height, ) @stdin, @stdout, @stderr, @wait_thread = Open3.popen3(*command) @stdin.binmode @stdout.binmode @writer_thread = Thread.new { write_frames } @stdout_thread = Thread.new { read_output } @stderr_thread = Thread.new { read_stderr } @client = @page.main_frame.client @frame_listener_id = @client.add_event_listener('Page.screencastFrame') do |event| handle_frame(event) end @disconnect_listener_id = @client.once(CDPSessionEmittedEvents::Disconnected) do stop rescue StandardError => error warn(error.) if ENV['DEBUG'] end end |
Class Method Details
.count_frames(start_timestamp, previous_timestamp, timestamp, fps) ⇒ Integer
18 19 20 21 22 |
# File 'lib/puppeteer/screen_recorder.rb', line 18 def self.count_frames(, , , fps) finish = (( - ) * fps).round start = (( - ) * fps).round [0, finish - start].max end |
Instance Method Details
#data ⇒ String
67 68 69 |
# File 'lib/puppeteer/screen_recorder.rb', line 67 def data @output.dup end |
#stop ⇒ void
This method returns an undefined value.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/puppeteer/screen_recorder.rb', line 72 def stop should_stop = @stop_mutex.synchronize do next false if @stopped @stopped = true true end unless should_stop finish_process return end begin @page._stop_screencast rescue StandardError # The page or its CDP session may already be gone. end enqueue_last_frame finish_process end |