Giter Site home page Giter Site logo

swipswaps / video_streaming_on_web Goto Github PK

View Code? Open in Web Editor NEW

This project forked from supertigim/video_streaming_on_web

0.0 0.0 0.0 1.32 MB

Web Cam Video Streaming using aiohttp, aiortc, OpenCV, WebRTC, React and etc

HTML 15.68% JavaScript 37.43% Python 35.93% CSS 8.77% Shell 2.19%

video_streaming_on_web's Introduction

Introduction

This project shows how to do video streaming on web epecially using WebRTC with ReactJS.

Note: Only run and tested on Ubuntu 18.04.

Browser Test

[Supported]

  • Chrome on Ubuntu(Linux), macOS, and Windows
  • Firefox on Ubuntu(Linux)
  • Safari on macOS and iOS (iPhone, iPad, etc)

[Not supported]

  • Microsoft Edge
  • Internet Explorer
  • Chrome on iOS (iPhone, iPad , etc)

Environment

For python 3,

    # for aiortc 
    $ apt install libavdevice-dev libavfilter-dev libopus-dev libvpx-dev pkg-config
    $
    # Aussme that anaconda or miniconda is already installed
    $ conda create -n vs python=3.7
    $ conda activate vs
    (vs)$ pip install aiohttp aiortc opencv-python 

For node.js,

    $ sudo apt-get install curl  
    $ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -  
    $ sudo apt-get install nodejs

For SSL on iOS, please read this site first and make sure that Websocket on iOS really depends on SSL.

    # assume that your IP address is 192.168.1.50
    $ cd cert
    cert$ openssl genrsa -out server.key 2048
    cert$ openssl req -new -x509 -sha256 -key server.key -out server.crt -days 365 -subj /CN=192.168.1.50
    # if you see the error about .rnd, go to trouble shooting section 
    cert$
    cert$ sudo npm install budo
    cert$ budo --ssl --cert=./server.crt --key=./server.key
  • Visit https://192.168.1.50:9966/
  • View and export the certificate as server.key <== the same name above
  • Update ./cert/server.pem with ./cert/server.key and ./cert/server.crt
    cert$ copy server.key server.share.pem 
  • Email server.share.pem as an attachment to yourself
  • Open the mail on iPhone and click the certificate to download
  • Go to Settings -> Download Profile --> Install and verify it
  • Go to Settings -> General -> About -> Certificate Trust Settings --> Turn it On

Do NOT forget to update the followin files

  • line 6 in ./react-webrct-app/src/components/const.js

STUN server

Bascially, you can use any of public STUN servers on the internet like stun.l.google.com:19302 or you don't need it in this project. However, you might consider running your own STUN in case like you test it on a Firefox browser without internet. Here's how to run your own STUN server.

    $ sudo apt-get install coturn  
    $ sudo /etc/turnserver.conf /etc/turnserver.conf.old  
    $ sudo copy ./data/turnserver.conf /etc/turnserver.conf   
    $ sudo turnserver  

    # Put your own stun server IP address in ./webrtc/index.js and ./webrtc/view.js

If you want to set SSL, then...

    $ sudo mkdir /var/local/cert  
    $ sudo copy ./cert/stun-* /var/local/cert  

    # Uncomment line 14, 15 in turnserver.conf  

Do NOT forget to update the followin files

  • line 19 in ./webrtc/index.js
  • line 19 in ./webrtc/view.js
  • line 2 in ./react-webrct-app/src/components/ReactRTC/functions/constants.js

How to Run

For aiohttp/aiortc server,

    $ conda activate vs 
    (vs) $ cd webrtc  
    (vs) webrtc$ python server.py --cert-file ../cert/server.crt --key-file ../cert/server.key

For react app,

    # Modify wss://IP-address:4000/ws with your server IP
    $
    $ cd react-webrtc-app
    react-webrtc-app$ npm install
    react-webrtc-app$ npm start 

How to use

You need to put an exact IP address on a browswer because localhost or 127.0.0.1 don't work with the certificate which is created by the IP address of your machine.

  • Navigate to https://your_IP_address:4000/

    • Check the below options

      • Use datachannel
      • Use video
      • Use audio (if required)
    • Click Start to start process.

    • Once the video is successfully getting processed, proceed to view

    • On another system(or browser) navigate to https://[your_IP_address]:4000/view

    • Click on start button

  • Navigate to https://your_IP_address:3000/

    • Click the button to connect to the cam

[Reference - One on One Test using ReactRTC Module]

  • Open a new browser and navigate to 'https://your_IP_address:3000/one_on_one'

    • Click the green button next to 'Share Screen'
    • Enter a room key in the text box and click 'submit'
  • Open another new browser and navigate to 'https://your_IP_address:3000/one_on_one'

    • Click the green button next to 'Share Screen'
    • Enter the same room key in the text box and click 'submit'

Trouble Shooting

(1) If you encounter a problem when you install aiortc on Ubuntu 18.04,

    conda install av -c conda-forge  

(2) It seems like Safari is the only browser that doesn't accept a self-signed untrusted certificate for secure WebSockets.

  • Make sure you're using SHA256 generating the self-signed key
  • Make sure your CommonName is set to the same host (i.e. IP) you are running โ€” you can use the command -subj /CN=192.168.1.54
  • You need to send the .cer file to your phone and manually Install/Trust it (which adds it to General > Profiles)
  • You can find the details in here

(3) can not find ~/your_home/.rnd

    openssl rand -out /home/your_home/.rnd -hex 256

(4) How to test websocket

    curl https://127.0.0.1:4000/ws -v -H "Connection: Upgrade" -H "Upgrade: WebSocket"

Reference

video_streaming_on_web's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.