注意:在这个例子中,只要是Http协议的流媒体请求,都将统一进行访问控制。
package com.wowza.wms.example.module;
import com.wowza.wms.httpstreamer.model.IHTTPStreamerSession;
import com.wowza.wms.module.*;
import com.wowza.wms.application.*;
public class ModuleAccessControlHTTPStreaming extends ModuleBase
{
public void onHTTPSessionCreate(IHTTPStreamerSession httpSession)
{
boolean isGood = true;
String ipAddressClient = httpSession.getIpAddress();
String ipAddressServer = httpSession.getServerIp();
String queryStr = httpSession.getQueryStr();
String referrer = httpSession.getReferrer();
String cookieStr = httpSession.getCookieStr();
String userAgent = httpSession.getUserAgent();
IApplicationInstance appInstance = httpSession.getAppInstance();
String streamName = httpSession.getStreamName();
// Here you can use the request and session information above to determine
// if you want to reject the connection
// isGood = true/false;
getLogger().info("ModuleAccessControlHTTPStreaming.onHTTPSessionCreate["+appInstance.getContextStr()+":"+streamName+"]: accept:"+isGood);
if (!isGood)
httpSession.rejectSession();
}
}
使用如何使用Wowza IDE开发Wowza的扩展模块编译上面的代码,将这个模块添加到/conf/[app-name]/Application.xml 文件的模块集合中:
<Module> <Name>ModuleAccessControlHTTPStreaming</Name> <Description>Access control for HTTP streams</Description> <Class>com.wowza.wms.example.module.ModuleAccessControlHTTPStreaming</Class> </Module>
在下面的代码展示了如何使用服务端API对使用Http Live Streaming协议的流媒体请求进行访问控制。
package com.wowza.wms.example.module;
import com.wowza.wms.httpstreamer.cupertinostreaming.httpstreamer.*;
import com.wowza.wms.module.*;
import com.wowza.wms.application.*;
public class ModuleAccessControlCupertinoStreaming extends ModuleBase
{
public void onHTTPCupertinoStreamingSessionCreate(HTTPStreamerSessionCupertino httpCupertinoStreamingSession)
{
boolean isGood = true;
String ipAddressClient = httpCupertinoStreamingSession.getIpAddress();
String ipAddressServer = httpCupertinoStreamingSession.getServerIp();
String queryStr = httpCupertinoStreamingSession.getQueryStr();
String referrer = httpCupertinoStreamingSession.getReferrer();
String cookieStr = httpCupertinoStreamingSession.getCookieStr();
String userAgent = httpCupertinoStreamingSession.getUserAgent();
IApplicationInstance appInstance = httpCupertinoStreamingSession.getAppInstance();
String streamName = httpCupertinoStreamingSession.getStreamName();
// Here you can use the request and session information above to determine
// if you want to reject the connection
// isGood = true/false;
getLogger().info("ModuleAccessControlCupertinoStreaming.onHTTPCupertinoStreamingSessionCreate["+appInstance.getContextStr()+":"+streamName+"]: accept:"+isGood);
if (!isGood)
httpCupertinoStreamingSession.rejectSession();
}
}
<Module> <Name>ModuleAccessControlCupertinoStreaming</Name> <Description>ModuleAccessControlCupertinoStreaming</Description> <Class>com.wowza.wms.example.module.ModuleAccessControlCupertinoStreaming</Class> </Module>
