简体   繁体   English

没有任何服务器的WebRTC甚至不可能成为信令服务器吗?

[英]Is WebRTC without any server not even a signaling server possible?

I'm trying to setup an a cordova plugin for iOS which implements the webrtc functions without using any server and it will only be used on a local network . 我正在尝试为iOS设置cordova插件,该插件可在不使用任何服务器的情况下实现webrtc功能,并且只能在本地网络上使用 I know there is this plugin , which looks promising but i have some problems with it. 我知道有这个插件 ,看起来很有希望,但是我有一些问题。 My plan is not to use a TRUN, STUN or any kind of signaling server. 我的计划是不使用TRUN,STUN或任何类型的信令服务器。

Maybe you think right now: " Ok this is not possible. No signaling equals no connection. " But let me explain first. 也许您现在就在想:“ 好吧,这不可能。没有信号就等于没有连接。 ”但是让我先解释一下。 As pointed out here and here it's possible to avoid using a TRUN, STUN or ICE server. 如此此处所指出的,可以避免使用TRUN,STUN或ICE服务器。 I think this is a good way to start my project but there is still an open question. 我认为这是启动我的项目的好方法,但仍然存在一个未解决的问题。 How shall the devices find each other if there isn't any kind signaling (in the example they use a Node.js server)? 如果没有任何类型的信号(在本示例中,它们使用Node.js服务器),设备将如何彼此找到对方? Right now i'm playing with the idea of an QR-Code which contains all the necessary information. 现在,我正在考虑包含所有必要信息的QR码的想法。

At the end it should look like this (black arrwos are more important): 最后,它应该看起来像这样(黑色arrwos更重要): 规划网络

The idea is that everyone who comes into a room has to scan a QR-Code on the RP and then the device knows the IP, port, etc. of the RP and a WebRTC connection with a DataChannel will be established. 这个想法是,进入房间的每个人都必须扫描RP上的QR码,然后设备知道RP的IP,端口等,并且将建立与DataChannel的WebRTC连接。

I've been looking for an answer for days now, but due to the fact (or at least one of the reasons) that WebRTC is not even supported on iOS nativly there aren't many WebRTC examples out there which work on iOS and no one for a local network. 我一直在寻找答案的几天,但是由于(或至少出于某种原因)iOS甚至不支持WebRTC的事实(实际上),没有太多在iOS上可用的WebRTC示例,并且没有一个用于本地网络。

So my question is: Am I on the right way or is this not even possible? 所以我的问题是:我走对了路还是不可能? (I found no example for this anywhere, but if I put all the posts I read together, I think it should be possible.) (我在任何地方都没有找到关于此的示例,但是如果我将所有阅读的文章放在一起,我认为应该是可能的。)

First of all, TURN and STUN are not signaling server. 首先,TURN和STUN不是信令服务器。 Signaling server is the term normally associated with the backend server that let's you relay the messages between two peers before the connection is established. 信令服务器是通常与后端服务器关联的术语,让您建立连接之前在两个对等方之间中继消息。 The signaling server is thus used to establish the connection. 因此,信令服务器用于建立连接。 Once the connection is established, there is no role of the signaling server in the communication, unless you intend to make any changes to the connection parameters. 建立连接后,除非打算对连接参数进行任何更改,否则信令服务器在通信中将不再起作用。

TURN and STUN servers, on the other hand, are used during the connection establishment process. 另一方面,在建立连接的过程中使用TURN和STUN服务器。 It helps the two peers find a direct path to each other. 它可以帮助两个对等方找到彼此的直接路径。 So when the connection is established, the peers can talk directly with each other and they don't require the signaling server to relay the messages anymore. 因此,建立连接后,对等方可以直接相互交谈 ,并且不需要信令服务器再中继消息。

Now coming to your question, short answer is, no, your plan is incomplete. 现在问您的问题,简短的答案是, 不,您的计划不完整。

