介绍
aiortc是用Python实现的WebRTC库。它是在不使用本机库libwebrtc的情况下创建的。我尝试使用Docker运行此示例。
环境
- 主机操作系统:Mac OS X 10.12.6(Sierra)
- Docker:适用于Mac的Docker版本17.06.0-ce-mac18(18433)
- 容器基础:Ubuntu 18.04 LTS
Ubuntu 18.04 LTS已发布,因此这次我以它为基础。
Docker文件
使用的Dockerfile在这里。
- python3
- libopus-dev,libvpx-dev
- libffi-dev,libssl-dev
- libopencv-dev(添加2018.07.03)
等已安装。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | # Ubuntu 18.04 and aiortc # aiortc: https://github.com/jlaine/aiortc FROM ubuntu:18.04 MAINTAINER mganeko # # -- if you are using docker behind proxy, please set ENV -- # #ENV http_proxy "http://proxy.yourdomain.com:8080/" #ENV https_proxy "http://proxy.yourdomain.com:8080/" # # -- set ENV for non-interactive # ENV DEBIAN_FRONTEND=noninteractive # -- build step -- RUN apt update RUN apt upgrade -y RUN apt install python3 -y RUN apt install python3-pip -y RUN apt install python3-dev -y RUN python3 -V RUN pip3 -V RUN pip3 install --upgrade pip RUN pip -V RUN apt install libopus-dev -y RUN apt install libvpx-dev -y RUN apt install libffi-dev -y RUN apt install libssl-dev -y RUN apt install libopencv-dev -y RUN apt install git -y RUN mkdir /root/work WORKDIR /root/work/ RUN git clone https://github.com/jlaine/aiortc.git RUN pip install aiohttp RUN pip install aiortc RUN pip install opencv-python # --- for running -- EXPOSE 8080 WORKDIR /root/work/aiortc/examples/server/ CMD [ "python3", "server.py" ] |
*在指出其不适用于最新版本(2018.07.03)后更正
建立程序
从终端运行docker build(请提供适当的映像名称)
1 | $ docker build -t mganeko/ubuntu18_aiortc -f Dockerfile . |
执行程序
(1)使用docker run从终端
启动容器
1 | $ docker run -d -p 8001:8080 mganeko/ubuntu18_aiortc |
- 在此示例中,主机OS的端口8001连接到容器的端口8080。
- 在容器内,我们正在运行aiortc / examples / server / server.py。
(2)使用Chrome
访问http://本地主机:8001 /
- Firefox,Safari无法使用服务器返回的错误
(3)选中[使用视频],然后单击[开始]按钮
如果一切顺利,则应如下所示:
-
相机的图像和所选图像效果的图像在"媒体"列中交替显示。
- 轮廓检测
- 回转
- 深绿色固体
- 无影响(相机图像仍然存在)
- 数据通道列显示ping / pong如何与服务器交换数据。
综上所述
aiortc是一个独特的项目,使用Python独立地实现WebRTC。通过使用Docker,我能够轻松地尝试它。
我还没有阅读过源代码,但是我希望一点一点地看一下它。