Interface ProxyChoiceInterface

The ProxyChoiceInterface interface allows the developer to create an heuristic to elect the best proxy to connect to.

Future versions of this interface will also include load and number of users heuristics.

/** 
* Sample to illustrate the use of the the choice of a proxy for the open data procedure (DataSessionInterface).
*/
import {
tChooseProxyCallback, ProxyChoiceInterface, tSetProxyCallback, InfiniteCacheInterface,
DirectorySessionInterface, DataSessionInterface, DataSessionInterfaceSignal, tListenerCallback
} from 'generated/documentation/appinfiniteapi';

// lDirectorySession has been created previously, the user is now logged in and knows the 3djuump infinite available builds.
let lDirectorySession : DirectorySessionInterface;
// lInfiniteCache may has been created previously (not required)
let lInfiniteCache : InfiniteCacheInterface | undefined;
// the build id to connect to
let lBuildId : string;
// the callback that will be called when the DMU has finished loading
let myDMULoadedCallback : tListenerCallback;

// very simple callback, choose the first available proxy
const lChooseProxyCallback : tChooseProxyCallback = (pProxies: Array<ProxyChoiceInterface>, pFinishLoadingCallback : tSetProxyCallback) : void =>
{
let i : number;
const lLength : number = pProxies.length;
// output all proxies
for (i = 0; i < lLength; ++i)
{
console.log(pProxies[0].getLabel());
}
// DO NOT forget to call pFinishLoadingCallback, if not, the DMU loading process will never finish
// and with the url of the chosen proxy
pFinishLoadingCallback(pProxies[0].getUrl());
}

// connect the data session to the build, the proxy choice is asynchronous, and will
// trigger lChooseProxyCallback when the dev chooses a proxy
const lDataSession : DataSessionInterface | undefined = lDirectorySession.createDataSession(lBuildId, lInfiniteCache, lChooseProxyCallback);
if (!lDataSession)
{
console.log('something weird happened, the directory session cannot create a data session');
console.log('Perhaps the directory session is already closed, or closing, or the login procedure failed');
}
else
{
// we sure want to be notified when the DMU has finished loading
lDataSession.addEventListener(DataSessionInterfaceSignal.DMULoadingSuccess, myDMULoadedCallback);

// and GO => open the data session
if (!lDataSession.openDataSession())
{
console.log('something weird happened, this session has already been used, this is not a freshly created one');
}

// and wait for myDMULoadedCallback to be called
}

Please refer to [DirectorySessionInterface](DirectorySessionInterface.html) for more information.
Sessions

See

DirectorySessionInterface

Hierarchy

  • ProxyChoiceInterface

Methods

Methods

  • Gets the label of the proxy.

    Returns

    The label of the given proxy.

    Returns string

  • Gets the url of the proxy.

    Returns

    The url of the given proxy.

    Returns string