Here are some changes that you'd need in order to make it work: 为了使它起作用,您需要进行一些更改:

  1. QR Code is not adequate to convey all required information. QR码不足以传达所有必需的信息。 According to this answer , they can store roughly 4kb of maximum data. 根据此答案 ,他们可以存储大约4kb的最大数据。 Thus it is not sufficient to pass all candidates. 因此,仅通过所有候选人是不够的。

    Not to mention that WebRTC requires both devices to share the candidates. 更不用说WebRTC要求两个设备共享候选者。 So, you'd need a display and QR code scanner on the Raspberry PI. 因此,您需要在Raspberry PI上使用显示器和QR码扫描仪。

    You might want to explore alternatives such as Wifi to allow for two-way data sharing between the device and Raspberry Pi. 您可能想探索诸如Wifi之类的替代方法,以实现设备与Raspberry Pi之间的双向数据共享。 Once setup, the Wifi connection will act as the Signaling server. 设置完成后,Wifi连接将充当信令服务器。

    Though I am not well versed in iOS or Raspberry Pi. 虽然我不太了解iOS或Raspberry Pi。 So I would recommend that you ask a separate question about the choice of communication channel if you are unsure about what to choose. 因此,如果您不确定该选择什么,我建议您再问一个有关通信渠道选择的问题。 Keep in mind that you need Raspberry Pi to be able to communicate with the device for a short period of time in order to allow WebRTC connection to be established. 请记住,您需要Raspberry Pi能够在短时间内与设备通信,以便建立WebRTC连接。

  2. Coming to STUN and TURN servers, you may be able to get away without using them. 来到STUN和TURN服务器,您可能可以不使用它们而逃脱。 I have seen a few cases when my app is able to establish connection to peers within the local network without STUN and TURN servers. 我已经看到了几种情况,当我的应用程序无需STUN和TURN服务器即可建立与本地网络中同级的连接。

    However, I would strongly recommend that you use at least a STUN server. 但是,我强烈建议您至少使用一个STUN服务器。 They are often available for free of charge. 它们通常是免费提供的。 Google and Firefox also provide their own STUN servers that you can use in any of your WebRTC apps. Google和Firefox还提供了自己的STUN服务器,您可以在任何WebRTC应用程序中使用它们。 You can search on internet to get their details. 您可以在互联网上搜索以获取其详细信息。

    TURN servers are required only when the two peers are behind NAT's. 仅当两个对等方位于NAT之后时才需要TURN服务器。 In such cases STUN servers are sometimes incapable of finding a direct route between them, and you need the TURN server to relay the audio/video/message stream. 在这种情况下,STUN服务器有时无法在它们之间找到直接路由,因此您需要TURN服务器来中继音频/视频/消息流。

  3. Your plan to establish the WebRTC channel between Raspberry Pi and the phones (the black arrows) seem fine to me. 您在Raspberry Pi和电话之间建立WebRTC通道的计划(黑色箭头)对我来说似乎不错。 It would help you establish further connections between two phones whenever required. 它将在需要时帮助您在两部电话之间建立进一步的连接。

    However, if you eventually decide to implement something like Wifi on your Raspberry Pi, the WebRTC connection may be redundant. 但是,如果您最终决定在Raspberry Pi上实现Wifi之类的功能,则WebRTC连接可能是多余的。 After all, you could use Wifi to pass the data back and forth, and don't really need an additional layer of WebRTC channel to do that. 毕竟,您可以使用Wifi来回传递数据,而实际上并不需要额外的WebRTC通道层。

Since you run your app on a local network you don't need STUN and TURN servers. 由于您在本地网络上运行应用程序,因此不需要STUN和TURN服务器。 But still you need a signaling server. 但是仍然需要一个信令服务器。 Signaling can't be done with QR-codes, read more about WebRTC and you will understand why. 无法使用QR码发出信号,请阅读有关WebRTC的更多信息,您将了解原因。

But a signaling server can be very simple. 但是信令服务器可能非常简单。 Since you have that raspberry pi in your local network, you can use this as your signaling server. 由于您的本地网络中有树莓派,因此可以将其用作信令服务器。 Just install node, express and socket.io on it. 只需在其上安装node,express和socket.io。 You need only one simple javascript file, mine is only 23 lines of code. 您只需要一个简单的javascript文件,我的只有23行代码。 Stop wasting your time with QR-codes and you will have your signaling server up and running in no time. 不要再浪费QR码浪费时间了,您的信令服务器将立即启动并运行。 You can look at Google Codelab for an example. 您可以查看Google Codelab的示例。 Hopes this helps you !! 希望这对您有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM