Twitch SDK (Internal)
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ttv::ads::AdsAPI Class Reference

#include <adsapi.h>

Inheritance diagram for ttv::ads::AdsAPI:
ttv::ModuleBase ttv::IModule

Classes

class  CoreApiClient
 

Public Types

using FetchAdsCallback = std::function< void(TTV_ErrorCode ec, std::vector< Ad > &&result)>
 
using ReportAdEventsCallback = std::function< void(TTV_ErrorCode ec)>
 
enum  State { State::Uninitialized, State::Initializing, State::Initialized, State::ShuttingDown }
 
using InitializeCallback = std::function< void(TTV_ErrorCode ec)>
 
using ShutdownCallback = std::function< void(TTV_ErrorCode ec)>
 

Public Member Functions

 AdsAPI ()
 
virtual ~AdsAPI ()
 
virtual std::string GetModuleName () const override
 
virtual TTV_ErrorCode Initialize (const InitializeCallback &callback) override
 
virtual TTV_ErrorCode Shutdown (const ShutdownCallback &callback) override
 
virtual TTV_ErrorCode Update () override
 
TTV_ErrorCode SetCoreApi (const std::shared_ptr< CoreAPI > &coreApi)
 
TTV_ErrorCode FetchAds (const AdConfiguration &config, const AdFetchRequestInfo &info, const FetchAdsCallback &callback)
 
TTV_ErrorCode ReportAdEvent (const std::string &url, const std::map< std::string, std::string > &macroSubstitutions, const ReportAdEventsCallback &callback)
 
TTV_ErrorCode ReportAdEvents (const std::vector< std::string > &urls, const std::map< std::string, std::string > &macroSubstitutions)
 
virtual State GetState () const override
 

Protected Member Functions

virtual bool CheckShutdown () override
 
virtual void CompleteShutdown () override
 
void NotifyStateChange ()
 
void RegisterInitializeCallback (const InitializeCallback &callback)
 
void RegisterShutdownCallback (const ShutdownCallback &callback)
 
template<typename T >
void Invoke (std::function< void(std::shared_ptr< T >)> callback)
 
std::shared_ptr< ComponentContainerGetComponentContainer ()
 

Protected Attributes

EventSource< IModuleListenermListeners
 
State mState
 
State mLastReportedState
 

Private Attributes

std::shared_ptr< CoreAPImCoreApi
 
std::shared_ptr< TaskRunnermTaskRunner
 
std::shared_ptr< CoreApiClientmCoreApiClient
 

Detailed Description

Provides client-side VAST functionality.

The following properties must be set before calling Initialize().

There are 2 main methods.

Member Typedef Documentation

◆ FetchAdsCallback

using ttv::ads::AdsAPI::FetchAdsCallback = std::function<void(TTV_ErrorCode ec, std::vector<Ad>&& result)>

◆ InitializeCallback

using ttv::IModule::InitializeCallback = std::function<void(TTV_ErrorCode ec)>
inherited

◆ ReportAdEventsCallback

◆ ShutdownCallback

using ttv::IModule::ShutdownCallback = std::function<void(TTV_ErrorCode ec)>
inherited

Member Enumeration Documentation

◆ State

enum ttv::IModule::State
stronginherited
Enumerator
Uninitialized 
Initializing 
Initialized 
ShuttingDown 

Constructor & Destructor Documentation

◆ AdsAPI()

ttv::ads::AdsAPI::AdsAPI ( )

◆ ~AdsAPI()

virtual ttv::ads::AdsAPI::~AdsAPI ( )
virtual

Member Function Documentation

◆ CheckShutdown()

virtual bool ttv::ads::AdsAPI::CheckShutdown ( )
overrideprotectedvirtual

Reimplemented from ttv::ModuleBase.

◆ CompleteShutdown()

virtual void ttv::ads::AdsAPI::CompleteShutdown ( )
overrideprotectedvirtual

Reimplemented from ttv::ModuleBase.

◆ FetchAds()

TTV_ErrorCode ttv::ads::AdsAPI::FetchAds ( const AdConfiguration config,
const AdFetchRequestInfo info,
const FetchAdsCallback callback 
)

Fetches a pod of ads using the given config and info. See AdConfiguration and AdFetchRequestInfo for options. MediaFiles within LinearCreatives will be returned sorted by decreasing width.

◆ GetComponentContainer()

std::shared_ptr<ComponentContainer> ttv::ModuleBase::GetComponentContainer ( )
inlineprotectedinherited

Returns the common ComponentContainer which hosts all components which live at the module level.

