The issue lies in the transmission of video file data through the peer.js connection.send function

Creating a basic website where multiple users can access a specific dashboard using a unique id. When one user sends a video file, it should start streaming for other users on the same dashboard. I am implementing this functionality using Express.js, socket.io, and peerjs to enable data transfer over the WebRTC stream.

Server-side code:

// Set up the express server
const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server); 
const { v4: uuidV4 } = require('uuid')

// Configure Express.js
app.set('view engine', 'ejs');
app.use(express.static('public'));

// Handle root route
app.get('/', (req, res) => {
  res.redirect(`/${uuidV4()}`)
});

// Handle dashboard route
app.get('/:dashboard', (req, res) => {
  res.render('dashboard', { dashboardId: req.params.dashboard })
})

// Set up Socket.io
io.on('connection', socket => {
  socket.on('join', (dashboardId, userId) => {
    socket.join(dashboardId)
    console.log(userId)
    socket.broadcast.emit('userJoined',{userId:userId})
  })
})

// Start the server
const port = 3000;
server.listen(port, () => {
  console.log(`Server running on port ${port}`);
});

Client-side code:

const socket = io('/');
const peer = new Peer(undefined, {
  host: '/',
  port: '3001'
});

peer.on('open', function (id) {
  const CHUNK_SIZE = 5120; // 5KB
  socket.emit('join', DASHBOARD_ID,id);
  socket.on('userJoined',(userId)=>{
    console.log(userId)
    const conn = peer.connect(userId.userId);
    conn.on('open', function () {
      ...
    });
  })
});
...

The issue is that although the connection with the correct peer is established, the data chunks are not being received by the receiver peer, and the video is not streaming. This problem has been persisting even after thorough debugging efforts. Any assistance in resolving this matter would be highly appreciated.

Answer №1

One effective way to accomplish this task is by incorporating data channels into your webrtc connection. This approach offers a simpler route to achieving your desired outcome.

To begin, establish a webrtc connection and integrate a data channel. Once the connection is active, monitor for the event and commence transmitting file chunks through the data channel. On the receiving end, await the new data channel event and then listen for incoming data chunk events on that particular channel.

The beauty of utilizing data channels is that they operate over the same UDP connection as audio/video rTP but provide reliability. If a chunk is lost during transmission, it will be automatically retransmitted without disrupting the process.

You can observe this concept in action through this interactive demo: . While the example showcases text message exchange, rest assured that you can also transfer various data types such as image files and videos using data blobs.

For a more intricate demonstration, explore this comprehensive example:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Mocha in conjunction with supertest and assert to display the response body when a test fails

In my testing setup for an Express app, I am utilizing mocha, supertest, and assert. The Express app operates in development mode, providing helpful debug information in JSON format when a request fails. To enhance my test suite, I want to display this dat ...

Disabling GPS with HTML5/phonegap: A step-by-step guide

Looking to create a function that can toggle GPS on and off for both iPhone and Android devices ...

Easy way to eliminate empty elements following a class using jQuery

I'm encountering a situation where I have a group of elements following a specific class that are either empty or contain only white space. <div class="post-content"> <div class="slider-1-smart"> --- slider contents --- < ...

Obtain the selected value from a nested radio button group in Angular 2

I am attempting to retrieve the value of each selected radio button from every group that follows in a row. <button ion-button (click)="sample()">Test</button> <ion-list *ngFor="let item of test; let i = index"> <ion-item ...

Issue with Angular Route Guard - Incorrect redirection to login page

I'm encountering an issue with my Angular app where even after the JWT token has expired, I am still able to navigate within the application without any API data being accessible. I've double-checked my setup and it seems right, but for some reas ...

Having trouble interpreting PHP-generated JSON data in JavaScript

I have a PHP script that outputs a JSON string. <?php $arr = array( 'id' => '1', 'myarray' => array( array('a' => 'a1', 'b' => 'b1', 'c' => 'c1', & ...

Enhance React component props for a styled component element using TypeScript

Looking to enhance the properties of a React component in TypeScript to include standard HTML button attributes along with specific React features such as ref. My research suggests that React.HTMLProps is the ideal type for this purpose (since React.HTMLA ...

Guide to Producing an Unorthodox 3D Polygon Extruded Form using React-Three-Fiber

Up until now, I've only utilized useBox statement to create 3D rectangles. Is there a method available to generate something like a wooden piece in dimensions of "two by four" with cut ends at specific angles, akin to the image shown below? https://i ...

What is the best way to access a file within a project folder using JavaScript?

Currently, I am tackling a react project that involves dealing with a video file located in the public folder. In a specific scenario, I need to read this file and then send it over to the server as a file. I attempted the code snippet below but unfortunat ...

Implementing debouncing or throttling for a callback function in React using hooks, allowing for continuous updates without having to wait for the user to finish typing

Using React with Hooks and Formik to create a form that includes a preview of the content, I noticed a performance issue when rendering both elements simultaneously. Even though the form works smoothly by itself, it becomes slow and unresponsive when incor ...

Tips for switching the background image in React while a page is loading?

Is there a way to automatically change the background of a page when it loads, instead of requiring a button click? import img1 from '../images/img1.jpg'; import img2 from '../images/img2.jpg'; import img3 from '../images/img3.jpg& ...

Capture keyboard input using socket.io

My goal is to capture individual keystroke events (keydown and keyup) in a chat client. The current code I have sets up a chat application that sends each message to a mongoDB cluster. However, I want to create a new record for each keystroke event rather ...

Mastering the art of utilizing _.debounce on VueJS data modifications

I'm currently developing a small application using vue.js where I am making some post requests to an API. I have implemented the watch method to monitor changes in the API, updating the component upon successful post requests. However, as the watcher ...

What is the trick to incorporating nested tabs within tabs?

My tabs are functional and working smoothly. To view the jsfiddle, click here - http://jsfiddle.net/K3WVG/ I am looking for a way to add nested tabs within the existing tabs. I would prefer a CSS/HTML solution, but a JavaScript/jQuery method is also acce ...

Remove a row from one table by selecting a cell in a different table

I have a situation where I have two different tables side by side: one with only one column and the other with multiple columns. My goal is to be able to delete a row in the multi-column table by clicking on a cell in the single-column table that correspon ...

Setting a base path in React: A step-by-step guide

I'm facing a challenge with my React app where I need it to function on subdirectories within a URL structure, such as this example: www.mysite.com/reactapp I've attempted redirection, setting a base URL on the router, and including the path in ...

How to activate Yii2 confirmation popup

I have a special ActionColumn on my GridView and I'm attempting to use the yii.confirm function with the data-confirm attribute for the delete action, but the dialog box is not appearing. [ 'format'=>'html', 'content' ...

What could be causing the parameter req.body.param to be undefined in a GET request?

Having an issue where req.body.param is returning undefined, although the body itself contains the desired JSON from the requested source. This issue is causing problems with my iteration as I require access to req.body.data.length or the count of the id ...

Issue with rvest's html_table() function causing it to return -Inf when the maximum value

Recently, I've been working on scraping tables from websites and I'm currently trying to extract a table from . After some research, I found that using the rvest library along with the html_table() function worked best for me. In fact, I successf ...