Class: ScreenRecorder::Common Private

Inherits:
Object
  • Object
show all
Defined in:
lib/screen-recorder/common.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0-beta11

Direct Known Subclasses

Desktop, Window

Constant Summary collapse

PROCESS_TIMEOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Seconds to wait for ffmpeg to quit

Since:

  • 1.0.0-beta11

5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input:, output:, advanced: {}) ⇒ Common

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Common.

Raises:

Since:

  • 1.0.0-beta11


11
12
13
14
15
16
17
# File 'lib/screen-recorder/common.rb', line 11

def initialize(input:, output:, advanced: {})
  raise Errors::DependencyNotFound unless ffmpeg_exists?

  @options = Options.new(input: input, output: output, advanced: advanced)
  @video   = nil
  @process = nil
end

Instance Attribute Details

#optionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0-beta11


9
10
11
# File 'lib/screen-recorder/common.rb', line 9

def options
  @options
end

#videoObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 1.0.0-beta11


9
10
11
# File 'lib/screen-recorder/common.rb', line 9

def video
  @video
end

Instance Method Details

#discardObject Also known as: delete

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Discards the recorded file. Useful in automated testing when a test passes and the recorded file is no longer needed.

Since:

  • 1.0.0-beta11


57
58
59
# File 'lib/screen-recorder/common.rb', line 57

def discard
  File.delete options.output
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Starts the recording

Since:

  • 1.0.0-beta11


22
23
24
25
26
27
28
29
30
# File 'lib/screen-recorder/common.rb', line 22

def start
  ScreenRecorder.logger.debug 'Starting recorder...'
  @video = nil # New file
  @process = start_ffmpeg
  raise 'FFmpeg process failed to start.' unless @process.alive?

  ScreenRecorder.logger.info 'Recording...'
  @process
end

#stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Stops the recording

Since:

  • 1.0.0-beta11


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/screen-recorder/common.rb', line 35

def stop
  ScreenRecorder.logger.debug 'Stopping ffmpeg...'

  @process.stop

  @process.poll_for_exit(PROCESS_TIMEOUT)
  if @process.alive?
    ScreenRecorder.logger.error "Failed to stop ffmpeg (pid: #{@process.pid}). Please kill it manually."
    return
  end

  ScreenRecorder.logger.debug 'Stopped ffmpeg.'
  ScreenRecorder.logger.info 'Preparing video...'
  @video = prepare_video
  ScreenRecorder.logger.info 'Recording ready.'
end