c# windows forms rtc code example

Example 1: c# windows forms rtc

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

// Load cefsharp
using CefSharp;
using CefSharp.WinForms;

namespace CefsharpExample
{
    public partial class Form1 : Form
    {
        public ChromiumWebBrowser chromeBrowser;

        public void InitializeChromium()
        {
            CefSettings settings = new CefSettings();

            // Initialize cef with a command line argument
            // In this case the enable-media-stream flag that allows you to access the camera and the microphone
            settings.CefCommandLineArgs.Add("enable-media-stream", "1");

            Cef.Initialize(settings);

            // Create a browser component
            // In this example we are opening a website that allows you to take pictures with the camera online
            chromeBrowser = new ChromiumWebBrowser("https://webcamtoy.com");
            // Or if you want to test the microphone level instead
            // chromeBrowser = new ChromiumWebBrowser("https://webaudiodemos.appspot.com/volume-meter/");

            // Add the cef control to the form and fill it to the form window.
            this.Controls.Add(chromeBrowser);
            chromeBrowser.Dock = DockStyle.Fill;
        }

        public Form1()
        {
            InitializeComponent();

            // Start cefsharp
            InitializeChromium();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            Cef.Shutdown();
        }
    }
}

Example 2: c# windows forms rtc

CefSettings settings = new CefSettings();

// Add the --enable-media-stream flag
settings.CefCommandLineArgs.Add("enable-media-stream", "1");

Cef.Initialize(settings);