Class MediaProxy

  • All Implemented Interfaces:
    SessionListener

    public class MediaProxy
    extends Object
    implements SessionListener
    A Media Proxy relays UDP traffic between two IPs to provide connectivity between two parties that are behind NAT devices. It also provides connectivity between two parties that are directly connected to the internet or one party on the internet and another behind a NAT.

    Each connection relay between two parties is called a session. You can setup a MediaProxy for all network interfaces with an empty constructor, or bind it to a specific interface with the MediaProxy(String localhost) constructor. The media proxy ONLY works if you are directly connected to the Internet with a valid IP address..

    Author:
    Thiago Camargo
    • Constructor Detail

      • MediaProxy

        public MediaProxy​(String ipAddress)
        Contruct a MediaProxy instance that will listen on a specific network interface.
        Parameters:
        ipAddress - the IP address on this server that will listen for packets.
    • Method Detail

      • getPublicIP

        public String getPublicIP()
        Get the public IP of this media proxy that listen for incomming packets.
        Returns:
        the host that listens for incomming packets.
      • getIdleTime

        public long getIdleTime()
        Returns the max time (in millis) that a session can remain open without receiving any packets. After this time period elapses, the session is automatically closed.
        Returns:
        the max idle time (in millis).
      • setIdleTime

        public void setIdleTime​(long idleTime)
        Sets the max time (in millis) that a session can remain open without receiving any packets. After this time period elapses, the session is automatically closed.
        Parameters:
        idleTime - the max idle time in millis.
      • getSessions

        public Collection<MediaProxySession> getSessions()
        Returns the list of all currently active and running sessions.
        Returns:
        List of the Agents
      • getMinPort

        public int getMinPort()
        Returns the minimum port value to listen for incoming packets.
        Returns:
        the minimum port value.
      • setMinPort

        public void setMinPort​(int minPort)
        Sets the minimum port value to listen from incoming packets.
        Parameters:
        minPort - the minimum port value.
      • getMaxPort

        public int getMaxPort()
        Returns the maximum port value to listen for incoming packets.
        Returns:
        the maximun port value.
      • setMaxPort

        public void setMaxPort​(int maxPort)
        Sets the maximum port value to listen for incoming packets.
        Parameters:
        maxPort - the maximun port value.
      • getLifetime

        public long getLifetime()
        Returns the maximum lifetime (in seconds) of a session. After the time period elapses, the session will be destroyed even if currently active.
        Returns:
        the max lifetime of a session (in seconds).
      • setLifetime

        public void setLifetime​(long lifetime)
        Sets the maximum lifetime (in seconds) of a session. After the time period elapses, the session will be destroyed even if currently active.
        Parameters:
        lifetime - the max lifetime of a session (in seconds).
      • getSession

        public MediaProxySession getSession​(String sid)
        Returns a media proxy session with the specified ID.
        Parameters:
        sid - the session ID.
        Returns:
        the session or null if the session doesn't exist.
      • sessionClosed

        public void sessionClosed​(MediaProxySession session)
        Implements Session Listener stopAgent event. Remove the stopped session from the sessions list.
        Specified by:
        sessionClosed in interface SessionListener
        Parameters:
        session - the session that stopped
      • addRelayAgent

        public ProxyCandidate addRelayAgent​(String id,
                                            String creator,
                                            String hostA,
                                            int portA,
                                            String hostB,
                                            int portB)
        Add a new Dynamic Session to the mediaproxy for defined IPs and ports. The IP and port pairs can change depending of the Senders IP and port. Which means that the IP and port values of the points can dynamic change after the Channel is opened. When the agent receives a packet from Point A, the channel set the point A IP and port according to the received packet sender IP and port. Every packet received from Point B will be relayed to the new Point A IP and port. When the agent receives a packet from Point B, the channel set the point B IP and port according to the received packet sender IP and port. Every packet received from Point A will be relayed to the new Point B IP and port. Create a dynamic channel between two IPs. ( Dynamic Point A - Dynamic Point B )
        Parameters:
        id - id of the candidate returned (Could be a Jingle session ID)
        creator - the agent creator name or description
        hostA - the hostname or IP of the point A of the Channel
        portA - the port number point A of the Channel
        hostB - the hostname or IP of the point B of the Channel
        portB - the port number point B of the Channel
        Returns:
        the added ProxyCandidate
      • addRelayAgent

        public ProxyCandidate addRelayAgent​(String id,
                                            String creator)
        Add a new Dynamic Session to the mediaproxy WITHOUT defined IPs and ports. The IP and port pairs WILL change depending of the Senders IP and port. Which means that the IP and port values of the points will dynamic change after the Channel is opened and received packet from both points. When the agent receives a packet from Point A, the channel set the point A IP and port according to the received packet sender IP and port. Every packet received from Point B will be relayed to the new Point A IP and port. When the agent receives a packet from Point B, the channel set the point B IP and port according to the received packet sender IP and port. Every packet received from Point A will be relayed to the new Point B IP and port. Create a dynamic channel between two IPs. ( Dynamic Point A - Dynamic Point B )
        Parameters:
        id - id of the candidate returned (Could be a Jingle session ID)
        creator - the agent creator name or description
        Returns:
        the added ProxyCandidate