-
Notifications
You must be signed in to change notification settings - Fork 2
Genetec Web Player Developer Guide
The Genetec Web Player (GWP) is a JavaScript/TypeScript library designed to embed live and playback video streams from Genetec Security Center™ into custom web applications. It offers advanced video streaming capabilities using WebSockets and Media Source Extensions, providing an easy-to-use API while abstracting the complexities of managing streams, codecs, and security.
This guide provides detailed instructions for integrating the GWP into your application, including setup, authentication, and usage examples for advanced features like PTZ control, timeline management, and diagnostics.
- Live and Playback Video Streaming: Access real-time and recorded video feeds.
- Audio Support: Stream AAC audio where supported.
- PTZ Camera Control: Low-latency Pan-Tilt-Zoom control.
- Dynamic Stream Selection: Adaptive resolution and bitrate adjustment based on player size.
- Digital Zoom: Enhance video regions for detailed views.
- Fisheye Dewarping: Correct fisheye distortions for a traditional PTZ-like experience.
- Timeline API: Access bookmarks and motion detection events.
- Diagnostics: Tools for debugging and monitoring.
-
Media Gateway Role:
- The Media Gateway Role must be configured in Security Center.
- Open ports 80 and 443 for public access.
- Ensure the Media Gateway and GWP library versions are compatible.
-
Authentication:
- Security Center user credentials or pre-generated tokens.
-
Environment Requirements:
- Supported Browsers: Chrome, Firefox, Edge, Safari, Internet Explorer 11.
- Node.js (if using the provided sample server).
-
Camera GUIDs: Unique identifiers for the cameras you wish to stream.
The GWP library can be included in two ways:
<script src="https://<MediaGatewayAddress>/v2/files/gwp.js"></script>
const gwp = require('<MediaGatewayAddress>/v2/files/gwp');
Ensure the GWP library version matches the Media Gateway version. To retrieve the version:
console.log(gwp.version);
The GWP requires a token to establish secure communication with the Media Gateway. Tokens encapsulate user credentials, permissions, and session validity.
Tokens can be obtained via the Media Gateway's /v2/token/{cameraId}
endpoint.
API Endpoint:
POST /v2/token/{cameraId}
Headers:
Authorization: Basic <Base64(username;sdkCertificate:password)>
Example:
const getTokenFct = async (cameraId) => {
const response = await fetch(`${mediaGatewayEndpoint}/v2/token/${cameraId}`, {
credentials: 'include',
headers: {
'Authorization': `Basic ${btoa(username + ";" + sdkCertificate + ":" + password)}`
}
});
if (!response.ok) {
throw new Error(`Failed to fetch token: ${response.statusText}`);
}
return await response.text();
};
- Do Not Hardcode Credentials: Use server-side logic to fetch tokens securely.
- Token Expiration: Handle token renewal to avoid disconnections.
- Public Streams: For publicly accessible cameras, you can embed tokens directly, though this is not recommended for sensitive streams.
Create a player instance by embedding it in a div
element on your webpage:
const divContainer = document.getElementById('playerContainer');
const webPlayer = gwp.buildPlayer(divContainer);
To connect the player to a camera:
await webPlayer.start(cameraGuid, mediaGatewayEndpoint, getTokenFct);
Parameters:
-
cameraGuid
: The unique identifier of the camera. -
mediaGatewayEndpoint
: The Media Gateway’s public address. -
getTokenFct
: A callback function returning a token.
webPlayer.playLive();
Seek to a Specific Time:
webPlayer.seek(new Date('2023-12-24T10:00:00Z'));
Pause and Resume:
webPlayer.pause();
webPlayer.resume();
Adjust Playback Speed:
webPlayer.setPlaySpeed(2); // Fast-forward at 2x speed
Stop the Stream:
webPlayer.stop();
Dispose the Player:
webPlayer.dispose();
This frees up resources and removes the player from the DOM.
Consider a large retail store using PTZ cameras to monitor different sections. A user can program the PTZ to focus on high-traffic areas during peak hours and adjust manually when suspicious activity is detected:
// Move the camera to monitor entrance
const ptz = webPlayer.ptzControl;
ptz.goToPreset(1); // Preset 1 is configured for the main entrance
// Follow a suspicious individual
ptz.startPanTilt(0.3, -0.2); // Pan right and tilt down
setTimeout(() => ptz.stopPanTilt(), 5000); // Stop after 5 seconds
// Zoom in for a closer look
ptz.startZoom(0.5); // Slowly zoom in
setTimeout(() => ptz.stopZoom(), 3000); // Stop after 3 seconds
A security operator in a corporate setting may want to review past events, such as motion detection in restricted areas:
// Set a timeline range to view activity during the night shift
webPlayer.setTimelineRange(new Date('2023-12-23T22:00:00Z'), new Date('2023-12-24T06:00:00Z'));
// Display bookmarks and motion detection events
webPlayer.onTimelineContentUpdated.register(({ events }) => {
events.forEach(event => {
if (event.kind === 1) { // Bookmark
console.log(`Bookmark: ${event.details} at ${event.time}`);
} else if (event.kind === 0) { // Recording sequence
console.log(`Motion detected: starts at ${event.time} for ${event.duration}s`);
}
});
});
The GWP supports Pan-Tilt-Zoom (PTZ) control for compatible cameras.
const ptz = webPlayer.ptzControl;
ptz.startPanTilt(0.5, 0.3); // Start panning and tilting
ptz.stopPanTilt(); // Stop movement
ptz.startZoom(1); // Zoom in
ptz.stopZoom(); // Stop zooming
ptz.goToPreset(1); // Move to a preset position
The Timeline API allows you to manage and display playback metadata, such as bookmarks and motion events.
Set Timeline Range:
webPlayer.setTimelineRange(new Date('2023-12-24T00:00:00Z'), new Date('2023-12-25T00:00:00Z'));
Handle Timeline Updates:
webPlayer.onTimelineContentUpdated.register(({ events }) => {
console.log('Timeline updated:', events);
});
Enable and control digital zoom:
const zoom = webPlayer.digitalZoomControl;
zoom.goTo(0.5, 0.5, 2); // Zoom to the center at 2x
zoom.zoom(3); // Increase zoom factor
zoom.stop(); // Reset to the full image
Toggle diagnostic overlay for troubleshooting:
webPlayer.showDebugOverlay();
Enable GWP logs:
gwp.enableLogs();
- Audio: Only AAC is supported.
- Reverse Playback: Only smooth for MJPEG streams.
- Digital Zoom and Dewarping: Limited by camera capabilities and configuration.
- CORS: Ensure the Media Gateway is configured to accept the web page’s origin.
- Token Expiration: Tokens must be renewed periodically.
-
Use Logs: Enable GWP logs to gather detailed information:
gwp.enableLogs();
-
Check Network Accessibility: Ensure the Media Gateway is reachable from your network.
-
Validate Configuration: Confirm the Media Gateway role and permissions are properly configured in Security Center.
For detailed support, include the following in your request:
- GWP library version.
- Security Center version.
- Relevant logs or error messages.
Contact the Development Acceleration Program (DAP) at [email protected] for assistance.