简体   繁体   English

在 Flask 应用程序中嵌入 WebRTC 时没有网络摄像头流

[英]No Webcam stream when embedding WebRTC in Flask app

Environment环境

  • Mac OSX El Capitan Mac OSX El Capitan
  • Chrome Version 48.0.2564.97 (64-bit) Chrome 版本 48.0.2564.97(64 位)

Goal目标

Trying to embed a WebRTC session in my Flask application.试图在我的Flask应用程序中嵌入WebRTC会话。

Added the following in my HTML在我的 HTML 中添加了以下内容

<iframe src="https://appear.in/my_webrtc_session" width="400" height="320" frameborder="1"></iframe>

Issue问题

When I open https://appear.in/my_webrtc_session in my browser, I am getting the video and audio as expected, but when embedding it in the my Flask app, NO video, BUT the Audio works!当我在浏览器中打开https://appear.in/my_webrtc_session时,我得到了预期的视频和音频,但是将它嵌入到我的 Flask 应用程序中时,没有视频,但音频有效!

If I create an HTML with the same code on my computer and open directly in the browser without serving it via Flask, then my session opens the webcam video stream correctly.如果我在我的计算机上使用相同的代码创建一个 HTML 并直接在浏览器中打开而不通过 Flask 提供它,那么我的会话会正确打开网络摄像头视频流。

Any pointers?任何指针?

__init__.py
    sio = socketio.Server()
    app = Flask(__name__)

    @app.route('/')
    def index():
        """Serve the client-side application."""
        return render_template('index.html')

    if __name__ == "__main__"
       app = socketio.Middleware(_sio, _app)
       eventlet.wsgi.server(eventlet.listen(('', 7000)), app)

No video stream when served via Flask通过 Flask 提供时没有视频流

在此处输入图片说明

What I expected我所期待的

在此处输入图片说明

在此处输入图片说明

getUserMedia() no longer works on insecure origins issue fixed BUT still NO VIDEO STREAM getUserMedia() no longer works on insecure origins问题,但仍然没有视频流

Message in the Chrome console Chrome 控制台中的消息

This appears to be Chrome
libs.23ea13d0.js:2 ScreenShareAction: check-extension message: undefined
libs.23ea13d0.js:7 chrome: {"audio":{"optional":[{"sourceId":"default"}]},"video":{"optional":[{"sourceId":"default"},{"minWidth":640},{"maxWidth":640},{"minHeight":480},{"maxHeight":480},{"minMaxFrameRate":25},{"maxMaxFrameRate":25}]}}
libs.23ea13d0.js:8 getUserMedia() no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.
libs.23ea13d0.js:7 chrome: {"audio":{"optional":[{"sourceId":"default"}]}}
libs.23ea13d0.js:7 chrome: {"video":true}
libs.23ea13d0.js:2 Enabling getstats.io for mysession.
libs.23ea13d0.js:2 ChromeNotifierAction: check-extension message: undefined
libs.23ea13d0.js:2 ReferenceError: cxApi is not defined
    at Object.<anonymous> (libs.23ea13d0.js:22)
    at Object.invoke (libs.23ea13d0.js:1)
    at Object.$get (libs.23ea13d0.js:1)
    at Object.invoke (libs.23ea13d0.js:1)
    at libs.23ea13d0.js:1
    at d (libs.23ea13d0.js:1)
    at e (libs.23ea13d0.js:1)
    at Object.invoke (libs.23ea13d0.js:1)
    at Object.$get (libs.23ea13d0.js:1)
    at Object.invoke (libs.23ea13d0.js:1)
libs.23ea13d0.js:2 Chose version -3
libs.23ea13d0.js:2 Loaded flags: {"group":"testimonials","flags":{"testimonials":true}}
libs.23ea13d0.js:2 ChromeNotifierAction: device-credentials message: Object
libs.23ea13d0.js:7 chrome: {"audio":{"optional":[{"sourceId":"default"}]},"video":{"optional":[{"sourceId":"default"},{"minWidth":640},{"maxWidth":640},{"minHeight":480},{"maxHeight":480},{"minMaxFrameRate":25},{"maxMaxFrameRate":25}]}}
libs.23ea13d0.js:2 ChromeNotifierAction: device-credentials message: ObjectdeviceCredentials: Object__proto__: Object
libs.23ea13d0.js:7 chrome: {"audio":{"optional":[{"sourceId":"default"}]}}
libs.23ea13d0.js:7 chrome: {"video":true}
libs.23ea13d0.js:2 Enabling getstats.io for mysession.
qb57:15 'Performance.webkitClearResourceTimings' is deprecated. Please use 'Performance.clearResourceTimings' instead.

在此处输入图片说明

Secure origin安全来源

NOTE: Addresses partly my issue, I still don't get the video stream, BUT getUserMedia() issue was removed.注意:部分解决了我的问题,我仍然没有得到视频流,但是getUserMedia()问题已被删除。

Created self signed certificates following these instruction按照这些说明创建自签名证书

And changed my code as follow:并更改了我的代码如下:

    eventlet.wsgi.server(eventlet.wrap_ssl(eventlet.listen(('', 7000)),
                                       certfile='server.crt',
                                       keyfile='server.key',
                                       server_side=True), app)

Cf.参见wsgi evenlet doc wsgi Evenlet 文档

This removed the getUserMedia() no longer works on insecure origins.这删除了getUserMedia() no longer works on insecure origins. issue and the camera LED on my Mac lights up.问题,Mac 上的摄像头 LED 亮起。 BUT I still don't have a video stream.我仍然没有视频流。

I think the size of iframe might be the problem.我认为 iframe 的大小可能是问题所在。

I've tried your code with size 400x320 .我试过你的代码,大小为400x320 No matter what I do I can not get the video to show up.无论我做什么,我都无法显示视频。 I came to notice that there is this output in the console: {"minWidth":640},{"maxWidth":640},{"minHeight":480},{"maxHeight":480} .我注意到控制台中有这个输出: {"minWidth":640},{"maxWidth":640},{"minHeight":480},{"maxHeight":480} So I changed the iframe size to 640x640 and everything finally works.所以我将 iframe 大小更改为640x640 ,一切终于正常了。

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

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