�
���g� � �N � d dl Z d dlmZ d dlmZ ddlmZ G d� de� � ZdS )� N)�packet� )�BaseManagerc �T � � e Zd ZdZd� Z dd�Z� fd�Zd� Zdd�Zd� Z d � Z
d
� Z� xZS )
�AsyncManagerz+Manage a client list for an asyncio server.c � �2 K � | � ||� � S �N)�is_connected)�self�sid� namespaces �f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/socketio/async_manager.py�can_disconnectzAsyncManager.can_disconnect
s � � � �� � ��i�0�0�0� Nc
� �� K � |p|}|| j vrdS t |t � � rt |� � }n|�|g}ng }t |t � � s|g}g } |s�| j � t j ||g|z �� � }
|
� � � }t |t � � s|g}d� |D � � }| � ||� � D ]N\ }
}|
|vrE|D ]B}| �
t j | j �
||� � � � � � �C�On�| � ||� � D ]�\ }
}|
|vr�| � |
|� � }| j � t j ||g|z |�� � }
| �
t j | j � ||
� � � � � � ��| g k rdS t j | � � � d{V �� dS )z�Emit a message to a single client, a room, or all the clients
connected to the namespace.
Note: this method is a coroutine.
N)r
�datac �L � g | ]!}t j t j |� � ��"S � )�
eio_packet�Packet�MESSAGE)�.0�ps r �
<listcomp>z%AsyncManager.emit.<locals>.<listcomp>* s8 � � 0� 0� 0�� "�(��);�Q�?�?� 0� 0� 0r )r
r �id)�rooms�
isinstance�tuple�list�server�packet_classr �EVENT�encode�get_participants�append�asyncio�create_task�_send_eio_packet�_generate_ack_id�_send_packet�wait)r �eventr r
�room�skip_sid�callback�to�kwargs�tasks�pkt�encoded_packet�eio_pktr �eio_sidr r s r �emitzAsyncManager.emit
sm � � � � �z�T���D�J�&�&��F��d�E�"�"� � ��:�:�D�D�
�
��6�D�D��D��(�D�)�)� "� �z�H���� A� �+�*�*��� ���$�� +� H� H�C� �Z�Z�\�\�N��n�d�3�3�
2�"0�!1��0� 0� .�0� 0� 0�G� $� 5� 5�i�� F� F�
G�
G���W��h�&�&�$� G� G�����W�%8� �K�8�8��!�D�D�&F� &F� G� G� G� G��
G� !%� 5� 5�i�� F� F�
A�
A���W��h�&�&��.�.�s�H�=�=�B��+�2�2��� ���$��� 3� � �C� �L�L��!4���0�0��#�>�>�"@� "@� A� A� A���B�;�;��F��l�5�!�!�!�!�!�!�!�!�!�!�!r c � �L �K � t � � � ||� � S )z`Register a client connection to a namespace.
Note: this method is a coroutine.
)�super�connect)r r6 r
� __class__s �r r: zAsyncManager.connectB s! �� � � �
�w�w���w� �2�2�2r c � �$ K � | j ||fi |��S )zHDisconnect a client.
Note: this method is a coroutine.
)�basic_disconnect)r r r
r1 s r �
disconnectzAsyncManager.disconnectI s% � � � �
%�t�$�S�)�>�>�v�>�>�>r c � �8 K � | � ||||�� � S )zKAdd a client to a room.
Note: this method is a coroutine.
)r6 )�basic_enter_room)r r r
r- r6 s r �
enter_roomzAsyncManager.enter_roomP s% � � � �
�$�$�S�)�T�7�$�K�K�Kr c � �4 K � | � |||� � S )zPRemove a client from a room.
Note: this method is a coroutine.
)�basic_leave_room)r r r
r- s r �
leave_roomzAsyncManager.leave_roomW s � � � �
�$�$�S�)�T�:�:�:r c � �2 K � | � ||� � S )zXRemove all participants from a room.
Note: this method is a coroutine.
)�basic_close_room)r r- r
s r �
close_roomzAsyncManager.close_room^ s � � � �
�$�$�T�9�5�5�5r c � �> K � d} | j | | }| j | |= n7# t $ r* | � � � � d� � Y nw xY w|�: ||� }t j |� � r# |� d{V �� dS # t j $ r Y dS w xY wdS dS )zSInvoke an application callback.
Note: this method is a coroutine.
Nz$Unknown callback received, ignoring.)� callbacks�KeyError�_get_logger�warningr&