/// Binds client with worker and runs authorization routines.
/// Method returns error if worker is not running or client already bound
Binds client with worker and runs authorization routines.
Method returns error if worker is not running or client already bound
Binds client with worker and runs authorization routines . Method returns error if worker is not running or client already bound
pub async fn bind_client(&mut self, mut client: Client<T>) -> RTDResult<Client<T>> {
        if !self.is_running() {
            return Err(RTDError::BadRequest("worker not started yet"));
        };
        let client_id = client.get_tdlib_client().new_client();
        log::debug!("new client created: {}", client_id);
        client.set_client_id(client_id)?;
        let (sx, rx) = match client.get_auth_state_channel_size() {
            None => (None, None),
            Some(size) => {
                let (sx, rx) = mpsc::channel(size);
                (Some(sx), Some(Arc::new(Mutex::new(rx))))
            }
        };
        let (psx, prx) = mpsc::channel::<ClientState>(5);
        let ctx = ClientContext {
            client: client.clone(),
            pub_state_message_sender: sx,
            pub_state_message_receiver: rx,
            private_state_message_receiver: Arc::new(Mutex::new(prx)),
            private_state_message_sender: psx,
        };
        self.clients.write().await.insert(client_id, ctx);
        log::debug!("new client added");
        // We need to call any tdlib method to retrieve first response.
        // Otherwise client can't be authorized: no `UpdateAuthorizationState` send by TDLib.
        first_internal_request(&client.get_tdlib_client(), client_id).await;
        log::trace!("received first internal response");
        Ok(client)
    }
pub async fn bind_client ( & mut self , mut client : Client < T > ) -> RTDResult < Client < T > > { if ! self . is_running ( ) { return Err ( RTDError :: BadRequest ( " " ) ) ; } ; let client_id = client . get_tdlib_client ( ) . new_client ( ) ; log :: debug ! ( " " client_id ) ; client . set_client_id ( client_id ) ? ; let ( sx , rx ) = match client . get_auth_state_channel_size ( ) { None => ( None , None ) , Some ( size ) => { let ( sx , rx ) = mpsc :: channel ( size ) ; ( Some ( sx ) , Some ( Arc :: new ( Mutex :: new ( rx ) ) ) ) } } ; let ( psx , prx ) = mpsc :: channel :: < ClientState > ( 5 ) ; let ctx = ClientContext { client : client . clone ( ) , pub_state_message_sender : sx , pub_state_message_receiver : rx , private_state_message_receiver : Arc :: new ( Mutex :: new ( prx ) ) , private_state_message_sender : psx , } ; self . clients . write ( ) . await . insert ( client_id , ctx ) ; log :: debug ! ( " " ) ; // We need to call any tdlib method to retrieve first response. // Otherwise client can't be authorized: no `UpdateAuthorizationState` send by TDLib. first_internal_request ( & client . get_tdlib_client ( ) , client_id ) . await ; log :: trace ! ( " " ) ; Ok ( client ) }
Binds client with worker and runs authorization routines.
Binds client with worker and runs authorization routines .
&mut self
client
Client<T>