📜  WebRTC-环境

📅  最后修改于: 2020-10-17 05:38:24             🧑  作者: Mango


在开始构建WebRTC应用程序之前,我们应该设置我们的编码环境。首先,您应该具有文本编辑器或IDE,可以在其中编辑HTML和Javascript。在阅读本教程时,您可能已经选择了首选方法。对于我来说,我正在使用WebStorm IDE。您可以从https://www.jetbrains.com/webstorm/下载其试用版。我还将Linux Mint用作我的首选操作系统。

常见WebRTC应用程序的另一个要求是要有一台服务器来托管HTML和Javascript文件。该代码仅通过双击文件就无法工作,因为除非文件由实际的服务器提供服务,否则不允许浏览器连接到相机和麦克风。显然是由于安全问题而这样做的。

有很多不同的Web服务器,但是在本教程中,我们将使用Node.js和node-static-

  • 访问https://nodejs.org/en/并下载最新的Node.js版本。

  • 将其解压缩到/ usr / local / nodejs目录。

  • 打开/home/YOUR_USERNAME/.profile文件,并将以下行添加到末尾-export PATH = $ PATH:/ usr / local / nodejs / bin

  • 您可以重新启动计算机或运行源/home/YOUR_USERNAME/.profile

  • 现在,可以从命令行使用node命令。 npm命令也可用。 NMP是Node.js的软件包管理器。您可以在https://www.npmjs.com/上了解更多信息。

  • 打开一个终端,然后运行sudo npm install -g node-static 。这将为Node.js安装静态Web服务器。

  • 现在,导航到包含HTML文件的任何目录,并在目录内运行static命令以启动Web服务器。

  • 您可以导航到http:// localhost:8080以查看文件。

还有另一种安装nodejs的方法。只需在终端窗口中运行sudo apt-get install nodejs

要测试Node.js的安装,请打开终端并运行node命令。键入一些命令以检查其工作方式-

打开终端

Node.js运行Javascript文件以及在终端中键入的命令。创建一个具有以下内容的index.js文件-

console.log(“Testing Node.js”);

然后运行节点索引命令。您将看到以下内容-

运行节点终端

在构建我们的信令服务器时,我们将为Node.js使用WebSockets库。要在运行npm中安装,请在终端中安装ws

为了测试我们的信令服务器,我们将使用wscat实用程序。要安装它,请在终端窗口中运行npm install -g wscat

S.No Protocols & Description
1 WebRTC Protocols

WebRTC applications use UDP (User Datagram Protocol) as the transport protocol. Most web applications today are built with the using of the TCP (Transmission Control Protocol)

2 Session Description Protocol

The SDP is an important part of the WebRTC. It is a protocol that is intended to describe media communication sessions.

3 Finding a Route

In order to connect to another user, you should find a clear path around your own network and the other user’s network. But there are chances that the network you are using has several levels of access control to avoid security issues.

4 Stream Control Transmission Protocol

With the peer connection, we have the ability to send quickly video and audio data. The SCTP protocol is used today to send blob data on top of our currently setup peer connection when using the RTCDataChannel object.

概要

在本章中,我们介绍了支持对等连接的几种技术,例如UDP,TCP,STUN,TURN,ICE和SCTP。现在,您应该对SDP的工作原理和用例有一个表面的了解。