Class BaseRTMPClientHandler

java.lang.Object
org.red5.server.net.rtmp.BaseRTMPHandler
org.red5.client.net.rtmp.BaseRTMPClientHandler
All Implemented Interfaces:
IRTMPClient, IRTMPHandler, Constants, StatusCodes
Direct Known Subclasses:
RTMPClient, RTMPTClient

public abstract class BaseRTMPClientHandler extends BaseRTMPHandler implements IRTMPClient
Base class for clients (RTMP and RTMPT)
  • Field Details

    • protocol

      protected String protocol
      Connection scheme / protocol
    • connectionParams

      protected Map<String,Object> connectionParams
      Connection parameters
    • conn

      protected volatile RTMPConnection conn
      Associated RTMP connection
    • bandwidthCheckDone

      protected boolean bandwidthCheckDone
      Whether or not the bandwidth done has been invoked
    • subscribed

      protected boolean subscribed
      Whether or not the client is subscribed
    • executor

      protected ScheduledExecutorService executor
      For handling threading / scheduling in the clients.
  • Constructor Details

    • BaseRTMPClientHandler

      protected BaseRTMPClientHandler()
  • Method Details

    • startConnector

      protected abstract void startConnector(String server, int port)
      Start network connection to server
      Parameters:
      server - Server
      port - Connection port
    • connect

      public void connect(String server, int port, String application)
      Connect RTMP client to server's application via given port
      Specified by:
      connect in interface IRTMPClient
      Parameters:
      server - Server
      port - Connection port
      application - Application at that server
    • connect

      public void connect(String server, int port, String application, IPendingServiceCallback connectCallback)
      Connect RTMP client to server's application via given port with given connection callback
      Specified by:
      connect in interface IRTMPClient
      Parameters:
      server - Server
      port - Connection port
      application - Application at that server
      connectCallback - Connection callback
    • makeDefaultConnectionParams

      public Map<String,Object> makeDefaultConnectionParams(String server, int port, String application)
      Creates the default connection parameters collection. Many implementations of this handler will create a tcUrl if not found, it is created with the current server url.
      Specified by:
      makeDefaultConnectionParams in interface IRTMPClient
      Parameters:
      server - the server location
      port - the port for the protocol
      application - the application name at the given server
      Returns:
      connection parameters map
    • connect

      public void connect(String server, int port, Map<String,Object> connectionParams)
      Connect RTMP client to server via given port and with given connection parameters
      Specified by:
      connect in interface IRTMPClient
      Parameters:
      server - Server
      port - Connection port
      connectionParams - Connection parameters
    • connect

      public void connect(String server, int port, Map<String,Object> connectionParams, IPendingServiceCallback connectCallback)
      Connect RTMP client to server's application via given port
      Specified by:
      connect in interface IRTMPClient
      Parameters:
      server - Server
      port - Connection port
      connectionParams - Connection parameters
      connectCallback - Connection callback
    • connect

      public void connect(String server, int port, Map<String,Object> connectionParams, IPendingServiceCallback connectCallback, Object[] connectCallArguments)
      Connect RTMP client to server's application via given port
      Specified by:
      connect in interface IRTMPClient
      Parameters:
      server - Server
      port - Connection port
      connectionParams - Connection parameters
      connectCallback - Connection callback
      connectCallArguments - Arguments for 'connect' call
    • setServiceProvider

      public void setServiceProvider(Object serviceProvider)
      Register object that provides methods that can be called by the server.
      Specified by:
      setServiceProvider in interface IRTMPClient
      Parameters:
      serviceProvider - Service provider
    • setConnectionClosedHandler

      public void setConnectionClosedHandler(Runnable connectionClosedHandler)
      Sets a handler for connection close.
      Specified by:
      setConnectionClosedHandler in interface IRTMPClient
      Parameters:
      connectionClosedHandler - close handler
    • setExceptionHandler

      public void setExceptionHandler(ClientExceptionHandler exceptionHandler)
      Sets a handler for exceptions.
      Specified by:
      setExceptionHandler in interface IRTMPClient
      Parameters:
      exceptionHandler - exception handler
    • getSharedObject

      public IClientSharedObject getSharedObject(String name, boolean persistent)
      Connect to client shared object.
      Specified by:
      getSharedObject in interface IRTMPClient
      Parameters:
      name - Client shared object name
      persistent - SO persistence flag
      Returns:
      Client shared object instance
    • onChunkSize

      protected void onChunkSize(RTMPConnection conn, Channel channel, Header source, ChunkSize chunkSize)
      Specified by:
      onChunkSize in class BaseRTMPHandler
    • onPing

      protected void onPing(RTMPConnection conn, Channel channel, Header source, Ping ping)
      Specified by:
      onPing in class BaseRTMPHandler
    • onServerBandwidth

      protected void onServerBandwidth(RTMPConnection conn, Channel channel, ServerBW message)
      Overrides:
      onServerBandwidth in class BaseRTMPHandler
    • onClientBandwidth

      protected void onClientBandwidth(RTMPConnection conn, Channel channel, ClientBW message)
      Overrides:
      onClientBandwidth in class BaseRTMPHandler
    • onSharedObject

      protected void onSharedObject(RTMPConnection conn, Channel channel, Header source, SharedObjectMessage object)
      Specified by:
      onSharedObject in class BaseRTMPHandler
    • onBWCheck

      public void onBWCheck()
      Called when negotiating bandwidth.
    • onBWCheck

      public void onBWCheck(Object params)
      Called when negotiating bandwidth.
      Parameters:
      params - bw parameters
    • onBWDone

      public void onBWDone(Object params)
      Called when bandwidth has been configured.
      Parameters:
      params - bw parameters
    • onBWDone

      public void onBWDone()
      Called when bandwidth has been configured.
    • invoke

      public void invoke(String method, IPendingServiceCallback callback)
      Invoke a method on the server.
      Specified by:
      invoke in interface IRTMPClient
      Parameters:
      method - Method name
      callback - Callback handler
    • invoke

      public void invoke(String method, Object[] params, IPendingServiceCallback callback)
      Invoke a method on the server and pass parameters.
      Specified by:
      invoke in interface IRTMPClient
      Parameters:
      method - Method
      params - Method call parameters
      callback - Callback object
    • disconnect

      public void disconnect()
      Disconnect the first connection in the connection map
      Specified by:
      disconnect in interface IRTMPClient
    • createStream

      public void createStream(IPendingServiceCallback callback)
      Specified by:
      createStream in interface IRTMPClient
    • releaseStream

      public void releaseStream(IPendingServiceCallback callback, Object[] params)
    • deleteStream

      public void deleteStream(IPendingServiceCallback callback)
    • subscribe

      public void subscribe(IPendingServiceCallback callback, Object[] params)
    • publish

      public void publish(Number streamId, String name, String mode, INetStreamEventHandler handler)
      Specified by:
      publish in interface IRTMPClient
    • unpublish

      public void unpublish(Number streamId)
      Specified by:
      unpublish in interface IRTMPClient
    • publishStreamData

      public void publishStreamData(Number streamId, IMessage message)
      Specified by:
      publishStreamData in interface IRTMPClient
    • play

      public void play(Number streamId, String name, int start, int length)
      Specified by:
      play in interface IRTMPClient
    • play2

      public void play2(Number streamId, Map<String,?> playOptions)
      Dynamic streaming play method. The following properties are supported on the play options:
               streamName: String. The name of the stream to play or the new stream to switch to.
               oldStreamName: String. The name of the initial stream that needs to be switched out. This is not needed and ignored
                              when play2 is used for just playing the stream and not switching to a new stream.
               start: Number. The start time of the new stream to play, just as supported by the existing play API. and it has the
                              same defaults. This is ignored when the method is called for switching (in other words, the transition
                              is either NetStreamPlayTransition.SWITCH or NetStreamPlayTransitions.SWAP)
               len: Number. The duration of the playback, just as supported by the existing play API and has the same defaults.
               transition: String. The transition mode for the playback command. It could be one of the following:
                                   NetStreamPlayTransitions.RESET
                                   NetStreamPlayTransitions.APPEND
                                   NetStreamPlayTransitions.SWITCH
                                   NetStreamPlayTransitions.SWAP
       
      NetStreamPlayTransitions:
                   APPEND : String = "append" - Adds the stream to a playlist and begins playback with the first stream.
                   APPEND_AND_WAIT : String = "appendAndWait" - Builds a playlist without starting to play it from the first stream.
                   RESET : String = "reset" - Clears any previous play calls and plays the specified stream immediately.
                   RESUME : String = "resume" - Requests data from the new connection starting from the point at which the previous connection ended.
                   STOP : String = "stop" - Stops playing the streams in a playlist.
                   SWAP : String = "swap" - Replaces a content stream with a different content stream and maintains the rest of the playlist.
                   SWITCH : String = "switch" - Switches from playing one stream to another stream, typically with streams of the same content.
       
      Specified by:
      play2 in interface IRTMPClient
      See Also:
    • ping

      public void ping(short pingType, Number streamId, int param)
      Sends a ping.
      Parameters:
      pingType - the type of ping
      streamId - streams id
      param - ping parameter
    • connectionOpened

      public void connectionOpened(RTMPConnection conn)
      Specified by:
      connectionOpened in interface IRTMPHandler
      Overrides:
      connectionOpened in class BaseRTMPHandler
    • connectionClosed

      public void connectionClosed(RTMPConnection conn)
      Specified by:
      connectionClosed in interface IRTMPHandler
      Overrides:
      connectionClosed in class BaseRTMPHandler
    • onCommand

      protected void onCommand(RTMPConnection conn, Channel channel, Header source, ICommand command)
      Specified by:
      onCommand in class BaseRTMPHandler
    • handleException

      public void handleException(Throwable throwable)
      Handle any exceptions that occur.
      Parameters:
      throwable - Exception thrown
    • getChannelForStreamId

      protected int getChannelForStreamId(Number streamId)
      Returns a channel based on the given stream id.
      Parameters:
      streamId - stream id
      Returns:
      the channel for this stream id
    • setProtocol

      public void setProtocol(String protocol) throws Exception
      Sets the protocol.
      Parameters:
      protocol - the data protocol to use.
      Throws:
      Exception - thrown
    • setConnection

      public void setConnection(RTMPConnection conn)
      Sets a reference to the connection associated with this client handler.
      Parameters:
      conn - connection
    • getConnection

      public RTMPConnection getConnection()
      Returns the connection associated with this client.
      Specified by:
      getConnection in interface IRTMPClient
      Returns:
      conn connection
    • setSwfVerification

      public void setSwfVerification(boolean enabled)
      Enables or disables SWF verification.
      Parameters:
      enabled - state of SWF verification
    • isSwfVerification

      public boolean isSwfVerification()
      Returns true if swf verification is enabled
      Returns:
      the swfVerification
    • isBandwidthCheckDone

      public boolean isBandwidthCheckDone()
      Returns true if bandwidth done has been invoked
      Returns:
      the bandwidthCheckDone
    • isSubscribed

      public boolean isSubscribed()
      Returns true if this client is subscribed
      Returns:
      subscribed state
    • getConnectionParams

      public Map<String,Object> getConnectionParams()
      Returns:
      the connectionParams
    • setStreamEventDispatcher

      public void setStreamEventDispatcher(IEventDispatcher streamEventDispatcher)
      Setter for stream event dispatcher (useful for saving playing stream to file)
      Specified by:
      setStreamEventDispatcher in interface IRTMPClient
      Parameters:
      streamEventDispatcher - event dispatcher
    • setStreamEventHandler

      public void setStreamEventHandler(INetStreamEventHandler streamEventHandler)
      Setter for the stream event handler.
      Parameters:
      streamEventHandler - event handler