Module: WscSdk::TranscoderSharedMethods

Included in:
Models::LiveStream, Models::Transcoder
Defined in:
lib/wsc_sdk/modules/transcoder_shared_methods.rb

Overview

Module for providing methods to handle state actions and transitions for a Transcoder or Live Stream model, since they have a lot of shared functionality.

Instance Method Summary collapse

Instance Method Details

#reset(options = {}) {|wait_state, transcoder_state| ... } ⇒ WscSdk::Model::TranscoderState

Reset the transcoder/live stream

If a block is passed to the call, the SDK will start a state request loop that checks the state of the transcoder for a given period of time (timeout). Each iteration of the wait loop will call the block with the current state of the wait loop, and the current state of the transcoder

The wait state will be one of 3 options: :waiting, :complete or :timeout

The loop will exit when the transcoder state is “started” or the timeout limit is reached.

Examples:

Simple Reset Request

state = transcoder.reset

Reset and Wait for Started

transcoder.reset do |wait_state, transcoder_state|
  if wait_state == :waiting
    puts "Waiting for the transcoder to start..."
  if wait_state == :timeout
    puts "The transcoder did not start in within the timeout period."
  else
    puts "Transcoder is #{state.state}.  The IP Address is #{state.ip_address}."
  end
end

Parameters:

  • options (Hash) (defaults to: {})

    A hash of options

Options Hash (options):

  • :timeout (Integer) — default: 30

    The maximum wait for a `started` state response.

  • :poll_interval (Integer) — default: 5

    The wait time (in seconds) between state requests. (Min: 1)

Yields:

  • (wait_state, transcoder_state)

    Calls the block with the states of the wait loop and the transcoder.

Yield Parameters:

  • wait_state (Symbol)

    The current state of the wait loop. Will always be one of the following: :waiting, :complete, :cannot_change_state or :timeout

  • transcoder_state (WscSdk::Model::TranscoderState)

    The current transcoder state data.

Returns:

  • (WscSdk::Model::TranscoderState)

    The transcoder state after the method execution has completed.



147
148
149
150
151
# File 'lib/wsc_sdk/modules/transcoder_shared_methods.rb', line 147

def reset(options={}, &block)
  current_state = self.endpoint.reset(self.id)
  return wait_for_state(:started, options, &block) if current_state.success? and block_given?
  return current_state
end

#start(options = {}) {|wait_state, transcoder_state| ... } ⇒ WscSdk::Model::TranscoderState

Start the transcoder/live stream

If a block is passed to the call, the SDK will start a state request loop that checks the state of the transcoder for a given period of time (timeout). Each iteration of the wait loop will call the block with the current state of the wait loop, and the current state of the transcoder

The wait state will be one of 3 options: :waiting, :complete or :timeout

The loop will exit when the transcoder state is “started” or the timeout limit is reached.

Examples:

Simple Start Request

state = transcoder.start

Start and Wait for Started

transcoder.start do |wait_state, transcoder_state|
  if wait_state == :waiting
    puts "Waiting for the transcoder to start..."
  if wait_state == :timeout
    puts "The transcoder did not start in within the timeout period."
  else
    puts "Transcoder is #{state.state}.  The IP Address is #{state.ip_address}."
  end
end

Parameters:

  • options (Hash) (defaults to: {})

    A hash of options

Options Hash (options):

  • :timeout (Integer) — default: 30

    The maximum wait for a `started` state response.

  • :poll_interval (Integer) — default: 5

    The wait time (in seconds) between state requests. (Min: 1)

Yields:

  • (wait_state, transcoder_state)

    Calls the block with the states of the wait loop and the transcoder.

Yield Parameters:

  • wait_state (Symbol)

    The current state of the wait loop. Will always be one of the following: :waiting, :complete, :cannot_change_state or :timeout

  • transcoder_state (WscSdk::Model::TranscoderState)

    The current transcoder state data.

Returns:

  • (WscSdk::Model::TranscoderState)

    The transcoder state after the method execution has completed.



59
60
61
62
63
# File 'lib/wsc_sdk/modules/transcoder_shared_methods.rb', line 59

def start(options={}, &block)
  current_state = self.endpoint.start(self.id)
  return wait_for_state(:started, options, &block) if current_state.success? and block_given?
  return current_state
end

#stateWscSdk::Model::TranscoderState

Return the current state of the transcoder/live stream.

Returns:

  • (WscSdk::Model::TranscoderState)


157
158
159
# File 'lib/wsc_sdk/modules/transcoder_shared_methods.rb', line 157

def state
  return self.endpoint.state(self.id)
end

#statsWscSdk::Model::TranscoderStats

Return the url of the current stats for the transcoder/live stream.

Returns:

  • (WscSdk::Model::TranscoderStats)


174
175
176
# File 'lib/wsc_sdk/modules/transcoder_shared_methods.rb', line 174

def stats
  return self.endpoint.stats(self.id)
end

#stop(options = {}) {|wait_state, transcoder_state| ... } ⇒ WscSdk::Model::TranscoderState

Stop the transcoder

If a block is passed to the call, the SDK will start a state request loop that checks the state of the transcoder for a given period of time (timeout). Each iteration of the wait loop will call the block with the current state of the wait loop, and the current state of the transcoder

The wait state will be one of 3 options: :waiting, :complete or :timeout

The loop will exit when the transcoder state is “stopped” or the timeout limit is reached.

Examples:

Simple Stop Request

state = transcoder.stop

Stop and Wait for Stopped

transcoder.stop do |wait_state, transcoder_state|
  if wait_state == :waiting
    puts "Waiting for the transcoder to stop..."
  if wait_state == :timeout
    puts "The transcoder did not stop in within the timeout period."
  else
    puts "Transcoder is #{state.state}."
  end
end

Parameters:

  • options (Hash) (defaults to: {})

    A hash of options

Options Hash (options):

  • :timeout (Integer) — default: 30

    The maximum wait for a `stopped` state response.

  • :poll_interval (Integer) — default: 5

    The wait time (in seconds) between state requests. (Min: 1)

Yields:

  • (wait_state, transcoder_state)

    Calls the block with the states of the wait loop and the transcoder.

Yield Parameters:

  • wait_state (Symbol)

    The current state of the wait loop. Will always be one of the following: :waiting, :complete, :cannot_change_state or :timeout

  • transcoder_state (WscSdk::Model::TranscoderState)

    The current transcoder state data.

Returns:

  • (WscSdk::Model::TranscoderState)

    The transcoder state after the method execution has completed.



103
104
105
106
107
# File 'lib/wsc_sdk/modules/transcoder_shared_methods.rb', line 103

def stop(options={}, &block)
  current_state = self.endpoint.stop(self.id)
  return wait_for_state(:stopped, options, &block) if current_state.success? and block_given?
  return current_state
end

#thumbnail_urlWscSdk::Model::TranscoderThumbnailUrl

Return the url of the current thumbnail for transcoder/live stream.

Returns:

  • (WscSdk::Model::TranscoderThumbnailUrl)


166
167
168
# File 'lib/wsc_sdk/modules/transcoder_shared_methods.rb', line 166

def thumbnail_url
  return self.endpoint.thumbnail_url(self.id)
end