Skip to main content

ScreenRecorder

Namespace: Wisej.Web.Ext.ScreenRecorder

Assembly: Wisej.Web.Ext.ScreenRecorder (4.1.0.0)

Records the user's screen (a monitor, window or browser tab chosen by the user) and uploads the recording to the server.

public class ScreenRecorder : Component, IWisejHandler

The component uses the browser's getDisplayMedia() API: the browser asks the user which screen to share when the component is rendered on the client. Call StartRecording and StopRecording to record the shared screen with a MediaRecorder; the recorded video is posted back to the component and delivered through the Uploaded event.

Screen capture requires a secure context (HTTPS or localhost) and a browser that supports the Screen Capture API.

Constructors​

Instance member ScreenRecorder()​

Initializes a new instance of the ScreenRecorder class.

Instance member ScreenRecorder(container)​

Initializes a new instance of the ScreenRecorder class with a specified container.

NameTypeDescription
containerIContainerAn IContainer that represents the container of the component.

Throws:

Properties​

Instance member Audio​

Boolean: Returns or sets whether audio should be recorded together with the screen. (Default: False)

The value is passed as the audio constraint to getDisplayMedia(). Changing it after the component is rendered requests the screen capture again, and the browser prompts the user again. Whether audio is actually captured depends on the browser and on the source selected by the user.

Methods​

Instance member GetImage(callback)​

Retrieves the current frame of the captured screen as an Image.

ParameterTypeDescription
callbackAction<Image>Callback method that receives the Image, or null when the image is not available.

The image is captured asynchronously on the client and callback is invoked when the image is received.

Throws:

Example:

Taking a snapshot of the shared screen:

private void buttonSnapshot_Click(object sender, EventArgs e)
{
this.screenRecorder1.GetImage(image =>
{
if (image != null)
this.pictureBox1.Image = image;
});
}

Instance member GetImageAsync()​

Asynchronously retrieves the current frame of the captured screen as an Image.

Returns: Task<Image>. An awaitable Task that contains the Image, or null when the image is not available.

Example:

Taking a snapshot of the shared screen using await:

private async void buttonSnapshot_Click(object sender, EventArgs e)
{
var image = await this.screenRecorder1.GetImageAsync();
if (image != null)
this.pictureBox1.Image = image;
}

Protected member OnError(e)​

Fires the Error event.

ParameterTypeDescription
eRecorderErrorEventArgsA RecorderErrorEventArgs that contains the event data.

Protected member OnProgress(e)​

Fires the Progress event.

ParameterTypeDescription
eUploadProgressEventArgsA UploadProgressEventArgs that contains the event data.

This event fires only if there is an handler attached to it. A simple overload of the On[Event] method in a derived class will not be invoked unless there is at least one handler attached to the event.

Protected member OnUploaded(e)​

Fires the Uploaded event.

ParameterTypeDescription
eUploadedEventArgsA UploadedEventArgs that contains the event data.

Protected member OnWebEvent(e)​

Processes the event from the client.

ParameterTypeDescription
eWisejEventArgsEvent arguments.

Protected member OnWebRender(config)​

Renders the client component.

ParameterTypeDescription
configObjectDynamic configuration object.

Instance member StartRecording(format, bitsPerSecond, updateInterval)​

Starts recording the shared screen.

ParameterTypeDescription
format optionalStringThe video encoding mime type format, i.e. "video/webm" or "video/webm;codecs=vp9". See MIME_types.
bitsPerSecond optionalInt32Audio and video bits per second. See MediaRecorder.
updateInterval optionalInt32Update interval in seconds. The default is zero causing the video to be uploaded on StopRecording.

You must call StopRecording to end recording. The user must have already shared a screen, otherwise the recording doesn't start and an error is reported on the client.

When updateInterval is greater than zero, the data recorded so far is uploaded every updateInterval seconds and the Uploaded event is fired for each chunk; only the first chunk contains the video header.

Example:

Starting and stopping the recording:

private void buttonStart_Click(object sender, EventArgs e)
{
this.screenRecorder1.StartRecording("video/webm", 4000000);
}

private void buttonStop_Click(object sender, EventArgs e)
{
this.screenRecorder1.StopRecording();
}

private void screenRecorder1_Uploaded(object sender, UploadedEventArgs e)
{
var file = e.Files[0];
file.SaveAs(Path.Combine(Application.StartupPath, "Recordings", $"{DateTime.Now:yyyyMMdd-HHmmss}.webm"));
}

Instance member StopRecording()​

Stops recording and uploads the recorded stream to the Uploaded event.

The upload is asynchronous: the Uploaded event is fired when the browser has finished posting the recording. Calling this method when there is no active recording reports an error on the client.

Example:

Stopping the recording:

private void buttonStop_Click(object sender, EventArgs e)
{
this.screenRecorder1.StopRecording();
}

Events​

Instance member Error​

RecorderErrorHandler Fired when an error occurs in the screen recorder setup or usage.

Instance member Progress​

UploadProgressEventHandler Fired while the ScreenRecorder control receives the recording stream being uploaded.

This event fires only if there is an handler attached to it. A simple overload of the On[Event] method in a derived class will not be invoked unless there is at least one handler attached to the event.

Instance member Uploaded​

UploadedEventHandler Fired when the current recording is available for download.

Implements​