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.
  • Wheel event conversion.

The Font loading mechanism is available through InfiniteApiControllerInterface.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_files/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 += 1)
{
if (lFonts[i].error !== undefined)
{
lErrorCount += 1;
}
}
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_files/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 InfiniteApiControllerInterfaceSignal.Tick signal is sent when all objects have been updated. Please note that the InfiniteEngineInterfaceSignal.DisplayDone signal is sent by the InfiniteEngineInterface when the **rendering** is done (this is not at the same moment than InfiniteApiControllerInterfaceSignal.Tick). Power saving is enabled with 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.

The wheel event conversion system helps having a consistent wheel event behavior depending on browser types. You may override/restore the default behavior with setWheelConverter / restoreDefaultWheelConverter by supplying a custom WheelConverterInterface implementation.


Main

interface InfiniteApiControllerInterface {
    addEventListener(pType, pListener, pObject): string;
    addEventListener(pType, pListener): string;
    addLog(pContent, pLogLevel): void;
    areSignalsBlocked(): boolean;
    asyncGetHardwareReport(): Promise<string>;
    blockSignals(pBlock): void;
    enableRequestIdentification(pEnable): void;
    getBrowserName(): string;
    getBrowserType(): BrowserType;
    getBrowserVersion(): string;
    getFontLoader(): FontLoaderInterface;
    getLogLevel(): LogLevel;
    getVersion(): string;
    getWebWorkerPath(): string;
    hasEventListener(pType, pListener): boolean;
    hasEventListenerById(pId): boolean;
    isEdgeChromium(): boolean;
    isPowerSavingEnabled(): boolean;
    isRequestIdentificationEnabled(): boolean;
    removeAllEventListeners(): boolean;
    removeEventListener(pType, pListener, pObject): boolean;
    removeEventListener(pType, pListener): boolean;
    removeEventListenerById(pId): boolean;
    restoreDefaultWheelConverter(): void;
    setLogLevel(pLogLevel): boolean;
    setLogLevelBehavior(pLogLevel, pBehavior, pLogObject?): boolean;
    setPowerSavingEnabled(pIsPowerSavingEnabled): void;
    setWebWorkerPath(pPath): boolean;
    setWheelConverter(pConverter): boolean;
}

