title: how to send video stream using webrtc
body: <p>I'm new to <strong>webrtc</strong>,i liked to make simple application where client send video and audio stream to server using webrtc and from server i will use the video frame for detecting object in the video using opencv, i have implemented simple <strong>server side code</strong> using docs of <strong>aiortc</strong> package,but i was stuck,because the <strong>on_track</strong> never called i dont know whats wrong with my code</p>
  <p><strong>Client code</strong></p>
  <pre><code>   const { RTCPeerConnection, RTCSessionDescription } = window;
  socket = io()
  const peerConnection = new RTCPeerConnection()
  const offerAsync = peerConnection.createOffer();
  offerAsync.then(async offer=&gt;{
      await peerConnection.setLocalDescription(new RTCSessionDescription(offer));
      socket.emit(&quot;connect_to_server&quot;, {
        offer
      });
  })
  
      
  socket.on(&quot;connect_to_server_response&quot;,async function(data){
       navigator.mediaDevices.getUserMedia({
           video:true,
           audio:true
       }).then(async stream=&gt;{
           const video = document.getElementById(&quot;video&quot;)
           await peerConnection.setRemoteDescription(
               data
            );
           console.log(data) 
           stream.getTracks().forEach(track =&gt; {
               console.log(&quot;this is track&quot;)
              peerConnection.addTrack(track, stream)
           });  
           console.log(video)
           video.srcObject = stream
           video.play()
       }).catch(err=&gt;{
           console.log(err)
           console.log(&quot;something went wrong please connect administrator, error code = [100]&quot;)
       })
  })    
  
  console.log(&quot;working&quot;);
  </code></pre>
  
  <p><strong>Server code</strong></p>
  <pre><code>async def res(data):
      offer = RTCSessionDescription(sdp=data[&quot;offer&quot;][&quot;sdp&quot;], type=data[&quot;offer&quot;][&quot;type&quot;])
      pc = RTCPeerConnection()
      @pc.on(&quot;track&quot;)
      def on_track(track):
          print(&quot;on Track&quot;)
          print(track.kind)     
      await pc.setRemoteDescription(offer)  
      answer = await pc.createAnswer()
      await pc.setLocalDescription(answer)  
      emit(&quot;connect_to_server_response&quot;, {&quot;sdp&quot;: pc.localDescription.sdp, &quot;type&quot;: pc.localDescription.type})
  
  @socketio.on(&quot;connect_to_server&quot;)
  def connect_to_server(data):
      asyncio.set_event_loop(asyncio.SelectorEventLoop())
      asyncio.get_event_loop().run_until_complete(res(data))
      print(data)
      print(request.sid)
      print(&quot;new user joint&quot;)  
  </code></pre>