rtsp-relay icon indicating copy to clipboard operation
rtsp-relay copied to clipboard

Conflict with Socket.IO when using Express

Open tesla-srt opened this issue 4 years ago • 2 comments

So I love this module. Imo better than the other RTSP modules simply because you can route express to the proxy.

However, maybe you could help me out? When I define these variables in a particular order Socket.IO gets bumped out of. web socket on client and all requests are done over XHR except for the RTSP socket.

const app = express();
app.set('view engine', 'ejs')
app.use(express.static('public'))

//initialize socket for the server
const {proxy} = require('rtsp-relay')(app);
const server = app.listen(3001, '0.0.0.0') //initialize socket for the server
const io = socketio(server)


app.ws('/live/:cameraIP/u/:user/p/:pass', async (ws, req) => {
    let uri =`rtsp://${req.params.user}:${req.params.pass}@${req.params.cameraIP}:554/MediaInput/h265/stream_3`
    //let uri = `rtsp://127.0.0.1:8554/`
    proxy({
        url: uri,
        verbose: false,
        //TODO: TEST
        additionalFlags: ['-preset', 'ultrafast', '-b:v', '128k']
    })(ws)
})
.....
io.on('connection', socket => {
.....

tesla-srt avatar Feb 11 '21 17:02 tesla-srt

Hi, SocketIO is different to plain websockets. socket-io is a wrapper around websockets to make it easier to use.

I've never tried using express-ws and socket-io in the same project - perhaps this comment will help

or do you have a simple example where I can reproduce this?

k-yle avatar Feb 12 '21 04:02 k-yle

Would you believe it was a simple solution lol

const app = express();
const streamApp = express();

const {proxy} = require('rtsp-relay')(streamApp);
const server = app.listen(3001, '0.0.0.0') //initialize socket for the server
const io = socketio(server)
const streamServer = streamApp.listen(3002, '0.0.0.0')

streamApp.ws('/live/:cameraIP/u/:user/p/:pass', (ws, req) => {
    let uri = `rtsp://${req.params.user}:${req.params.pass}@${req.params.cameraIP}:554/MediaInput/h265/stream_3`
    //let uri = `rtsp://127.0.0.1:8554/`
    proxy({
        url: uri,
        verbose: false,
        //TODO: TEST
        additionalFlags: ['-preset', 'ultrafast', '-b:v', '128k']
    })(ws)
})

Hope this helps someone out Cheers 👍

tesla-srt avatar Feb 17 '21 04:02 tesla-srt