Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Disconnect stream connection if relay disconnects #1766

Open
daxiachonger opened this issue Jul 22, 2024 · 3 comments
Open

[Question] Disconnect stream connection if relay disconnects #1766

daxiachonger opened this issue Jul 22, 2024 · 3 comments

Comments

@daxiachonger
Copy link

Is there a way to disconnect a stream connection if the relay disconnects? The following is a code snippet. If the push to port 2935 disconnects, I would like to disconnect the stream to port 1935.

rtmp {
  server {
    listen 1936 proxy_protocol;
    application live {
        live on;
        record off;
        push rtmp://localhost:2935;
    }
  }
}

stream {
    proxy_protocol on;
    server {
        listen 1935;
        proxy_pass localhost:1936;
    }
}
@SaltyPretzel303
Copy link

In nginx-rtmp module there is on_publish_done directive using which you can specify the URL at which the HTTP POST request will be sent once the stream is terminated.

rtmp {  
  server {  
    listen 1936 proxy_protocol;  
    application live {  
        live on;  
        record off;  
        push rtmp://localhost:2935;  
        on_publish_done htp://some_valid/url;
    }  
  }  
}

This way you can setup the server (with the adequate rest api) that will interrupt the stream source (the one connected at port 1935) once it receives the request from the on_publish_done directive. The interrupted stream name will be stored under the name key in the form of url encoded arguments.

More info can be found at: https://github.com/JIEgOKOJI/nginx-rtmp/blob/master/directives.md#on_publish_done

@daxiachonger
Copy link
Author

@SaltyPretzel303 Thanks for the response. Unfortunately, the client sends the stream to port 1935, which we cannot interrupt. Is there no way to achieve this using the RTMP directive? I have tried using the HTTP Control module to disconnect, but it doesn't seem to work. Do you know of a way to achieve this by refactoring the code?

@SaltyPretzel303
Copy link

I have never used nginx tcp load balancing directive but from the quick look at the documentation (https://docs.nginx.com/nginx/admin-guide/load-balancer/dynamic-configuration-api/) it seems that the only way may be to remove and then add the rtmp server handling the connection once the on_publish_done is triggered (inside the POST request sent by the on_publish_done you can get the server's ip). This would of course work if one rtmp server is expected to handle only one incoming rtmp stream.
If that doesn't help check out haproxy tcp load balancer, it is free and has a bit better api for server management.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants