Using JavaScript Callbacks

Kiosk Pro's JavaScript API uses predefined callbacks which are triggered by different events. For example, the callback  kp_ExternalScreen_videoPlaybackStateDidChange is triggered whenever the current video changes playback state.

Some Kiosk Pro functions let you define a callback of your own:

kp_ExternalScreen_getCurrentVideoPlaybackState(callback);

In this case, you would choose a callback name of your choice, (for example, "callback1") and then define that callback and what you want to happen somewhere else in your script:

function callback1(playbackState, filePath, currentTime, duration, isLooped) {
	if (playbackState = 1) {
		// Stop the video and open new url
	}
}

The structure of the callback and the parameters it returns are predefined by the app, but you can name it whatever you want.

Creating a chain of callbacks

You can call multiple callbacks in a row by chaining callbacks together. Using External Screen API functions as an example:

function setBackground() {
	kp_ExternalScreen_setBrowserBgColor('255,255,255','setBrowserBgColorCallback');	
}
function setBrowserBgColorCallback() {
	kp_ExternalScreen_openDocument('img/logo-screen.png','openDocumentCallback');
}
function openDocumentCallback(success) {
	window.kp_ExternalScreen_setPlayVideoParams('1','0,0,0','setPlayVideoParamsCallback');
}

In this scenario, the function is calling an API function to set the background color, which has the option for a callback. This callback is user defined, and is used to call another API function to open a document, which has another callback option. The third callback is used to set the parameters for playing a video.

Still stuck? How can we help? How can we help?