on_publish

The `on_publish` directive in the NGINX RTMP module allows you to specify a callback function triggered when a stream is published.

Syntaxon_publish ;
Defaultnone
Context
Arguments1

Description

The on_publish directive is designed to facilitate the execution of actions on an RTMP stream when a user publishes their content to the server. This directive takes a single argument, which specifies the name of the callback function to be executed upon the stream's publication.

When a client publishes a stream to the NGINX server, the server calls the specified callback function, allowing for additional processing, logging, or security checks. This can be particularly useful for enforcing authentication, logging user activity, or triggering other server-side processes based on streams being made live. The context in which this directive is used adds flexibility for server administrators to tailor functionality to specific streaming applications or requirements.

The on_publish directive is especially relevant in live streaming scenarios, where managing stream access and performing actions upon stream initiation is crucial for maintaining an organized and secure streaming environment. If the specified callback encounters an error, the publication may be rejected, which protects the integrity of the streaming service.

Config Example

rtmp {
    server {
        listen 1935;
        application live {
            live on;
            on_publish my_callback;
        }
    }
}

Ensure the specified callback function is correctly defined in the configuration or in the server code; otherwise, the directive will not function as intended.

Be cautious of performance implications if the callback function executes heavy processing during a live stream publication.

← Back to all directives