◆ GetModuleName()

virtual std::string ttv::ads::AdsAPI::GetModuleName ( ) const
overridevirtual

Returns the name of the module.

Implements ttv::IModule.

◆ GetState()

virtual State ttv::ModuleBase::GetState ( ) const
overridevirtualinherited

Returns the current state of the module.

Implements ttv::IModule.

◆ Initialize()

virtual TTV_ErrorCode ttv::ads::AdsAPI::Initialize ( const InitializeCallback callback)
overridevirtual

Initializes the module asynchronously. The module state will be reported in IModuleListener::ModuleStateChanged(). No other calls should be made into the module until the module state is either State::Initialized or State::Uninitialized. You should only expect changes to the module state if this method succeeds.

Reimplemented from ttv::ModuleBase.

◆ Invoke()

template<typename T >
void ttv::ModuleBase::Invoke ( std::function< void(std::shared_ptr< T >)>  callback)
inlineprotectedinherited

Invokes the callback for the module listeners.

◆ NotifyStateChange()

void ttv::ModuleBase::NotifyStateChange ( )
protectedinherited

◆ RegisterInitializeCallback()

void ttv::ModuleBase::RegisterInitializeCallback ( const InitializeCallback callback)
inlineprotectedinherited

◆ RegisterShutdownCallback()

void ttv::ModuleBase::RegisterShutdownCallback ( const ShutdownCallback callback)
inlineprotectedinherited

◆ ReportAdEvent()

TTV_ErrorCode ttv::ads::AdsAPI::ReportAdEvent ( const std::string &  url,
const std::map< std::string, std::string > &  macroSubstitutions,
const ReportAdEventsCallback callback 
)

Report tracking info to the passed-in URL. This can be used for the following cases:

  • Impression URLs, when first displaying the ad
  • Click event URLs, when the user clicks on the ad
  • Event tracking URLs, which correspond to particular events when displaying the ad (Pause, Mute, Progress/Quartile events, etc.)
  • Error URLs, if there is an issue with fetching or playing an ad.

The URLs provided by the VAST server often include square-bracket-enclosed macro strings for which the client can provide replacement values. The client can provide these values with the macroSubstitutions parameter, with the keys being lower-cased strings of the macro name. The values are automatically percent encoded by the request before being injected into the URL. Any values not provided are replaced with an empty string, with the exception of the "cachebusting" macro which is automatically replaced with an 8-digit random number as per the VAST specification.

◆ ReportAdEvents()

TTV_ErrorCode ttv::ads::AdsAPI::ReportAdEvents ( const std::vector< std::string > &  urls,
const std::map< std::string, std::string > &  macroSubstitutions 
)

Similar to ReportAdEvent but handles a batch of urls. There is no success or failure callback. If you require confirmation of success use ReportAdEvent in a loop to know which urls are failing.

◆ SetCoreApi()

TTV_ErrorCode ttv::ads::AdsAPI::SetCoreApi ( const std::shared_ptr< CoreAPI > &  coreApi)

◆ Shutdown()

virtual TTV_ErrorCode ttv::ads::AdsAPI::Shutdown ( const ShutdownCallback callback)
overridevirtual

Initiates an asynchronous shutdown of the module. The module state will be reported in IModuleListener::ModuleStateChanged(). No other calls should be made into the module until the module state is either State::Initialized or State::Uninitialized. All modules that depend on this module need to be shutdown first. You should only expect changes to the module state if this method succeeds.

Reimplemented from ttv::ModuleBase.

◆ Update()

virtual TTV_ErrorCode ttv::ads::AdsAPI::Update ( )
overridevirtual

Updates the internal state of the module and fires any pending callbacks.

Reimplemented from ttv::ModuleBase.

Member Data Documentation

◆ mCoreApi

std::shared_ptr<CoreAPI> ttv::ads::AdsAPI::mCoreApi
private

◆ mCoreApiClient

std::shared_ptr<CoreApiClient> ttv::ads::AdsAPI::mCoreApiClient
private

◆ mLastReportedState

State ttv::ModuleBase::mLastReportedState
protectedinherited

◆ mListeners

EventSource<IModuleListener> ttv::ModuleBase::mListeners
protectedinherited

The registered listeners. These listeners extend IModuleListener and will be of the type required for the module.

◆ mState

State ttv::ModuleBase::mState
protectedinherited

◆ mTaskRunner

std::shared_ptr<TaskRunner> ttv::ads::AdsAPI::mTaskRunner
private

The documentation for this class was generated from the following file: