コード例 #1
0
ファイル: base.py プロジェクト: longde123/fmspy
    def _handshakeComplete(self):
        """
        Handshake was complete.

        Start regular pings.
        """
        RTMPBaseProtocol._handshakeComplete(self)

        self.pingTask = task.LoopingCall(self._pinger)
        self.pingTask.start(config.getint('RTMP', 'pingInterval'), now=False)
コード例 #2
0
ファイル: base.py プロジェクト: Xkeeper/fmspy
    def _handshakeComplete(self):
        """
        Handshake was complete.

        Start regular pings.
        """
        RTMPBaseProtocol._handshakeComplete(self)

        self.pingTask = task.LoopingCall(self._pinger)
        self.pingTask.start(config.getint('RTMP', 'pingInterval'), now=False)
コード例 #3
0
ファイル: base.py プロジェクト: Xkeeper/fmspy
    def connectionMade(self):
        """
        Successfully connected to peer.
        """
        self.input = RTMPDisassembler(constants.DEFAULT_CHUNK_SIZE)
        self.output = RTMPAssembler(constants.DEFAULT_CHUNK_SIZE, self.transport)

        self.state = self.State.HANDSHAKE_SEND
        self.handshakeTimeout = reactor.callLater(config.getint('RTMP', 'handshakeTimeout'), self._handshakeTimedout)
        self.handshakeBuf = BufferedByteStream()
        self._beginHandshake()
コード例 #4
0
ファイル: base.py プロジェクト: Xkeeper/fmspy
    def _pinger(self):
        """
        Regular 'ping' service.

        We send 'pings' to other end of RTMP protocol, expecting to receive
        'pong'. If we receive some data, we assume 'ping' is sent. If other end
        of protocol doesn't send anything in reply to our 'ping' for some timeout,
        we disconnect connection.
        """
        noDataInterval = _time.seconds() - self.lastReceived

        if noDataInterval > config.getint('RTMP', 'keepAliveTimeout'):
            log.msg('Closing connection due too much inactivity (%d)' % noDataInterval)
            self.transport.loseConnection()
            return

        if noDataInterval > config.getint('RTMP', 'pingInterval'):
            self.pushPacket(Ping(Ping.PING_CLIENT, [int(_time.seconds()*1000) & 0x7fffffff]))

        self.pushPacket(BytesRead(self.bytesReceived))
コード例 #5
0
ファイル: base.py プロジェクト: longde123/fmspy
    def connectionMade(self):
        """
        Successfully connected to peer.
        """
        self.input = RTMPDisassembler(constants.DEFAULT_CHUNK_SIZE)
        self.output = RTMPAssembler(constants.DEFAULT_CHUNK_SIZE,
                                    self.transport)

        self.state = self.State.HANDSHAKE_SEND
        self.handshakeTimeout = reactor.callLater(
            config.getint('RTMP', 'handshakeTimeout'), self._handshakeTimedout)
        self.handshakeBuf = BufferedByteStream()
        self._beginHandshake()
コード例 #6
0
ファイル: base.py プロジェクト: longde123/fmspy
    def _pinger(self):
        """
        Regular 'ping' service.

        We send 'pings' to other end of RTMP protocol, expecting to receive
        'pong'. If we receive some data, we assume 'ping' is sent. If other end
        of protocol doesn't send anything in reply to our 'ping' for some timeout,
        we disconnect connection.
        """
        noDataInterval = _time.seconds() - self.lastReceived

        if noDataInterval > config.getint('RTMP', 'keepAliveTimeout'):
            log.msg('Closing connection due too much inactivity (%d)' %
                    noDataInterval)
            self.transport.loseConnection()
            return

        if noDataInterval > config.getint('RTMP', 'pingInterval'):
            self.pushPacket(
                Ping(Ping.PING_CLIENT,
                     [int(_time.seconds() * 1000) & 0x7fffffff]))

        self.pushPacket(BytesRead(self.bytesReceived))
