How to create video and voice call to python application?

16,463

Solution 1

There are several aspects involved in building WebRTC application:

  • Serving the web pages and javascript code used by your web clients. You can either use plain static files, or a server-side framework of your choice.

  • Providing a signaling channel which allows participants to exchange information about what media they support (audio, video, data channels) and how they can reach each other. Very often a WebSocket is used for this, but it's not the only possibility.

  • Taking part in the actual WebRTC media exchange. This really depends on your usecase. If you are doing one-to-one audio/video then the WebRTC endpoints are usually web browsers, but they could also be native applications. If you are building something like a voice-over-IP service, then most likely one endpoint is a browser, and the other is a server such as Asterisk or FreeSWITCH.

In the event you actually want your users to communicate with a custom server written in Python (for instance if you are doing audio / video processing using OpenCV) you can take a look at aiortc:

https://github.com/jlaine/aiortc

Solution 2

Sanic is just a web server which will serve HTML and JavaScript. You could also use any web server and it would not matter to WebRTC. Web server has no interaction with WebRTC code in any way.

All WebRTC code that you need for video chat will be in a JavaScript file and that code will be used by your browser (Firefox, Chrome, Opera,...). What you need to do in a server is signaling between peers. For this signaling process you can use socketio in python.

I would recommend you to learn more about WebRTC https://codelabs.developers.google.com/codelabs/webrtc-web/#0

Share:
16,463
Ali Najafi
Author by

Ali Najafi

Updated on June 12, 2022

Comments

  • Ali Najafi
    Ali Najafi almost 2 years

    I want to add video and voice call to my web application developed with python. I searched about it on internet, I found that I can do it with WebRTC, but this work is done with JavaScript, but I don't know how to do this work with python? I'm using Sanic as a web framework in python 3.6.

    On the other hand, is it possible to do this work with socketio in python? I know this module is suitable for chatting apps. I appreciate for your help.

  • Ali Najafi
    Ali Najafi about 6 years
    Thank you so much. I searched a lot and found that I can use WebRTC and I must write a python server for handling requests of clients.
  • Ali Najafi
    Ali Najafi almost 6 years
    thanks a lot. I think its very useful for me and its the same thing that I wanted.
  • Ali Najafi
    Ali Najafi almost 6 years
    Do you know how can I get audio from WebRTC and save it to wave format on the server?
  • Jeremy
    Jeremy almost 6 years
    The server example provided with aiortc now illustrates how to save audio to a WAV file.