def disconnect(self, close_code): LOGGER.warn("WebConsumer: Closed websocket with code: {}".format(close_code)) async_to_sync(self.channel_layer.group_discard)( channels.web_group_name(self.printer.id), self.channel_name ) Room.objects.remove(channels.web_group_name(self.printer.id), self.channel_name)
def disconnect(self, close_code): LOGGER.warn( "WebConsumer: Closed websocket with code: {}".format(close_code)) async_to_sync(self.channel_layer.group_discard)( channels.web_group_name(self.printer.id), self.channel_name) channels.broadcast_ws_connection_change( channels.web_group_name(self.printer.id))
def connect(self): self.anomaly_tracker = AnomalyTracker(now()) if self.current_printer().is_authenticated: self.accept() async_to_sync(self.channel_layer.group_add)( channels.octo_group_name(self.current_printer().id), self.channel_name) self.last_touch = time.time() Room.objects.add( channels.octo_group_name(self.current_printer().id), self.channel_name) # Send remote status to OctoPrint as soon as it connects self.printer_message({ 'remote_status': { 'viewing': channels.num_ws_connections( channels.web_group_name(self.current_printer().id)) > 0, 'should_watch': self.current_printer().should_watch(), } }) else: self.close()
def connect(self): self.anomaly_tracker = AnomalyTracker(now()) self.printer = None self.printer = self.get_printer() self.accept() async_to_sync(self.channel_layer.group_add)(channels.octo_group_name( self.printer.id), self.channel_name) self.last_touch = time.time() Room.objects.add(channels.octo_group_name(self.printer.id), self.channel_name) # Send remote status to OctoPrint as soon as it connects self.printer_message({ 'remote_status': { 'viewing': channels.num_ws_connections( channels.web_group_name(self.printer.id)) > 0, 'should_watch': self.printer.should_watch(), } }) touch_user_last_active(self.printer.user)
def connect(self): self.printer = None self.printer = self.get_printer() self.accept() async_to_sync(self.channel_layer.group_add)(channels.web_group_name( self.printer.id), self.channel_name) self.last_touch = time.time() Room.objects.add(channels.web_group_name(self.printer.id), self.channel_name) # Send printer status to web frontend as soon as it connects self.printer_status(None) touch_user_last_active(self.printer.user)
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.web_group_name(self.printer.id), self.channel_name ) self.accept() Room.objects.add(channels.web_group_name(self.printer.id), self.channel_name) self.printer_status(None) # Send printer status to web frontend as soon as it connects except: LOGGER.exception("Websocket failed to connect") self.close()
def connect(self): try: if self.scope['path'].startswith('/ws/share_token/') or self.scope[ 'path'].startswith('/ws/token/'): self.printer = self.current_user() else: # Throw exception in case of un-authenticated or un-authorized access self.printer = Printer.objects.get( user=self.current_user(), id=self.scope['url_route']['kwargs']['printer_id']) self.group_name = channels.web_group_name(self.printer.id) async_to_sync(self.channel_layer.group_add)(self.group_name, self.channel_name) self.accept() channels.broadcast_ws_connection_change(self.group_name) self.printer_status( None ) # Send printer status to web frontend as soon as it connects except: LOGGER.exception("Websocket failed to connect") self.close()
def receive_json(self, data, **kwargs): channels.touch_channel(channels.web_group_name(self.printer.id), self.channel_name) if 'passthru' in data: channels.send_msg_to_printer(self.printer.id, data)