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



48
49
50
# File 'lib/screen-recorder/common.rb', line 48

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
# File 'lib/screen-recorder/common.rb', line 22

def start
  ScreenRecorder.logger.debug 'Starting recorder...'
  @video   = nil # New file
  @process = start_ffmpeg
  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



33
34
35
36
37
38
39
40
41
# File 'lib/screen-recorder/common.rb', line 33

def stop
  ScreenRecorder.logger.debug 'Stopping ffmpeg...'
  exit_code = stop_ffmpeg
  return if exit_code == 1 # recording failed

  ScreenRecorder.logger.debug 'Stopped ffmpeg.'
  ScreenRecorder.logger.info 'Recording complete.'
  @video = prepare_video unless exit_code == 1
end