package org.red5.server.webapp.oflaDemo; import org.red5.server.adapter.ApplicationAdapter; import org.red5.server.api.IBandwidthConfigure; import org.red5.server.api.IConnection; import org.red5.server.api.IScope; import org.red5.server.api.stream.IServerStream; import org.red5.server.api.stream.IStreamCapableConnection; import org.red5.server.api.stream.support.SimpleConnectionBWConfig; import java.util.Iterator; import org.red5.server.api.service.IServiceCapableConnection; import org.red5.server.api.service.IPendingServiceCall; import org.red5.server.api.service.IPendingServiceCallback; public class Application extends ApplicationAdapter implements IPendingServiceCallback { private IScope appScope; private IServerStream serverStream; /** {@inheritDoc} */ @Override public boolean appStart(IScope app) { appScope = app; return true; } /** {@inheritDoc} */ @Override public boolean appConnect(IConnection conn, Object[] params) { conn.getClient().setAttribute("name",params[0]); // Trigger calling of "onBWDone", required for some FLV players measureBandwidth(conn); if (conn instanceof IStreamCapableConnection) { IStreamCapableConnection streamConn = (IStreamCapableConnection) conn; SimpleConnectionBWConfig bwConfig = new SimpleConnectionBWConfig(); bwConfig.getChannelBandwidth()[IBandwidthConfigure.OVERALL_CHANNEL] = 1024 * 1024; bwConfig.getChannelInitialBurst()[IBandwidthConfigure.OVERALL_CHANNEL] = 128 * 1024; streamConn.setBandwidthConfigure(bwConfig); } return super.appConnect(conn, params); } public void resultReceived(IPendingServiceCall call) { } /** {@inheritDoc} */ @Override public void appDisconnect(IConnection conn) {String name=(String)conn.getClient().getAttribute("name"); Iterator conns3 = appScope.getConnections(); while(conns3.hasNext()) { try{ //to notify clients IConnection conn1=conns3.next(); ((IServiceCapableConnection)conn1).invoke("userClose",new Object[]{name},this); } catch(Exception e){} } if (appScope == conn.getScope() && serverStream != null) {serverStream.close(); } super.appDisconnect(conn); } }