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.
- C#
- VB.NET
public class ScreenRecorder : Component, IWisejHandler
Public Class ScreenRecorder
Inherits Component
Implements 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
ScreenRecorder()
Initializes a new instance of the ScreenRecorder class.
ScreenRecorder(container)
Initializes a new instance of the ScreenRecorder class with a specified container.
| Name | Type | Description |
|---|---|---|
| container | IContainer | An IContainer that represents the container of the component. |
Throws:
- ArgumentNullException container is null.
Properties
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
GetImage(callback)
Retrieves the current frame of the captured screen as an Image.
| Parameter | Type | Description |
|---|---|---|
| callback | Action<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:
- ArgumentNullException callback is null.
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;
});
}
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;
}
OnError(e)
Fires the Error event.
| Parameter | Type | Description |
|---|---|---|
| e | RecorderErrorEventArgs | A RecorderErrorEventArgs that contains the event data. |
OnProgress(e)
Fires the Progress event.
| Parameter | Type | Description |
|---|---|---|
| e | UploadProgressEventArgs | A 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.
OnUploaded(e)
Fires the Uploaded event.
| Parameter | Type | Description |
|---|---|---|
| e | UploadedEventArgs | A UploadedEventArgs that contains the event data. |
OnWebEvent(e)
Processes the event from the client.
| Parameter | Type | Description |
|---|---|---|
| e | WisejEventArgs | Event arguments. |
OnWebRender(config)
Renders the client component.
| Parameter | Type | Description |
|---|---|---|
| config | Object | Dynamic configuration object. |
StartRecording(format, bitsPerSecond, updateInterval)
Starts recording the shared screen.
| Parameter | Type | Description |
|---|---|---|
| format | String | The video encoding mime type format, i.e. "video/webm" or "video/webm;codecs=vp9". See MIME_types. |
| bitsPerSecond | Int32 | Audio and video bits per second. See MediaRecorder. |
| updateInterval | Int32 | Update 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"));
}
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
Error
RecorderErrorHandler Fired when an error occurs in the screen recorder setup or usage.
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.
Uploaded
UploadedEventHandler Fired when the current recording is available for download.
Implements
| Name | Description |
|---|---|
| IUserData | |
| IWisejComponent | |
| IWisejHandler | |
| IWisejSerializable |