Exemplo n.º 1
0
class BridgeServer(DeviceDiscoveryService):

    def __init__(self, interface):
        DeviceDiscoveryService.__init__(self, interface[0], MEDIA_RENDERER_TYPES,
                                        [MEDIA_RENDERER_DEVICE_TYPE],
                                        REQ_SERVICE_TYPES)

        self._ports = []
        
        # optionally add a server for the Interactive Web
        if config.interactive_web_enabled():
            iwebport = config.interactive_web_port()
            self.iweb = InteractiveWeb(iwebport, interface[0])
            self.iweb.setServiceParent(self)
        else:
            self.iweb = None

        # add a server for serving photos to UPnP devices
        self.photoweb = PhotoWeb(0, 5, interface[0])
        self.photoweb.setServiceParent(self)

        self.interface = interface

    def startService(self):
        log.msg("Airpnp started. Will now search for UPnP devices!")

        if self.iweb:
            # apparently, logging in __init__ is too early
            iwebport = self.iweb.port
            log.msg("Starting interactive web at port %d" % (iwebport, ))
        DeviceDiscoveryService.startService(self)

    def on_device_found(self, device):
        log.msg('Found device %s with base URL %s' % (device,
                                                      device.get_base_url()))
        cpoint = AVControlPoint(device, self.photoweb, self.interface[0])
        devid = create_device_id(device.UDN)
        avc = AirPlayService(cpoint, device.friendlyName, host=self.interface[0], port=self._find_port(), index=self.interface[1], device_id=devid)
        avc.setName(device.UDN)
        avc.setServiceParent(self)
        
        if self.iweb:
            self.iweb.add_device(device) 

    def on_device_removed(self, device):
        log.msg('Lost device %s' % (device, ))
        avc = self.getServiceNamed(device.UDN)
        avc.disownServiceParent()
        self._ports.remove(avc.port)
        del avc

        if self.iweb:
            self.iweb.remove_device(device)

    def _find_port(self):
        port = 22555
        while port in self._ports:
            port += 1
        self._ports.append(port)
        return port
Exemplo n.º 2
0
    def __init__(self, interface):
        DeviceDiscoveryService.__init__(self, interface[0], MEDIA_RENDERER_TYPES,
                                        [MEDIA_RENDERER_DEVICE_TYPE],
                                        REQ_SERVICE_TYPES)

        self._ports = []
        
        # optionally add a server for the Interactive Web
        if config.interactive_web_enabled():
            iwebport = config.interactive_web_port()
            self.iweb = InteractiveWeb(iwebport, interface[0])
            self.iweb.setServiceParent(self)
        else:
            self.iweb = None

        # add a server for serving photos to UPnP devices
        self.photoweb = PhotoWeb(0, 5, interface[0])
        self.photoweb.setServiceParent(self)

        self.interface = interface