Download zamok.js and include it in your website.
Example:
<script src="zamok.js"></script>
Please Note: You must allow your website's domain in the Zamok Dashboard at Settings > Webview > API Origins.
const zamok = Zamok.api('https://www.mywebsite.com'); // Most websites will use this method
// or
const zamok = Zamok.api({ topWindowOrigin: 'https://www.mywebsite.com' }); // for usage in sub frame (iframe)
// or
const zamok = Zamok.api({ topWindowOrigin: 'https://www.mywebsite.com', topWindowRef: someWindowObject }); // if the above doesn't work you may need to supply topmost window reference
The API loads asynchronously. You must wait for .ready
before you can request state or dispatch an action.
zamok.ready
.then(() => {
// The API is now ready
}
.catch((e)=>console.error)
type ZamokAction = { type: string; payload?: any };
type ZamokState = {
kiosk: {
kid: string; // kiosk ID
name: string;
};
// many other fields that can vary based on enabled modules
};
type ZamokUpdate = { state: ZamokState; action: ZamokAction };
type GetStateProps = { needProps: string[] };
zamok.getState(props?: GetStateProps): Promise<ZamokState>
Resolves with most recent state.
An optional parameter can be used to ensure the resolved state already has the properties you need, e.g.
zamok.getState({ needProps: ['someSolutionSettings'] }).then(({ someSolutionSettings }) => {
console.log('This is not undefined:', someSolutionSettings);
});
zamok.dispatch(action: ZamokAction): Promise<ZamokState>
Dispatches an action and resolves with updated state
zamok.waitForAction(type: string, timeoutMs?: number | Date): Promise<ZamokUpdate>
Waits for Zamok action of specified type.
If timeoutMs
is specified, waits for specified amount of milliseconds and rejects if there's no result to resolve with yet.
zamok.data$: Observable<ZamokUpdate>
RxJS observable. ZamokUpdate is fired anytime Redux action is fired or state changes. Contains {action: ReduxAction, state: ReduxState }.