k-yle / rtsp-relay

📽 View an RTSP stream in your web browser using an express.js server
https://npm.im/rtsp-relay
MIT License
312 stars 58 forks source link

Issue while getting streams on aws ec2 instance #213

Open sanajavaidraja opened 1 year ago

sanajavaidraja commented 1 year ago

I want to display 2 rtsp camera streams simantaniously on a page .I can successfully streams these camera on my local but unable to get these streams on aws ec2 instance.I also enable 2000 port on aws scurity groups:

here is my react code: import React, { useRef, useEffect } from 'react'; import { loadPlayer } from 'rtsp-relay/browser';

const App = () => { const canvasRefs = useRef([]);

useEffect(() => { const streamUrls = [ 'ws://localhost:2000/api/stream/0', 'ws://localhost:2000/api/stream/1',

];

streamUrls.forEach((url, index) => {
  const playerOptions = {
    url,
    canvas: canvasRefs.current[index],
  };
  loadPlayer(playerOptions);
});

}, []);

const numCanvases = 2; // Set the desired number of canvas elements

// Generate the array of canvas elements const canvases = Array.from({ length: numCanvases }, (_, index) => ( <canvas key={canvas-${index}} id={canvas-${index}} ref={(el) => (canvasRefs.current[index] = el)} style={{ height: '400px', width: '400px', objectFit: 'contain' }}

></canvas>

));

return <div style={{ display: 'flex' }}>{canvases}

; };

export default App;

and here is code in express js: const express = require('express'); const app = express(); const path = require("path");

const { proxy, scriptUrl } = require('rtsp-relay')(app);

const urls = [ "rtsp://adm...", "rtsp://adm...", ];

let i = 0; for (const url of urls) { const handler = proxy({ url: url, verbose: false, transport: 'tcp' });

app.ws('/api/stream/' + i, handler); i++; }

app.use(express.static(path.join(dirname, "client/build"))); app.get('/*', function(req, res) { res.sendFile(path.join(dirname, 'client/build', 'index.html')); });

app.listen(2000, () => { console.log('Express server listening on port 2000'); });

tobitoi commented 11 months ago

make

make sure your ip camera have ip public or vpn to connect to local ip camera