webrtc-working-example:在本地和公共网络上测试

  • q1_808451
    了解作者
  • 280.3KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 04:15
    上传日期
WebRTC:一个可行的例子 这是WebRTC技术的简单工作示例,没有不必要的第三方依赖。 它允许2个设备交换音频和视频流。 在Mozilla Firefox 74,Android 5.1和Android 9上进行了测试。 可以在(常规说明和Web应用程序)和(React Native设置和移动应用程序)中找到有关此示例如何工作的完整说明。 依存关系 信令服务器将Python3与aiohttp和python-socketio模块一起使用。 该Web应用程序使用获MIT许可发布的socket.io-client版本2.2.0,可以从下载。 该脚本已添加到此存储库,因此您无需单独下载它或使用npm安装它。 移动应用程序与一起使用。 该存储库仅包含Android配置,但使用iOS对其进行扩展应该并不困难。 设置 Docker撰写 多亏了 ,使用一个命令就可以轻松地启动信令服务器,TURN服
webrtc-working-example-master.zip
内容介绍
# WebRTC: a working example This is a simple working example of WebRTC technology, without unnecessary 3rd party dependencies. It allows 2 devices to exchange audio and video streams. Tested on Mozilla Firefox 74, Android 5.1, and Android 9. Full description of how this example works can be found in [this blog post](https://pfertyk.me/2020/03/webrtc-a-working-example/) (general explanation and web app) and in [this blog post](https://pfertyk.me/2020/04/webrtc-on-mobile-devices/) (React Native setup and mobile app). ## Dependencies The signaling server uses Python3 with `aiohttp` and `python-socketio` modules. The web application uses `socket.io-client` version 2.2.0, released under MIT license, which can be downloaded from [here](https://github.com/socketio/socket.io-client/releases). The script is added to this repository, so you don't have to download it separately or install it with `npm`. The mobile application uses [React Native](https://reactnative.dev/) with [this module](https://github.com/react-native-webrtc/react-native-webrtc). The repository contains only Android configuration, but extending it with iOS should not be difficult. ## Setup ### Docker Compose Thanks to [grebtsew](https://github.com/grebtsew), starting the signaling server, the TURN server, and the web application (all described below) can be easily done with a single command: ``` docker-compose up -d ``` This setup should also work on public servers. ### Signaling server ``` cd signaling pip install -r requirements.txt python server.py ``` This will start a websocket server at `localhost:9999`. ### TURN server You will not need this for localhost testing. However, if you are going to use this example over a public network, then you have to setup your own TURN server on a publicly available IP address. On Ubuntu-based OS it can be done like this: ``` sudo apt install coturn turnserver -a -o -v -n --no-dtls --no-tls -u username:credential -r realmName ``` This will start a TURN server at `{YOUR_SERVER_IP}:3478`. To check if your TURN server setup is correct, you can use [this validator](https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/). To test the example above you should input the following values: * **STUN or TURN URI**: `turn:{YOUR_SERVER_IP}:3478` * **TURN username**: `test` * **TURN password**: `test` Click "Add Server", remove other servers, and select "Gather candidates". If you get a component of type `relay`, that means your setup is working. ### Web application You just need to host the files from `web` directory. Any HTTP server will do, for example: ``` cd web python -m http.server 7000 ``` Then you can access the application in your browser: `localhost:7000`. ### Mobile application You need to setup React Native on your machine by following [these instructions](https://reactnative.dev/docs/environment-setup). WebRTC doesn't work with Expo or emulators, so you will have to run it on a physical phone. Connect the phone to the computer and enable USB debugging. Edit `mobile/src/webrtc-utils.js` file to point to an actual signaling server (and an actual TURN server, if you want to communicate over a non-local network). Then run these commands: ``` cd mobile npm install npx react-native start ``` In a new terminal session (also in the `mobile` directory) run: ``` npx react-native run-android ``` The application should now be installed on your phone. You can test it with another mobile device or with the web application. Press the "Connect" button to start the WebRTC connection.
评论
    相关推荐