简体   繁体   English

webrtc-使用php或node.js的信令服务器

[英]webrtc - signaling server with php or node.js

I'm trying to build a simple video streaming web application where one user (chatroom owner) broadcasts video from his webcam and the other users (chatroom members) are able to see it in real time 我正在尝试构建一个简单的视频流Web应用程序,其中一个用户(聊天室所有者)从他的网络摄像头广播视频,而其他用户(聊天室成员)则可以实时观看视频

i have done tons of researches on google so i found out that what i need is : 我已经在Google上进行了大量研究,所以发现我需要的是:

- get the adapter.js file for compatibility ( no clue where to get it ) -获取adapter.js文件的兼容性(不知道从何处获取)

- get video stream from the webcam -从网络摄像头获取视频流

- send it to a server -将其发送到服务器

- have the server send it to certain users -让服务器将其发送给某些用户

- clients receive that video stream and displays it inside a < video > tag -客户端接收该视频流并将其显示在<video>标签内

i was only able to do the first step, the examples i found on the web are clear and simple 我只能执行第一步,我在网上找到的示例清晰明了

for the other steps, all examples i found on the web explains how to do this locally on a single page but i want to do it remotly, even followed the guides in O'reilly WebRTC book 对于其他步骤,我在网络上找到的所有示例都在单个页面上解释了如何在本地进行此操作,但是我想远程执行此操作,甚至遵循O'reilly WebRTC书中的指南进行操作。

i have no clue what i should write in the server side code or how to send the received video stream ( i have some examples but i didn't understand the code ) 我不知道我应该在服务器端代码中写些什么或如何发送接收到的视频流(我有一些示例,但我不理解该代码)

i have no clue how the clients will receive that stream ( no examples found for this one, all examples out there send and receive video on the same page ) 我不知道客户端将如何接收该流(此示例未找到任何示例,所有示例都在同一页面上发送和接收视频)

can anyone help, my server side langages is PHP but i can switch to Node.js if that's a must 谁能帮忙,我的服务器端语言是PHP,但是如果必须的话,我可以切换到Node.js

Am answering your questions inline 正在在线回答您的问题

  1. You can get adapter.js file from https://github.com/webrtc/adapter/tree/master/release 您可以从https://github.com/webrtc/adapter/tree/master/release获取adapter.js文件
  2. To get video stream from the webcam, use getUserMedia API , see the demo 要从网络摄像头获取视频流,请使用getUserMedia API ,请参见演示

  3. To Stream video to viewers, use PeerConnection , 要将视频流传输给观看者,请使用PeerConnection

    • WebRTC has no specific signalling defined, you can use any signalling to exchange offer/answer/candidates between publisher and viewer using any server(node/php) in p2p. WebRTC没有定义任何特定的信号,您可以使用任何信号在p2p中使用任何服务器(节点/ php)在发布者和查看者之间交换报价/答案/候选人。 See official complex demo and get the source . 查看官方综合演示并获取源代码

    • If you want to stream to multiple viewers, then you need a media server , see demos Janus & Jitsi 如果要流式传输到多个查看器,则需要媒体服务器 ,请参阅演示JanusJitsi

You can find more resources here 您可以在此处找到更多资源

So, it seems you ask for help and you have tons of questions. 因此,您似乎寻求帮助,并且有很多问题。

Regarding local or remotely: there is no difference whether it only works on your computer or at a server. 关于本地还是远程:它仅适用于您的计算机还是服务器都没有区别。 Usually you test things locally on your computer, and then you put it online. 通常,您在计算机上本地测试事物,然后将其联机。 You usually do not need to change your code (except settings like URLs) to get it working on a server. 通常,您无需更改代码(URL等设置除外)即可在服务器上使用它。

You say you have no idea what you should write at the server code. 您说您不知道应该在服务器代码中写什么。 Well, it is just for signalling, so any two browsers should be able to communicate. 好吧,这只是为了发出信号,因此任何两个浏览器都应该能够通信。 Usually it is done with websockets and coded with less than 10 lines of code for node.js; 通常,它是通过websocket完成的,并使用少于10行的node.js代码进行编码; there are plenty of small examples of that, like here . 有很多这样的小例子,例如这里 You say your main server language is PHP; 您说您的主要服务器语言是PHP; that is challenging because PHP can not use websockets without commandline access. 这具有挑战性,因为没有命令行访问权限,PHP无法使用websocket。 If you have regular shared-hosted PHP access, you can use my example at http://github.com/nielsbaloe/webrtc-php which uses ServerSideEvents. 如果您具有常规的共享托管PHP访问,则可以在http://github.com/nielsbaloe/webrtc-php上使用我的示例,该示例使用ServerSideEvents。

You want to know how clients will receive the stream. 您想知道客户端将如何接收流。 Well, the browser takes care of the streams. 好吧,浏览器会处理流。 You only have to take care of the handshakes. 您只需要照顾握手。 So when you have code for two browsers running (like in my example), it is exactly the same code for more clients, you can extend it so that there is one sender and multiple viewers. 因此,当您有两个运行的浏览器的代码(例如在我的示例中)时,对于更多客户端来说,它是完全相同的代码,则可以对其进行扩展,以便有一个发送者和多个查看者。

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

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