ScreenRecorder
ScreenRecorder is a component that records what the user chooses to share: a whole monitor, an application window or a browser tab. It uploads the video to your server. It's built on the browser's Screen Capture API (getDisplayMedia) and MediaRecorder, and it uses the same upload mechanism as the Camera extension.
Typical uses are "record the problem" buttons for support, and capturing a walkthrough of an application.
ScreenRecorder is in the 4.1 source and in the API reference, but it isn't published on NuGet, and parts of it are unfinished. To use it, build Wisej.Web.Ext.ScreenRecorder from source and reference the assembly. Read Known limitations before relying on it.
Requirements
- A secure context: HTTPS, or
http://localhostduring development. - A desktop browser that supports
getDisplayMedia: current Chrome, Edge, Firefox and Safari do. Mobile browsers generally don't support screen capture. - The user's consent. The browser always shows its own picker, where the user chooses what to share, and it can't be bypassed or pre-selected.
Getting started
Drop a ScreenRecorder on the page (it goes to the component tray), or create it in code. When the component is rendered, the browser asks the user what to share. Once the user has shared something, StartRecording and StopRecording record it, and the video arrives in the Uploaded event.
- C#
- VB.NET
using Wisej.Web.Ext.ScreenRecorder;
private void buttonStart_Click(object sender, EventArgs e)
{
this.screenRecorder1.StartRecording("video/webm");
}
private void buttonStop_Click(object sender, EventArgs e)
{
this.screenRecorder1.StopRecording(); // the upload starts now
}
private void screenRecorder1_Uploaded(object sender, UploadedEventArgs e)
{
var file = e.Files[0];
var path = Path.Combine(Application.StartupPath, "recordings", $"{Guid.NewGuid()}.webm");
using (var output = File.Create(path))
file.InputStream.CopyTo(output);
}
Imports Wisej.Web.Ext.ScreenRecorder
Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles ButtonStart.Click
Me.ScreenRecorder1.StartRecording("video/webm")
End Sub
Private Sub ButtonStop_Click(sender As Object, e As EventArgs) Handles ButtonStop.Click
Me.ScreenRecorder1.StopRecording() ' the upload starts now
End Sub
Private Sub ScreenRecorder1_Uploaded(sender As Object, e As UploadedEventArgs) Handles ScreenRecorder1.Uploaded
Dim file = e.Files(0)
Dim path = IO.Path.Combine(Application.StartupPath, "recordings", $"{Guid.NewGuid()}.webm")
Using output = IO.File.Create(path)
file.InputStream.CopyTo(output)
End Using
End Sub
Recording
StartRecording(format, bitsPerSecond, updateInterval) takes:
| Parameter | Default | Meaning |
|---|---|---|
format | "video/webm" | The MIME type passed to MediaRecorder, e.g. "video/webm;codecs=vp9". It must be a format the browser can record. Safari records video/mp4. |
bitsPerSecond | 2500000 | The combined audio and video bit rate. |
updateInterval | 0 | With 0, the recording is uploaded once, on StopRecording(). With a value greater than zero, the data recorded so far is uploaded every that many seconds, and Uploaded fires for each chunk. |
With an updateInterval, only the first chunk contains the video header. The later chunks are continuations, not playable files. Append them to the same file in the order they arrive.
Audio (default false) asks the browser to capture audio along with the screen. Whether audio is actually captured depends on the browser and on what the user shares. Chromium-based browsers can capture a tab's audio, for example, but not always the audio of a whole screen. Changing Audio after the component is rendered asks the user to share again.
GetImageAsync() (or GetImage(callback)) is meant to return the current frame of the shared screen as an Image, or null when no frame is available.
A screen recording can show anything the user has open: other applications, e-mails, passwords being typed. Tell users clearly what's recorded and why, and store and delete recordings according to your privacy policy.
Events
| Event | When |
|---|---|
Uploaded | A recording, or a chunk of one, has been uploaded. The data is in e.Files (UploadedEventArgs). |
Progress | A recording is being uploaded. See the limitations below. |
Error | Setting up or using the recorder fails. e.Message is the browser's message. See the limitations below. |
Known limitations
These are the gaps in the 4.1 source:
ErrorandProgressdon't reach the server. The client raises them, but the component doesn't yet subscribe the server to them. For now, don't rely on either event: detect a failed recording by the absence of anUploadedevent, for example with a timeout.- A refused share is silent. If the user cancels the browser's picker, or the browser blocks it, nothing is reported to the server, and
StartRecordingthen has no stream to record. - The picker opens on render. Firefox and Safari only show the screen-share picker in response to a user action, such as a click. Because the component asks as soon as it's rendered, create or show it from a button click.
- Snapshots.
GetImagesizes its capture canvas from the component's own bounds, and a non-visual component has none, so snapshots may come back empty. To capture an image of your own application, use Html2Canvas instead.
API reference
ScreenRecorder- The whole
Wisej.Web.Ext.ScreenRecordernamespace