3dEYE Toolkit

Multiple Instances

Run several toolkit app instances side by side and pass them to components via React context.

app contains a reference to the default instance of the toolkit application. It is used automatically by all the components.

import { app } from '@3deye-toolkit/core';

const options = {
    token: {...},                  // token previously obtained from API
    tokenStorage: localStorage;    // optional storage for token. Token is stored in memory by default
	tokenStorageKey: string;       // optional key for token in storage
	apiUrl: string;                // optional
	tokenServiceUrl: string;       // optional
}

// default app
const defaultApp = app.init(options);

// another app
const myApp = app.init(options, 'my-app');

console.log(app === defaultApp); // true
console.log(myApp === defaultApp); // false

// stop connection to the 3dEYE service and free resources
app.dispose();

You can pass other instances to the components using React Context API:

import { app, AppContext } from '@3deye-toolkit/core';
import { Camera } from '@3deye-toolkit/react-camera';

const app1 = app.init({ token }, 'app-1');
const app2 = app.init({ token }, 'app-2');

function App() {
	return (
		<AppContext.Provider value={app2}>
			<Camera id={1} />
		</AppContext.Provider>
	);
}