const express = require('express');
const expressWs = require('express-ws');
const app = express();
expressWs(app);

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

const port = 8080;
const urlCamera = 'rtsp://admin:admin@dantinjsc.cpplusddns.com:88/cam/realmonitor?channel=1&subtype=0';

app.ws('/api/stream/:cameraIP', (ws, req) =>
  proxy({
    url: `rtsp://${req.params.cameraIP}:554/feed`,
  })(ws),
);

const handler = proxy({
  url: urlCamera,
  verbose: false,
  transport: 'tcp'
});


app.ws('/stream', handler);

const server = app.listen(port, () => {
  console.log(`RTSP Relay Server is listening on port ${port}`);
});

