Ejemplo n.º 1
0
 def disconnect(self, close_code):
     LOGGER.warn("WebConsumer: Closed websocket with code: {}".format(close_code))
     send_remote_status(self.printer, viewing=False)
     async_to_sync(self.channel_layer.group_discard)(
         channels.status_group_name(self.printer_id),
         self.channel_name
     )
Ejemplo n.º 2
0
    def connect(self):
        self.printer_id = self.scope['url_route']['kwargs']['printer_id']
        try:
            printer = Printer.objects.get(
                user=self.current_user(), id=self.printer_id
            )  # Exception for un-authenticated or un-authorized access

            async_to_sync(self.channel_layer.group_add)(
                channels.status_group_name(self.printer_id), self.channel_name)
            self.accept()
            channels.send_status_to_web(printer.id)
        except:
            self.close()
Ejemplo n.º 3
0
    def connect(self):
        try:
            if self.scope['path'].startswith('/ws/shared/'):
                self.printer = self.current_user()
            else:
                # Exception for un-authenticated or un-authorized access
                self.printer = Printer.objects.get(
                    user=self.current_user(),
                    id=self.scope['url_route']['kwargs']['printer_id'])

            async_to_sync(self.channel_layer.group_add)(
                channels.status_group_name(self.printer.id), self.channel_name)
            self.accept()
            channels.send_status_to_web(self.printer.id)
            send_remote_status(self.printer, viewing=True)
        except:
            LOGGER.exception("Websocket failed to connect")
            self.close()