on_connect
The 'on_connect' directive in the NGINX RTMP module allows for specifying a callback function to be executed when a client connects to the streaming server.
Description
The 'on_connect' directive is used in the NGINX RTMP module to define a custom behavior or action that takes place whenever a new client establishes a connection to the RTMP application. This is particularly useful for managing connection states, logging connection details, or implementing any custom authentication mechanisms upon connection. The directive accepts a single argument, which typically is the name of the handler function that will be executed.
When clients connect, NGINX calls the function specified in 'on_connect', allowing developers to extend the functionality of their RTMP applications. The defined function can utilize NGINX's APIs to access information about the connecting client, manipulate streams, and perform necessary actions like checking the client's permissions or sending notifications. It's essential to ensure that the callback function is designed to handle connections efficiently to maintain the performance and responsiveness of the server.
Because this directive operates at the connection level, it is invoked before any streaming session starts, making it suitable for preliminary connection checks. Developers should be aware of potential performance implications if the function involves heavy processing or long-running tasks, as this could block the accepting of new connections.
Config Example
application live {
on_connect my_connect_handler;
}Ensure the callback function is implemented correctly in your NGINX configuration to avoid connection failures.
Be cautious of resource-intensive tasks in the callback function; heavy processing may degrade connection performance.
Always test the handler function thoroughly to avoid unintended behaviors when clients connect.