iizukanao / node-rtsp-rtmp-server

RTSP/RTMP/HTTP hybrid server
MIT License
1.09k stars 280 forks source link

Authenticate Streams #65

Open jazzy348 opened 7 years ago

jazzy348 commented 7 years ago

Hi,

Can node-rtsp-rtmp-server authenticate livestreams before allowing them? If so, how is this configured?

iizukanao commented 7 years ago

Authentication is not built-in, but it's possible. You need to implement setLivePathConsumer() method in server.coffee. Basically, create a unique URL for each authenticated session in your application code, then call callback null in setLivePathConsumer() if correct URL is requested.

dr1v3 commented 7 years ago

Hi @iizukanao, i need a feature to authenticate stream broadcaster. Lets imagine that we have url like rtsp://example.com/live/coolstream, any user can connect to it and watch the stream, but for the broadcast starting the broadcaster should use url like rtsp://example.com/live/coolstream?stream_key=xxxx. Please give me an advice where should I put some verification function for this parameter.

iizukanao commented 7 years ago

@dr1v3 You can do it by modifying setLivePathConsumer() in server.coffee like the following:

streamServer.setLivePathConsumer (uri, callback) ->
  uriInfo = url.parse uri, true
  if uriInfo.query.stream_key is 'xxxx'
    return callback null  # Accept access
  else
    return callback new Error 'Unauthorized'  # Deny access

The full version is here.