OliverF / mjpeg-relay

Relays any given MJPEG stream
MIT License
66 stars 23 forks source link

Pushing the websocket data to a server? #18

Closed nicw closed 7 years ago

nicw commented 7 years ago

Hi! The scenario I have is that I need an outgoing connection from this relay to a websockets server, which then isreceiving/relaying/etc.

Your WS example is having the relay act as a client, and users connect to it, which isn't possible in my scenario (firewalls, must be outgoing).

I'm still working through your code, do you see a way that your relay could connect to a WS server and begin sending these messages?

Thanks! Nic

Silex commented 7 years ago

See around https://github.com/OliverF/mjpeg-relay/blob/master/app/broadcaster.py#L161

I believe that by modifying the code a little you'd be able to add a custom client which simply forwards to your websocket server. Or maybe simply connect a local client which forwards to your other server, but maybe there are performances penalties for this.

OliverF commented 7 years ago

I had a similar issue to you a while back so I wrote a quick script to sort of "rewire" the direction connections are made: https://github.com/OliverF/rewire/blob/master/rewire.py

Think of your scenario as wanting to plug a "socket" (not the TCP kind, the physical kind) into another "socket". Since mjpeg-relay accepts connections, and so does your websockets server, you need to "rewire" this. So spin up rewire in the following way (run this on the same machine as mjpeg-relay to avoid firewall issues):

python rewire.py -o localhost:54321 -o YOUR_SERVER:12345

That will make rewire make an outgoing connection to both mjpeg-relay and your server, and then pass data between the two. You can also make some combination of incoming/outgoing sockets with rewire. It's just a simple little script so don't expect too much in the performance department.

Hope it helps!

nicw commented 7 years ago

Hey hey, very cool! Thanks for this, I'll pull it down and play with it. I'd actually stepped back for a few days as I wasn't sure if WS was going to be a viable solution for video streaming. This is rejuvenating :)