Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
Node.js - Client to Server WebRTC with P2P

After looking to implement WebRTC with a Client to Server model (like Discord), I came to the conclusion that the way to do this is to have 2 clients - the server and client. Audio streams can be overlayed and sent back to the user in 1 single stream.

backend/server.js

const clientPeer = new Peer({ initiator: true, wrtc });
    
clientPeer.on('connect', () => console.log('hi client, this is server'));
clientPeer.on('data', (data) => console.log('got a message from client peer: ', data));

frontend/index.js

serverPeer.on('connect', () => console.log('Connected to server'));
serverPeer.on('stream', async (stream) => {
  const video = document.createElement('audio');

  ('srcObject' in video)
    ? video.srcObject = stream
    : video.src = window.URL.createObjectURL(stream);

  await video.play();
});

How would I implement sending media streams between the client and server?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

A possible solution can be: Create a MediaRecorder object, which can record the media streams on the client-side. This object emits data chunks over time. You can send these chunks via WebSocket to the server. On the server side, you can do what you want with the data chunks. For more details, you can check this https://mux.com/blog/the-state-of-going-live-from-a-browser/.

https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder Another solution can be: Making a node.js application a PEER with WebRTC

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!