Hierarchy (view full)

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. Calling twice addEventListener with the same parameters results in the second call to be ignored, only unique pairs callback / object are allowed, in order to avoid calling multiple times the same thing.

    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: Object
      in
      The optional object the callback will be called with when the given event fires.

    Returns string

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

  • 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.

    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

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

  • Adds a log to be logged.

    The log timestamp is the current time of the call.

    Parameters

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

    Returns void

  • Tells if signals sent by the object are blocked or not.

    If signals are blocked, no signal will be emitted nor buffered, such signal will be lost.

    Returns boolean

    true if signals are blocked.

  • Gets hardware information on the currently running instance.

    This information may be useful for debugging and statistics. This is the JSON representation of the multiple properties.

    Returns Promise<string>

    A promise. This is the JSON representation of the hardware properties.

  • Blocks / Unblocks all signals sent by the object.

    If signals are blocked, no signal will be emitted nor buffered, such signal will be lost.

    Parameters

    • pBlock: boolean
      in
      If set to true, all further signals will be silently discarded.

    Returns void

  • Enables/Disables the debug request identification.

    This feature should only be set for troubleshooting.

    Parameters

    • pEnable: boolean
      in
      If set to true, packet tracing will be enabled from client to server responses.

    Returns void

  • Gets the current browser name.

    Returns string

    The current browser name.

  • Gets the current browser version.

    Returns string

    The current browser version.

  • Gets the version of the Infinite API.

    Returns string

    The version of the Infinite API.

  • The infinite api is now using webworkers.

    For security reasons, webworkers cannot be launched from CORS.

    For this reason, the infinite api is shipped with a very small worker that needs to be included in the application, this worker then loads the actual updated webworker from the infinite directory.

    This call gets the full path to the webworker loader script (e.g infiniteapi-webworker-loader.js).

    Returns string

    The full path to the webworker loader script.

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

    Parameters

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

    Returns boolean

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

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

    Parameters

    • pId: string
      in
      The id of the callback to test.

    Returns boolean

    true if such a listener is installed for the given callback id.

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

    Returns boolean

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

  • 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 boolean

    true if the power saving mode is enabled.

  • Tells if the debug request identification is in use.

    This feature should only be used for troubleshooting.

    Returns boolean

    true If packet tracing is enabled from client to server responses.

  • 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.

    Parameters

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

      The listener function that gets removed.

    • pObject: Object

      The listener object that was used when addEventListener was called.

    Returns boolean

    true if the callback was removed else false.

  • 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.

    Parameters

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

      The listener function that gets removed.

    Returns boolean

    true if the callback was removed else false.

  • 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.

    Parameters

    • pId: string
      in
      The id returned by the call to addEventListener that you want to remove.

    Returns boolean

    true if the callback was removed else false.

  • Restores the default wheel event converter behavior.

    Wheel events are not consistent from browser to browser. In order to have the same behavior from browsers to browsers, the Infinite api needs to translate a wheel event to a homogeneous value.

    import { BrowserType, WheelConverterInterface } from 'generated_files/documentation/appinfiniteapi';

    // Wheel events are not really consistent from browser to browser
    // this default implementation runs on current usual browsers
    class DefaultWheelConverter implements WheelConverterInterface
    {
    // convert wheel event depending on browser and version
    convertWheelEvent(pEvent: WheelEvent, pBrowserTpe : BrowserType, pIsEdgeChromium: boolean, _pBrowserVersion : string) : number
    {
    switch (pBrowserTpe) {
    // firefox
    case BrowserType.firefox:
    return pEvent.deltaY * -1; // wheel value 3
    // safari
    case BrowserType.safari:
    // (pEvent['wheelDelta'] < 0 ? -1 : 1)
    return Math.min(24, Math.abs(pEvent['wheelDelta'])) * (1 - 2 * (<any>(pEvent['wheelDelta'] < 0) | 0)) * -15; // wheel value 12
    // edge
    case BrowserType.edge:
    if (pIsEdgeChromium) {
    return pEvent['wheelDelta'];
    }
    return pEvent['wheelDelta'] * 1.5; // wheel value 120
    // internet explorer
    case BrowserType.ie:
    return pEvent.deltaY * -0.9; // wheel value 198.3
    // default, mainly chrome
    default:
    if (pEvent['wheelDelta'] !== undefined) {
    return pEvent['wheelDelta']; // wheel value 180
    }
    if (pEvent.deltaY !== undefined) {
    return pEvent.deltaY * -60;
    }
    return 0;
    }
    }
    }
    export { DefaultWheelConverter };

    The default wheel converter may be overridden by setWheelConverter, and restored by this function.

    Returns void

  • 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 LogLevel.LL_Debug and bigger than LogLevel.LL_Required.

    Parameters

    • pLogLevel: LogLevel
      in
      The new current log level.

    Returns boolean

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

  • 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 WorkingSetInterface 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

  • The infinite api is now using webworkers.

    For security reasons, webworkers cannot be launched from CORS.

    For this reason, the infinite api is shipped with a very small worker that needs to be included in the application, this worker then loads the actual updated webworker from the infinite directory.

    This call sets the path to the correct script. If pPath does not end with .js, then pPath is considered as a folder and the default loader script name is used (e.g. pPath + infiniteapi-webworker-loader.js).

    Parameters

    • pPath: string
      in
      The path to use when loading the web-worker.

    Returns boolean

    true if the path was set.

  • Sets the wheel event converter behavior.

    Wheel events are not consistent from browser to browser. In order to have the same behavior from browsers to browsers, the Infinite api needs to translate a wheel event to a homogeneous value.

    Such behavior will depend on the browser type (getBrowserType) and optionally the browser version (getBrowserVersion).

    import { BrowserType, WheelConverterInterface } from 'generated_files/documentation/appinfiniteapi';

    // Wheel events are not really consistent from browser to browser
    // this default implementation runs on current usual browsers
    class DefaultWheelConverter implements WheelConverterInterface
    {
    // convert wheel event depending on browser and version
    convertWheelEvent(pEvent: WheelEvent, pBrowserTpe : BrowserType, pIsEdgeChromium: boolean, _pBrowserVersion : string) : number
    {
    switch (pBrowserTpe) {
    // firefox
    case BrowserType.firefox:
    return pEvent.deltaY * -1; // wheel value 3
    // safari
    case BrowserType.safari:
    // (pEvent['wheelDelta'] < 0 ? -1 : 1)
    return Math.min(24, Math.abs(pEvent['wheelDelta'])) * (1 - 2 * (<any>(pEvent['wheelDelta'] < 0) | 0)) * -15; // wheel value 12
    // edge
    case BrowserType.edge:
    if (pIsEdgeChromium) {
    return pEvent['wheelDelta'];
    }
    return pEvent['wheelDelta'] * 1.5; // wheel value 120
    // internet explorer
    case BrowserType.ie:
    return pEvent.deltaY * -0.9; // wheel value 198.3
    // default, mainly chrome
    default:
    if (pEvent['wheelDelta'] !== undefined) {
    return pEvent['wheelDelta']; // wheel value 180
    }
    if (pEvent.deltaY !== undefined) {
    return pEvent.deltaY * -60;
    }
    return 0;
    }
    }
    }
    export { DefaultWheelConverter };

    The default wheel converter may be restored by restoreDefaultWheelConverter.

    Parameters

    Returns boolean

    true if the call succeeded.