コード例 #7
0
ファイル: fmspy_plugin.py プロジェクト: Xkeeper/fmspy
    def makeService(self, options):
        """
        Construct a TCPServer from a factory defined in myproject.
        """
        observer = log.FileLogObserver(sys.stderr)
        log.addObserver(observer.emit)

        from fmspy.config import config
        
        if options['rtmp-port'] != 1935:
            config.set('RTMP', 'port', options['rtmp-port'])
        if options['rtmp-interface'] != '':
            config.set('RTMP', 'interface', options['rtmp-interface'])

        from twisted.application import internet, service
        from fmspy.rtmp.protocol import RTMPServerFactory

        s = service.MultiService()

        h = internet.TCPServer(config.getint('RTMP', 'port'), RTMPServerFactory(), config.getint('RTMP', 'backlog'), config.get('RTMP', 'interface'))
        h.setServiceParent(s)

        log.msg('RTMP server at port %d.' % config.getint('RTMP', 'port'))

        from fmspy.application import app_factory

        def appsLoaded(_):
            log.msg("Applications loaded.")

        def appsError(fail):
            log.err(fail, "Applications failed to load.")

        app_factory.load_applications().addCallbacks(appsLoaded, appsError)

        if config.getboolean('HTTP', 'enabled'):
            from twisted.web import server, static, resource

            root = resource.Resource()

            if config.getboolean('HTTP', 'examples-enabled'):
                examples_path = 'examples/'

                try:
                    from pkg_resources import Requirement, resource_filename, DistributionNotFound

                    try:
                        examples_path = resource_filename(Requirement.parse("fmspy"), "share/examples")
                    except DistributionNotFound:
                        pass

                except ImportError:
                    pass 

                root.putChild('examples', static.File(examples_path))

                h = internet.TCPServer(config.getint('HTTP', 'port'), server.Site(root))
                h.setServiceParent(s)

                log.msg('HTTP server at port %d.' % config.getint('HTTP', 'port'))

        log.removeObserver(observer.emit)

        return s
コード例 #8
0
ファイル: fmspy_plugin.py プロジェクト: longde123/fmspy
    def makeService(self, options):
        """
        Construct a TCPServer from a factory defined in myproject.
        """
        observer = log.FileLogObserver(sys.stderr)
        log.addObserver(observer.emit)

        from fmspy.config import config

        if options['rtmp-port'] != 1935:
            config.set('RTMP', 'port', options['rtmp-port'])
        if options['rtmp-interface'] != '':
            config.set('RTMP', 'interface', options['rtmp-interface'])

        from twisted.application import internet, service
        from fmspy.rtmp.protocol import RTMPServerFactory

        s = service.MultiService()

        h = internet.TCPServer(config.getint('RTMP', 'port'),
                               RTMPServerFactory(),
                               config.getint('RTMP', 'backlog'),
                               config.get('RTMP', 'interface'))
        h.setServiceParent(s)

        log.msg('RTMP server at port %d.' % config.getint('RTMP', 'port'))

        from fmspy.application import app_factory

        def appsLoaded(_):
            log.msg("Applications loaded.")

        def appsError(fail):
            log.err(fail, "Applications failed to load.")

        app_factory.load_applications().addCallbacks(appsLoaded, appsError)

        if config.getboolean('HTTP', 'enabled'):
            from twisted.web import server, static, resource

            root = resource.Resource()

            if config.getboolean('HTTP', 'examples-enabled'):
                examples_path = 'examples/'

                try:
                    from pkg_resources import Requirement, resource_filename, DistributionNotFound

                    try:
                        examples_path = resource_filename(
                            Requirement.parse("fmspy"), "share/examples")
                    except DistributionNotFound:
                        pass

                except ImportError:
                    pass

                root.putChild('examples', static.File(examples_path))

                h = internet.TCPServer(config.getint('HTTP', 'port'),
                                       server.Site(root))
                h.setServiceParent(s)

                log.msg('HTTP server at port %d.' %
                        config.getint('HTTP', 'port'))

        log.removeObserver(observer.emit)

        return s