Interface InfiniteApiControllerInterface

The InfiniteApiControllerInterface interface is the core singleton of the 3djuump infinite javascript API.

It provides access to the following services :

  • Font loading system.
  • Logging System.
  • Power saving management and 3djuump infinite internal clock.
  • Browser detection.

The Font loading mechanism is available through getFontLoader.

The font loading mechanism may be done with the following :

/** 
* Sample to illustrate the Loading of fonts.
*/
import { FontLoaderInterface, InfiniteFactory, FontLoaderInterfaceSignal, InfiniteEvent, FontLoadingStatus, FontInterface } from 'generated/documentation/appinfiniteapi';

// font loading is used wheen loading annotations

// what to do when fonts are loaded
let lFontLoaded : (pEvent : InfiniteEvent) => void;
// get the font loader, no need to create it, all the time available (singleton)
const lFontLoader : FontLoaderInterface = InfiniteFactory.GetInfiniteApiController().getFontLoader();
// register font Open Sans normal (no bold, no italic) by its url
const lFontRegistered : boolean = lFontLoader.registerFont('Open Sans', false, false, 'resources/fonts/OpenSans-Regular.otf');
console.assert(lFontRegistered, 'font should be registered');

// what to do when fonts is loaded ?
lFontLoader.addEventListener(FontLoaderInterfaceSignal.FontsLoaded, lFontLoaded)
// load explicitly font, if not, font will be loaded if required when loading annotations
const lLoadStatus : FontLoadingStatus = lFontLoader.loadFont('Open Sans', false, false);
console.assert(lLoadStatus === FontLoadingStatus.FLS_LoadingStarted, 'Font loading should be started');

// when fonts are loaded => what do we do ?
// perhaps some gui code ?
lFontLoaded = (_pEvent : InfiniteEvent) : void =>
{
// get all registered fonts and their status
const lFonts : Array<FontInterface> = [];
lFontLoader.getRegisteredFonts(lFonts);
let i : number;
let lErrorCount : number = 0;
for (i = 0; i < lFonts.length; ++i)
{
if (lFonts[i].error !== undefined)
{
++lErrorCount;
}
}
console.assert(lErrorCount === 0, 'There should be no font in error');
// when font is loaded, we unload it, but perhaps we should make some gui code ? :)
lFontLoader.unregisterFont('Open Sans', false, false);
}

The logging system is based on string messages with a criticality and a timestamp (date). The 3djuump infinite javascript API may log messages when key events occur.

You may :

/** 
* Sample to illustrate the use of the logging system.
*/
import { InfiniteApiControllerInterface, InfiniteFactory, InfiniteLogger, LogLevel, LogBehavior } from 'generated/documentation/appinfiniteapi';

// a custom logger
class MyLogger implements InfiniteLogger
{
// just output a fancy message, but you may use your own GUI
addLog(pContent : string, pDate : Date, pLevel : LogLevel) : void
{
console.log('got log ' + pContent + ' at time ' + pDate + ' at level ' + pLevel);
}
}

// the api controller interface (no need to create it, it is available !)
const lControllerInterface : InfiniteApiControllerInterface = InfiniteFactory.GetInfiniteApiController();
// create our custom logger
const lLogger : MyLogger = new MyLogger();
// no message less than information
lControllerInterface.setLogLevel(LogLevel.LL_Information);
// and we use our custom logger for the Information level
lControllerInterface.setLogLevelBehavior(LogLevel.LL_Information, LogBehavior.LB_LogToObject, lLogger);

// add some logs
lControllerInterface.addLog('this log should be discarded', LogLevel.LL_Debug);

lControllerInterface.addLog('this log should be displayed with my fancy logger', LogLevel.LL_Information);

