How to implement a video conferencing application with Electron?

For online education, medical, video conferencing and other scenarios, developing a cross-platform client for Windows and Mac is an essential step. In the past, each operating system application was written in a specific programming language, and each client needed to be developed separately. Now we can use a variety of tools and frameworks for cross-platform development. Electron is one of the most popular.

Electron's predecessor was the Atom Shell, which is based on the Node.js and Chromium open source projects. It allows front-end developers to build cross-platform desktop applications using JavaScript, HTML, and CSS.

Electron is compatible with Mac, Windows and Linux. Applications built with it can run on all three operating systems. We can see it in many famous projects, such as Slack, Cocos Creator, Visual Studio Code and more than 500 projects.

This article will analyze several implementation ideas and advantages and disadvantages of using Electron as a video conferencing application. At the same time, combined with the demo example, share how to develop a video conferencing application based on Electron and the sound network Agora Web SDK.

Several ideas for implementing video conferencing

How to implement a video conferencing application with Electron? This depends mainly on what technology is used to implement the RTC part that is the core of the business.

The first idea is to use the C++ SDK. We can use the NodeJS plugin node-gyp to compile the C++ library into a file that NodeJS can use directly, and the interface part is implemented through the Web. Finally, the RTC business part uses the compiled plugin to directly call the C++ interface.

The advantage of this approach is that it directly calls the C++ interface, which has certain advantages in performance and stability. However, the downside is that the interaction between the Native module and the Web module is relatively complex.

Although NodeJS can directly call C++'s interface, if C++ wants to pass data to the Node part through a callback, you need to ensure that the data is transferred to the thread where Electron is located, and Electron can receive the callback. For example, if the C++ SDK uses dynamic library dependencies with platform differences, you must compile different versions on different platforms during the compilation with node-gyp to work properly in Electron.

The second idea is to use WebRTC, that is, the interface part and the RTC business part are implemented through the Web.

The advantage of this approach is that integration and debugging is very simple, and most of the work can be done directly in the browser and seamlessly ported to Electron.

However, due to the lack of server-side design and deployment solutions for WebRTC, we first need to combine WebRTC with open source projects such as Janus to solve server deployment, NAT penetration and other issues, and implement the RTC part. This is also the difficulty of this implementation method. However, if you implement the RTC part through the Agora Web SDK, you don't need to worry about the above issues, and it is the fastest and easiest way to implement it.

Combined with WebRTC technology, the Agora Web SDK enables multi-party audio and video communication on the web side, enabling rapid development of the RTC part. The audio and video data of WebRTC users are transmitted via Agora.io's SD-RTN real-time cloud, which can ensure the transmission quality of the public network to the greatest extent, combined with WebRTC's own packet loss/drop frame retransmission, bandwidth prediction, and dynamic rate adjustment. Other strategies can achieve a very good multi-party call user experience.

For this integration, we have also provided an open source demo project on Github. Let's take a brief look at how to implement core audio and video calling in the demo.

Audio and video calls based on Agora Web SDK

We need to create a directory called web-app in the Electron environment, where we create basic web parts and quickly implement a video call.

Create an AgoraRTC instance and join the channel:

1let client = AgoraRTC.CreateClient({mode:"interop"})

Initialize the appid and join the channel:

1 client.init(options.key, () => {2 console.log("AgoraRTC client initialized")3 client.join(options.key, options.channel, options.uid, (uid) => {4 console .log("User " + uid + " join channel successfully")5 console.log(new Date().toLocaleTimeString())6 // create localstream7 resolve(uid)8 })9 })

Create a local stream and push:

1let stream = AgoraRTC.creatStream(merge(defaultConfig.config))2localStream.init(() =>{3 client.publish(localStream, err => {4 console.log("Publish local stream error: " + err); 5 localStream.play("element_id")6 })7},

After completing the above steps, you should be able to see your own video screen. Next we will let this part of the code run in Electron's App container.

Create a BrowserWindow instance and read the contents of the web-app directory:

1const electron = require('electron') 2// Module to control application life. 3const app = electron.app 4// Module to create native browser window. 5const BrowserWindow = electron.BrowserWindow 6let mainwindow 7function createWindow () { 8 // Create the browser window. 9mainWindow = new BrowserWindow({width: 800, height: 600})10 // and load the index.html of the app.11 mainWindow.loadURL(url.format({12 pathname: path.join( __dirname, './web-app/dist/index.html'),13 protocol: 'file:',14 slashes: true15 }))16mainWindow.webContents.openDevTools()17//Open the DevTools18//mainWindow.webContents .openDevTools()19//Emitted when the window is closed.20mainWindow.on('closed',function(){21 // Dereference the window object, usually you would store windows22 // in an array if your app supports multi windows , this is the time23 // when you should delete the corresponding element.24 mainWindow = null25})

Once you're done, start the Electron with npm start.

Finally, the demo source code is attached: https://github.com/AgoraIO/Agora-Web-Electron-Demo

Phase Control Stud Thyristor

China Phase Control Stud Thyristor,Stud Version Phase Control Thyristor supplier & manufacturer, offer low price, high quality Dc Power Encapsulation Thyristors,High Power Drives Thyristor Power Control, etc.

The output voltage of thyristor phase-controlled rectifier circuit can be regulated in a large range and has a small fluctuation, which has an impact on the electrical performance of ac power and devices.




Phase Control Stud Thyristor,Stud Version Phase Control Thyristor,Dc Power Encapsulation Thyristors,High Power Drives Thyristor Power Control

YANGZHOU POSITIONING TECH CO., LTD. , https://www.cnfudatech.com