JavaScript Calls
This page lists the JavaScript calls that are available through the Screenleap API. The JavaScript API provides the following functionality:
- Start a Share Session
- Controlling an Active Share Session
- Implementing Callback Functions
- Access Share Session Properties
Start a Share Session
After you have created a share session (see Make a Share Session Request), these functions can be used to start the share session.
screenleap.startSharing(presenterAppType, screenShareData, callbacks)
Starts a share session using the specified presenter app.
The available presenterAppType
options are:
- IFREE - Installation-free sharing. Neither the presenters nor viewers need to install any software.
- NATIVE - The native Screenleap application for Mac and Windows. The native application has the advantage of only requiring a download the first time it is run, or when an update is required.
The screenShareData
is the JSON object received from a successful request to make
a new share session.
The callbacks
is a JavaScript object contain functions
that you implement that will be called when specific share session events occur during the course of a share session.
The available callbacks are:
nativeDownloadStarting
- ForNATIVE
shares, this callback will be called when the download of the native app begins. Use this callback to show instructions to the users for installing the app and starting the share session.screenShareStarting
- For all shares, this callback will be called when the downloaded app starts. Use it to display feedback to the user that the share is starting.screenShareStartError
- This callback will be called when the share session cannot be started. Use this callback to let the user know that the share session was unable to be started and allow them to try starting a new share.
screenleap.downloadNativeApp(onAppDownloadEnd, callbacks)
Downloads the native app and calls the onAppDownloadEnd
function when the download is complete.
Accepted callback:
nativeDownloadStarting
: function to call before the download begins. Use this call to display the installation instructions.
screenleap.startAppUsingCustomProtocolHandler()
Attempts to start the native app using the custom protocol handler. This call is usually made from a link in the instructions shown the users when the automatic attempt to start the presenter app using the custom protocol handler fails.
Controlling an Active Share Session
screenleap.stopSharing()
- Stop the active share session.screenleap.pauseSharing(successCallback, errorCallback)
- Pause the active share session.screenleap.resumeSharing(successCallback, errorCallback)
- Resume a paused but active share session.
ImplementingCallback Functions
You can get notified about various screen sharing events by implementing JavaScript callback functions on the screenleap object. For example, you can get notified when a viewer joins or leaves a share session so that you can update your page to show or hide participant information.
screenleap.onScreenShareStart()
- This function is called when the web page is able to successfully connect to the presenter app. If you do not define this function, the default behavior is to pop up an alert.
screenleap.onPresenterConnect()
- This function is called when the presenter app has successfully connected to the app server.
screenleap.onPresenterConnect
usually gets called afterscreenleap.onScreenShareStart
but this is not guaranteed. Most of the time, you can implement either callbacks to add code you want to run after the share session starts. Some Screenleap JavaScript calls (such asscreenleap.startRecording
andscreenleap.stopRecording
) only works after the presenter app has connected to the app server, so you'll want to use thescreenleap.onPresenterConnect
callback for these situations. screenleap.onScreenShareEnd()
- This function is called when a share session ends. If you do not define this function, the default behavior is to pop up an alert.
screenleap.onViewerConnect(participantId, externalId)
screenleap.onViewerDisconnect(participantId, externalId)
- These functions are called whenever a viewer joins or leaves a share session, respectively. The
participantId
is a Screenleap identifier for a participant. TheexternalId
parameter will only be included if you provided an optionalexternalId
for this viewer's connection.
Note that this information is provided in order to give the presenter real-time information about viewer presence. It is not intended to be used for billing purposes. If a viewer's Internet connection drops and reconnects repeatedly, each event will trigger a callback. Please make use of thecallbackOnEndUrl
callback to receive billing information for a completed share session. screenleap.onPause()
screenleap.onResume()
- These functions will get called when the share session gets paused or resumed, respectively.
screenleap.onRecordStartError
- This function is called when we are unable to start recording the share session due to an error. When calling
screenleap.startRecording
, iferrorCallback
is passed in, errors starting the recording will be passed to the callback. Otherwise, errors starting the recording will be reported viascreenleap.onRecordStartError
. Even if you passerrorCallback
toscreenleap.startRecording
, you should still implementscreenleap.onRecordStartError
so you get notified when recording couldn't be started whenautoRecord
is enabled. screenleap.onError(action, message, err)
- This function is called when an error is encountered. The
action
is the name of the action that triggered the error. Themessage
may provide some additional explanation of the issue. Theerr
is either anError
object or anXmlHttpRequest
object, depending on the type of error. The default behavior is to pop up an alert to help with integration. You will want to override this before releasing to your users so that your users are not shown an alert everytime there is an error.
Important Note: These functions are defined on the screenleap object which is instantiated by screenleap.js
.
As a result, it is important that you implement these callbacks in window.onload
to ensure that the screenleap
object is instantiated first.
Sample Callback Implementation
Access Share Session Properties
screenleap.getScreenShareCode()
- returns the 9-digit share code for this share session.screenleap.getViewerUrl()
- returns the URL for viewing this share.