The power saving system may be used to lower the CPU usage of the API when the browser is hidden. The 3djuump infinite javascript API features an internal clock that ticks every 16 milliseconds if the browser has the focus, and every 1 second when the browser has not the focus and power saving is enabled. When the internal clock ticks, the infinite objects are updated and calculated, and the [Tick](../enums/InfiniteApiControllerInterfaceSignal.html#Tick) signal is sent when all objects have been updated. Please note that the [DisplayDone](../enums/InfiniteEngineInterfaceSignal.html#DisplayDone) signal is sent by the [InfiniteEngineInterface](InfiniteEngineInterface.html) when the **rendering** is done (this is not at the same moment than [Tick](../enums/InfiniteApiControllerInterfaceSignal.html#Tick)). Power saving is enabled with [setPowerSavingEnabled](InfiniteApiControllerInterface.html#setPowerSavingEnabled).

The browser detection is based on bowser. At the start of the API, the running browser is detected and getBrowserName, getBrowserType, getBrowserVersion provide information about the current browser. The browser type is a BrowserType that helps identify the current browser.

NB : In case of Microsoft Edge, two versions exist, one is chromium based, the other not, and isEdgeChromium helps to disambiguate the two.


Main

See

Hierarchy

Methods

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal. It is possible to add an object that will be included in the callback to avoid creating too many closures.

    Returns

    The id of the inserted callback (actually an UUID).

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.
    • pObject: undefined | Object
      in
      The optional object the callback will be called with when the given event fires.

    Returns string

  • Adds a listener to an event type.

    When an event of the type pType fires, the callback pListener will be called. This function returns a unique string id that may be used in removeEventListenerById to allow simple listener removal.

    Returns

    The id of the inserted callback (actually an UUID).

    Parameters

    • pType: string
      in
      The type of the event pListener will be called upon.
    • pListener: tListenerCallback
      in
      The listener function that fires when the given event type occurs.

    Returns string

  • Adds a log to be logged.

    The log timestamp is the current time of the call.

    Parameters

    • pContent: string
      in
      The log content.
    • pLevel: LogLevel
      in
      The criticality of the log message.

    Returns void

  • Gets the current browser name.

    Returns

    The current browser name.

    Returns string

  • Gets the current browser type.

    Returns

    The current browser type.

    Returns BrowserType

  • Gets the current browser version.

    Returns

    The current browser version.

    Returns string

  • Gets the version of the infinite API.

    Returns

    The version of the infinite API.

    Returns string

  • Tells if the EventDispatcher has such a callback registered for the given event type.

    Returns

    true if such a listener is installed for the given type of event.

    Parameters

    • pType: string
      in
      The type of the event to test.
    • pListener: tListenerCallback
      in
      The listener function that gets tested.

    Returns boolean

  • Tells when the current browser is Microsoft Edge if the browser is chromium based.

    Returns

    true if the current browser is Microsoft Edge and if it is chromium based.

    Returns boolean

  • Tells if power saving mode is enabled.

    Power saving mode is used to save CPU usage when the browser tab is hidden by introducing some frame throttling.

    Returns

    true if the power saving mode is enabled.

    Returns boolean

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Returns

    true if the callback was removed else false.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    • pObject: undefined | Object

      The listener object that was used when addEventListener was called.

    Returns boolean

  • Removes a listener from an event type.

    If no such listener is found, then the function returns false and does nothing. You must use the exact parameters that were used in addEventListener to actually remove the listener.

    Returns

    true if the callback was removed else false.

    Parameters

    • pType: string
      in
      The type of the listener that gets removed.
    • pListener: tListenerCallback

      The listener function that gets removed.

    Returns boolean

  • Removes a listener by its id.

    If no such listener is found, then the function returns false and does nothing. You must use the return value of addEventListener to actually remove the listener.

    Returns

    true if the callback was removed else false.

    Parameters

    • pId: string
      in
      The id returned by the call to [addEventListener](InfiniteApiControllerInterface.html#addEventListener) that you want to remove.

    Returns boolean

  • Sets the log level of the logger.

    Any message with a criticality strictly lower than pLogLevel will be silently discarded. You cannot set a criticality lower than LL_Debug and bigger than LL_Required.

    Returns

    true if pLogLevel is correct and that the log level has been set.

    Parameters

    • pLogLevel: LogLevel
      in
      The new current log level.

    Returns boolean

  • Customizes the way logging is handled for a specific criticality.

    pLogLevel must be superior or equal to LL_Debug and strictly inferior to LL_Required. Thus, the LL_Required level cannot be customized.

    You may choose to :

    When using LB_LogToObject, pLogObject cannot be undefined, else pLogObject is ignored.

    Returns

    true if the log level has been set (i.e. pLogLevel and pBehavior are correct and pLogObject is defined in case of LB_LogToObject).

    Parameters

    • pLogLevel: LogLevel
      in
      The log level to override.
    • pBehavior: LogBehavior
      in
      The log behavior to use.
    • Optional pLogObject: InfiniteLogger
      in
      The logger to use in case of [LB_LogToObject](../enums/LogBehavior.html#LB_LogToObject).

    Returns boolean

  • Enables/Disables power saving mode.

    Power saving mode is used to save CPU usage when the browser tab is hidden by introducing some frame throttling. The FilterSolverInterface calculations will be slower if the tab is hidden.

    Power saving is disabled (false) by default.

    Parameters

    • pIsPowerSavingEnabled: boolean
      in
      tells if the power saving mode should be enabled.

    Returns void