JavaScript Calls
This page lists the JavaScript calls that are available through the Screenleap API. The JavaScript API provides the following functionality:
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.onPresenterConnectusually gets called afterscreenleap.onScreenShareStartbut 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.startRecordingandscreenleap.stopRecording) only works after the presenter app has connected to the app server, so you'll want to use thescreenleap.onPresenterConnectcallback 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
participantIdis a Screenleap identifier for a participant. TheexternalIdparameter will only be included if you provided an optionalexternalIdfor 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 thecallbackOnEndUrlcallback 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, iferrorCallbackis 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 passerrorCallbacktoscreenleap.startRecording, you should still implementscreenleap.onRecordStartErrorso you get notified when recording couldn't be started whenautoRecordis enabled. screenleap.onError(action, message, err)- This function is called when an error is encountered. The
actionis the name of the action that triggered the error. Themessagemay provide some additional explanation of the issue. Theerris either anErrorobject or anXmlHttpRequestobject, 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
window.onload = function() {
screenleap.onScreenShareStart = function() {
alert('Your screen is now shared.');
};
screenleap.onScreenShareEnd = function() {
alert('Your share session has ended.');
};
screenleap.onRecordingStartError = function() {
alert('Unable to start recording. You should alert your user and reset the recording UI.');
};
screenleap.onError = function(action, errorMessage, xhr) {
var msg = action + ': ' + errorMessage;
if (xhr) {
msg += ' (' + xhr.status + ')';
}
alert('Error in ' + msg);
};
}
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.
