【nginx-rtmp】04、获取客户端订阅/连接数(Getting number of subscribers)

来源:互联网 发布:淘宝账号销号 编辑:程序博客网 时间:2024/06/13 08:51
这是一个简单的方法来显示流媒体的观看人数,你需要在 location /stat 里设置统计页面(Set up statistics page at location /stat):

location /stat {
    rtmp_stat all;
    allow 127.0.0.1;
}

创建一个简单的 xsl 文件 nclients.xsl ,用来提取流媒体订阅数:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html"/>

<xsl:param name="app"/>
<xsl:param name="name"/>

<xsl:template match="/">
    <xsl:value-of select="count(//application[name=$app]/live/stream[name=$name]/client[not(publishing) and flashver])"/>
</xsl:template>

</xsl:stylesheet>

设置一个location用来返回订阅数:

location /nclients {
    proxy_pass http://127.0.0.1/stat;
    xslt_stylesheet /www/nclients.xsl app='$arg_app' name='$arg_name';
    add_header Refresh "3; $request_uri";
}

使用http请求获取流媒体订阅数:

http://myserver.com/nclients?app=myapp&name=mystream

在浏览器中的上时,会每3秒钟自动刷新!




参考:https://github.com/arut/nginx-rtmp-module/wiki/Getting-number-of-subscribers
原创粉丝点击