user www-data;

worker_processes 1;
events {
    worker_connections  1024;
}

# twily nginx stream configs for use with
# nginx-rtmp-module and/or nginx-srt-module
# (compile with pcre and ssl)

stream {
#    #server {
#    #    listen 1935;
#    #    proxy_pass localhost:1936;
#    #}
#
    server {
        listen 127.0.0.1:6002;
        srt_proxy_pass srt://localhost:6001;
        #proxy_bind $remote_addr transparent;
        #proxy_pass localhost:6001;
        #proxy_protocol on;
        error_log /home/amalie/nginx/logs/srt_error.log debug;
    }
}

# SRT -> TCP proxy
srt {
    server {
        listen 6000;
        proxy_pass tcp://localhost:6002;
        #proxy_protocol on;
        error_log /home/amalie/nginx/logs/srt_error.log debug;
    }
}
# TCP -> SRT proxy
#stream {
#    server {
#        listen 127.0.0.1:6001;
#        srt_proxy_pass srt://localhost:6002;
#    }
#}

#rtmp {
#    server {
#        listen 1935; # Listen on standard RTMP port
#        chunk_size 4000;
#
#        application show {
#            live on;
#            # Turn on HLS
#            hls on;
#            hls_path /mnt/hls/;
#            hls_fragment 3;
#            hls_playlist_length 60;
#            # disable consuming the stream from nginx as rtmp
#            deny play all;
#        }
#    }
#}

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        #allow play 127.0.0.1;
        allow play all;

        application p_12345678 { # main, with record 30sec file
            # name = game mediasoup instream.js
            live on;
            #record off;

            meta copy;
            interleave on;
            wait_key on;

            publish_notify on;
            drop_idle_publisher 10s;
            sync 10ms;

            respawn off;
            play_restart on;
            idle_streams off;

            record all;
            record_path /mnt/rec;
            record_interval 30s;
            #record_unique on; # store full?
            exec_record_done bash -c "sh /home/amalie/analiestar.com/nginx/makethumb.sh $name";

            push rtmp://localhost/$app/$name;

            exec_kill_signal term;

            #exec_push /home/amalie/analiestar.com/nginx_/pushrtmprtp.sh "$app" "$name";

            exec_publish_done /home/amalie/analiestar.com/nginx_/killrtmppush.sh "$app" "$name";
        }

        application p_23456789 { # guest ? no record
            # name = guest mediasoup instream.js
            live on;
            record off;

            meta copy;
            interleave on;
            wait_key on;

            publish_notify on;
            drop_idle_publisher 10s;
            sync 10ms;

            respawn off;
            play_restart on;
            idle_streams off;

            push rtmp://localhost/$app/$name;

            exec_kill_signal term;

            #exec_push /home/amalie/analiestar.com/nginx_/pushrtmprtp.sh "$app" "$name";

            #exec_publish_done /home/amalie/analiestar.com/nginx_/killrtmppush.sh "$app" "$name";
        }
    }
}

