Better handling of unexpected unplugging; notify javascript handler when it happens