Ivideon Web SDK
Ivideon Web SDK
Changelog 3
Introduction 4
Supported browsers and platforms 4
Quick start 4
Sample code 4
Demo application 6
See the demo application online 6
Building the demo application 6
SDK API Guide 8
Initialization 8
Integrating the SDK with your web application 8
Changes made to the environment 8
Initializing the SDK 8
Authenticating the SDK to access Ivideon API 9
Event handling API 10
StandaloneWebSdkCamera 11
Creating a camera 11
Finding a closest archive record timestamp 12
StandaloneWebSdkPlayer 13
Creating a player 13
Starting the live playback 15
Starting the archive playback 16
Controlling the playback 17
Controlling the sound volume 18
Changing video rotation 18
Cleaning up 18
Other 18
StandaloneWebSdkTimeline 18
Creating a timeline 19
Binding the timeline to a camera to display archive records 20
Binding the timeline to a player to display playback state 20
Handling a timeline time click to play the corresponding video 20
Controlling the timeline time span 21
Cleaning up 21
StandaloneWebSdkCalendar 21
Creating a calendar 22
Binding the calendar to a camera to display archive records 22
Controlling the calendar selected day 22
Cleaning up 22
Internationalization API 22
Selecting a language and a locale 22
Adding a custom translation 23
Changelog
Version Date Changes
1.0.0 26 February 2019 [Feature] Added support for signed video and preview requests (see hmac_secret param in
configureWithCloudApiAuthResponse() ).
[Feature] The set of default player controls now supports video quality and speed selection.
[Feature] Default player controls can now be enabled or disabled individually (see defaultControls param in
createPlayer() ).
[Improvement] Demo application added! Now you can see a live example of Ivideon Web SDK (see the Demo application
section below).
[Bugfix] Fixed broken sound playback: SDK was not playing sound at all, and now it will. However, if you want to opt out
of this and disable sound, see soundEnabled param in createCamera() . It will also guarantee autoplay permissions for
your video, as some browsers forbid autoplay for videos with sound.
[Docs] Documentation overhauled, updated and corrected. Added info on new options and demo application.
0.19.1 12 December 2018 [Feature] Added WebRTC support (now WebRTC engine can be selected when creating a video player).
[Feature] Now you can limit archive search interval (see playArchive() method).
[Change] This SDK now uses Ivideon OpenAPI to communicate with the video streaming service.
If you were using streaming.ivideon.com as api_host value, please provide api_host returned to you with the
OpenAPI access token.
If you were using your own streaming service, you need to update its API to match that of Ivideon OpenAPI.
[Docs] Added a note about public video playback.
0.18.0 27 August 2018 [Feature] Added support for German, Spanish, French, Italian, Japanese, Portuguese, Russian and Turkish languages.
[Docs] Updated i18n documentation. Added info on creating custom translations.
0.17.0 05 June 2018 [Feature] Now a specific player engine can be manually selected when creating a video player (see playerEngine param
in the createPlayer() method).
0.15.8 05 February 2018 [Improvement] If api_host does not contain scheme, it will be prefixed with https:// .
Version Date Changes
0.15.7 30 November 2017 [Bugfix] Error messages on iOS were not displayed properly.
0.15.6 02 November 2017 [Bugfix] When using HLS engine after pausing archive video playhead stopped updating.
0.15.5 05 October 2017 [Bugfix] api_host param in configureWithCloudApiAuthResponse() method was not handled properly.
Introduction
The SDK provides a set of APIs and UI components to integrate a web application with Ivideon Server and Cloud software.
Ivideon recommends to ensure the customers have the automatic browser updates enabled.
Ivideon recommends Chrome with automatic updates enabled for its stability and reliability on every platform.
Quick start
Sample code
The code below demonstrates basic Ivideon Web SDK usage: a player is added to a page, and video playback is started for a public camera.
<!DOCTYPE html>
<html>
<head>
<title>Ivideon WEB SDK example</title>
<link rel="stylesheet" href="/vendor/ivideon-web-sdk-1.0.0/iv-standalone-web-sdk.css" />
<script src="/vendor/ivideon-web-sdk-1.0.0/iv-standalone-web-sdk.js"></script>
</head>
<body>
<div class="myapp-player-container" style="max-width: 640px;"></div>
<script>
_ivideon.sdk.init({
rootUrl: 'https://<your-domain>/vendor/ivideon-web-sdk-1.0.0/',
i18nOptions: {
availableLanguages: [
'de',
'en',
'fr',
],
language: 'en',
}
}).then(function (sdk) {
sdk.configureWithCloudApiAuthResponse({
api_host: 'openapi-alpha.ivideon.com',
access_token: 'public',
});
// `id` used below is not an actual camera ID. Replace it with your own.
var camera = sdk.createCamera({
id: '100-481adxa07s5cgd974306aff47e62b639:65536',
cameraName: 'Demo Cam',
imageWidth: 800,
imageHeight: 450,
soundEnabled: true,
});
player.playLive();
}, function (error) {
console.error(error);
});
</script>
</body>
</html>
Demo application
To get a better understanding of how to use Ivideon Web SDK with a UI library we distribute it with a demo application. Based on create-react-app, it showcases
the use of WEB SDK with ReactJS.
Initialization
1. Download the SDK archive and extract the files into a folder which is directly accessible from the browser. The assets should be available via a web server
through HTTP or HTTPS protocol.
For example, at /vendor/ivideon-standalone-web-sdk-1.0.0/
2. Include the CSS file into the page via the <link rel="stylesheet"> tag.
For example, <link rel="stylesheet" href="/vendor/ivideon-standalone-web-sdk-1.0.0/iv-standalone-web-sdk.css">
3. Include the JS file into the page via the <script> tag.
For example, <script src="/vendor/ivideon-standalone-web-sdk-1.0.0/iv-standalone-web-sdk.js"></script>
4. Include the initialization code snippet in a separate <script> tag after the SDK <script> tag.
If you’re unsure how to integrate Ivideon Web SDK into your application, check Quick start.
The dot-notation in the tables below designates the nested object structure.
options.rootUrl string Yes The absolute URL to the folder where the SDK is located.
Option Type Required? Description
options.i18nOptions Object<string,*> No The internationalization options. See the Internationalization API section for
additional info.
options.i18nOptions.availableLanguages Array No The list of 2-letter language codes for the languages to load. See the iv-i18n
subdirectory for the list of supported languages. Defaults to ['en'] .
options.i18nOptions.language string No The identifier of the language to select initially. Defaults to 'en' .
options.i18nOptions.locale string No The identifier of the locale (date and time formatting rules) to select initially.
Defaults to the language identifier, which is suitable for most cases.
_ivideon.sdk.init({
rootUrl: 'https://example.com/vendor/ivideon-standalone-web-sdk-1.0.0/',
i18nOptions: {
availableLanguages: [
'en'
],
language: 'en'
}
}).then(function (sdk) {
// Use `sdk` object which is an instance of `StandaloneWebSdk`.
}, function (error) {
// Handle the initialization error.
});
This is done via StandaloneWebSdk#configureWithCloudApiAuthResponse() method. The following JavaScript snippet shows how to do that.
/*
Pass the OAuth response object returned by the Ivideon API.
The object should have the following structure:
{
api_host: '...',
access_token: '...',
hmac_secret: '...',
// ...other fields
}
*/
sdk.configureWithCloudApiAuthResponse(cloudApiAuthResponse);
Please note:
If URL scheme in api_host param is omitted, it will be automatically prefixed with https://.
To play public video (which does not require authentication), use the following parameters:
api_host: 'openapi-alpha.ivideon.com'
access_token: 'public'
hmac_secret is a special key provided by Ivideon API to sign video feed and preview requests so that they could not be reused. If omitted, requests
will not be signed.
The call to StandaloneWebSdk#configureWithCloudApiAuthResponse() may be repeated later, when a new token is acquired.
Please note that the call will only affect the upcoming requests to the Ivideon API. Changing the configuration does not terminate the outstanding requests
made by the SDK, including video streams.
The dispatcher has the methods to subscribe and unsubscribe from the events happening in the SDK components.
StandaloneWebSdkDispatcher#subscribe(handler: function(event)) -> number — Registers a handler to listen to all events. Returns a handler identifier to
use in unsubscribe().
StandaloneWebSdkDispatcher#unsubscribe(handlerId: number) — Unregisters a handler by its identifier. The identifier is returned from subscribe().
event.sender Object Yes A reference to the component which reported the event.
The following JavaScript snippet subscribes a handler function to all events and then unsubscribes it.
StandaloneWebSdkCamera
The camera model is required to access video streams, previews, archive records etc.
Creating a camera
StandaloneWebSdk#createCamera(options) -> StandaloneWebSdkCamera
options.id string Yes The camera identifier. Use Camera.id from the Ivideon API.
options.soundEnabled boolean No If set to false, sound will be disabled for this camera and volume control will be hidden. Note that this can
help with restrictive browser autoplay policies , as for videos without sound autoplay is always available.
The following JavaScript snippet creates the camera model.
This function locates an archive record closest to the given timestamp (within a certain range). If there are no archive records within the specified range, it
returns null .
Defaults to 's' .
The following JavaScript snippet finds an archive record closest to current time (within -10 minute / +10 minute range).
camera.getClosestArchivePlaybackTime({
requiredTime: (new Date()).getTime(),
offsetValue: 600,
})
.then(function (closestArchiveRecord) {
if ( closestArchiveRecord !== null ) {
...
}
else {
...
}
})
.catch(function (error) {
...
});
StandaloneWebSdkPlayer
The player UI is created per camera for playing live and archive video from it.
Creating a player
StandaloneWebSdk#createPlayer(options: Object) -> StandaloneWebSdkPlayer
options.container HTMLElement | string Yes The DOM element or a CSS selector string that targets the element to put the
player into.
options.defaultControls boolean | No If undefined or true default player controls will be enabled: volume,
Object<string,boolean> play/pause/stop, live, quality, fullscreen, timeline, calendar and zoom-center
buttons under the player.
Or you can pass an object with the following keys enabling or disabling each
control separately:
options.playerEngine StandaloneWebSdkPlayerEngine No Video player supports several engines. Normally the optimal engine is selected
automatically, based on the user’s operating system and browser. However, in some
cases you may want to enforce the engine choice.
Possible values:
options.quality number No The quality value, one of the following: 0 (low), 1 (medium), 2 (high). Defaults to the last specified quality for live
or archive video, initially 2 (high).
The following JavaScript snippet starts live playback with the last specified quality.
player.playLive();
options.limitArchiveSearch boolean No If true, the search interval start at (options.startTime - offset) and end at (options.startTime +
offset) . The offset is specified by options.offsetValue and options.offsetUnit .
Defaults to 's' .
options.quality number No The quality value, one of the following: 0 (low), 1 (medium), 2 (high). Defaults to the last specified
quality for live or archive video, initially 2 (high).
player.playArchive({
startTime: Date.now() - 1000 * 60 * 60 //< Start an hour back from now.
});
Events:
ivideon.StandaloneWebSdkPlayer:playback-state-changed — The playback state has changed. Query getLoading, getPlaying, getPlayheadTime,
getPaused to get the current state.
StandaloneWebSdkPlayer#getVolume() -> number — Gets the sound volume. The volume value is from 0.0 to 1.0.
StandaloneWebSdkPlayer#setVolume(volume: number) — Sets the sound volume. The volume value is from 0.0 to 1.0.
StandaloneWebSdkPlayer#getMuted() -> boolean — Gets the sound muted state.
StandaloneWebSdkPlayer#setMuted(isMuted: boolean) — Mutes the sound or reverts the volume to the current level.
Events:
ivideon.StandaloneWebSdkPlayer:volume-changed — The volume has changed. Query getVolume to get the current value.
ivideon.StandaloneWebSdkPlayer:muted-changed — The muted state has changed. Query getMuted to get the current value.
StandaloneWebSdkPlayer#getVideoRotation() -> number — Gets the current video rotation angle. Either 0 or 180.
StandaloneWebSdkPlayer#setVideoRotation(volume: number) — Sets the current video rotation angle. Either 0 or 180.
Cleaning up
The player component should be explicitly destroyed before removing its container from the DOM.
Other
StandaloneWebSdkPlayer#getCamera() -> StandaloneWebSdkCamera — Returns the camera this player is bound to.
StandaloneWebSdkTimeline
The timeline displays the recorded archive of the bound cameras and the playback state of the bound players.
Events:
ivideon.StandaloneWebSdkTimeline:time-clicked — The user has clicked the timeline to select a video for playback. See Handling a timeline time
click to play the corresponding video.
Creating a timeline
StandaloneWebSdk#createTimeline(options: Object) -> StandaloneWebSdkTimeline
options.container HTMLElement | string Yes The DOM element or a CSS selector string that targets the element to put the
timeline into.
options.timelineColorsGenerator function({ camera: Yes A function to generate the timeline colors. Should return either an RGBA
StandaloneWebSdkCamera object {r:number,g:number,b:number,a:number}, or a string like rgba(0,0,0,0.5)
}):RGBA|string|undefined or #FFFFFF, or undefined to use the default color.
The timeline requests the color once for a camera when the camera gets
bound to the timeline.
The following example generates the timeline colors based on the camera index:
Event data:
data.now number Yes The timestamp when the event is sent, in milliseconds.
The following JavaScript snippet subscribes to all events via the StandaloneWebSdkDispatcher and handles a timeline click event to select live or archive video
depending on the clicked time.
StandaloneWebSdkTimeline#getTimeSpan() -> { startTime: number, endTime: number } — Returns the time span displayed on the timeline. If the timeline
is animating, this will be the target of the animation.
StandaloneWebSdkTimeline#centerAt(time: number, center: number, animate: boolean) — Centers the timeline view at the specified timestamp. The
center argument specifies the relative coordinate [0; 1] where the target time should end up (default is 0.5 which is the center).
StandaloneWebSdkTimeline#zoomBy(factor: number, center: number, animate: boolean) — Zooms the timeline view by the given factor (positive to zoom
in, negative to zoom out). The center argument specifies the relative coordinate [0; 1] where the zoom occurs (default is 0.5 which is the center).
Cleaning up
The timeline component should be explicitly destroyed before removing its container from the DOM.
StandaloneWebSdkCalendar
The calendar displays archive records and events on a calendar.
Creating a calendar
StandaloneWebSdk#createCalendar(options: Object) -> StandaloneWebSdkCalendar
StandaloneWebSdkCalendar#unbindCamera(camera: StandaloneWebSdkCamera)
Events:
ivideon.StandaloneWebSdkCalendar:selected-date-changed — The selected date has changed (either via setSelectedDate or via a user click). Query
getSelectedTimeSpan to get the current value.
ivideon.StandaloneWebSdkCalendar:selected-date-changed-by-user — The user has selected a date on the calendar. Query getSelectedTimeSpan
to get the current value.
Cleaning up
The calendar component should be explicitly destroyed before removing its container from the DOM.
Internationalization API
The SDK provides an API for selecting a language to render the messages, and for selecting a locale to render the time and date.
To obtain an entry point to the internationalization API, call the following method:
Sets the language and locale for the SDK components. The specified language must be added before with StandaloneWebSdkI18n#addMessages(category,
messages, language) .
language string Yes The identifier of the language to select. Supported options are:
'de' — Deutch
'en' — English
'es' — Spanish
'fr' — French
'it' — Italian
'pt' — Portuguese
'ja' — Japanese
'ru' — Russian
'tr' — Turkish
locale string No The identifier of the locale to select. Defaults to the language identifier. Supported options are the same as those of
language parameter (listed above).
Warning: The SDK components that have been created before must be destroyed and created again to correctly reflect the change in language and locale.
_ivideon.sdk.init({
…
i18nOptions: {
availableLanguages: [
'en',
'{lg}'
],
language: 'en',
…
English translation should be always added to availableLanguages list as it is used as a fallback in case a message is missing from the selected translation.
Please note new releases of the SDK can come with updated translation files, so you will have to update your custom translations as well.