alik0211 / mtproto-core

Telegram API JS (MTProto) client library for Node.js and browser
https://mtproto-core.js.org
GNU General Public License v3.0
630 stars 113 forks source link

Add possibility to destroy (disconnect) #235

Closed fedyk closed 11 months ago

fedyk commented 2 years ago

Currently, after creating an instance of MTProto, there are no easy way to destroy instance (close open ws/socket connections and remove listeners).

Here I added a destroy method. The usage is following:

// 1. Create instance
const mtproto = new MTProto({ api_id, api_hash, storageOptions: {...}});

// 2. Call any method(-s)
mtproto.call('help.getNearestDc').then(result => ...});

// 3. Destroy: close open connections, reject pending requests, cleanup event's listeners
mtproto.destroy()
abdulgalimov commented 2 years ago

Please tell me, can these edits be merge to the master? Need a destroy method. Thanks

Alexxosipov commented 2 years ago

@alik0211 can you please merge it?