@mtkruto/node 0.1.500 → 0.1.700

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/esm/3_types.d.ts +6 -1
  2. package/esm/3_types.js +6 -1
  3. package/esm/4_errors.js +2 -4
  4. package/esm/5_client.d.ts +1 -1
  5. package/esm/5_client.js +1 -1
  6. package/esm/client/0_params.d.ts +33 -7
  7. package/esm/client/0_storage_operations.d.ts +182 -0
  8. package/esm/client/0_storage_operations.js +611 -0
  9. package/esm/client/1_composer.d.ts +2 -0
  10. package/esm/client/1_composer.js +28 -0
  11. package/{script/client/0_types.d.ts → esm/client/1_types.d.ts} +3 -3
  12. package/{script/client/1_account_manager.d.ts → esm/client/2_account_manager.d.ts} +1 -1
  13. package/{script/client/1_bot_info_manager.d.ts → esm/client/2_bot_info_manager.d.ts} +1 -1
  14. package/esm/client/{1_business_connection_manager.d.ts → 2_business_connection_manager.d.ts} +1 -1
  15. package/{script/client/1_file_manager.d.ts → esm/client/2_file_manager.d.ts} +6 -2
  16. package/esm/client/{1_file_manager.js → 2_file_manager.js} +55 -52
  17. package/esm/client/{1_network_statistics_manager.d.ts → 2_network_statistics_manager.d.ts} +1 -1
  18. package/{script/client/1_reaction_manager.d.ts → esm/client/2_reaction_manager.d.ts} +1 -1
  19. package/{script/client/1_update_manager.d.ts → esm/client/2_update_manager.d.ts} +1 -1
  20. package/esm/client/{2_message_manager.d.ts → 3_message_manager.d.ts} +2 -2
  21. package/esm/client/3_video_chat_manager.d.ts +43 -0
  22. package/esm/client/3_video_chat_manager.js +194 -0
  23. package/esm/client/{3_callback_query_manager.d.ts → 4_callback_query_manager.d.ts} +2 -2
  24. package/esm/client/{3_callback_query_manager.js → 4_callback_query_manager.js} +1 -0
  25. package/{script/client/3_chat_list_manager.d.ts → esm/client/4_chat_list_manager.d.ts} +6 -6
  26. package/esm/client/{3_chat_list_manager.js → 4_chat_list_manager.js} +75 -98
  27. package/esm/client/{3_inline_query_manager.d.ts → 4_inline_query_manager.d.ts} +2 -2
  28. package/esm/client/{3_inline_query_manager.js → 4_inline_query_manager.js} +1 -0
  29. package/esm/client/{3_story_manager.d.ts → 4_story_manager.d.ts} +3 -3
  30. package/{script/client/4_client.d.ts → esm/client/5_client.d.ts} +105 -31
  31. package/esm/client/{4_client.js → 5_client.js} +172 -73
  32. package/esm/connection/0_connection.d.ts +6 -15
  33. package/esm/connection/0_connection.js +1 -38
  34. package/esm/connection/1_connection_web_socket.d.ts +3 -2
  35. package/esm/connection/1_connection_web_socket.js +7 -3
  36. package/esm/mod.d.ts +1 -1
  37. package/esm/mod.js +1 -1
  38. package/esm/storage/0_storage.d.ts +9 -145
  39. package/esm/storage/0_storage.js +1 -526
  40. package/esm/storage/2_storage_indexed_db.d.ts +3 -2
  41. package/esm/storage/2_storage_indexed_db.js +9 -8
  42. package/esm/storage/2_storage_local_storage.d.ts +3 -2
  43. package/esm/storage/2_storage_local_storage.js +5 -4
  44. package/esm/storage/2_storage_memory.d.ts +4 -4
  45. package/esm/storage/2_storage_memory.js +12 -19
  46. package/esm/storage/2_storage_session_storage.d.ts +2 -1
  47. package/esm/storage/2_storage_session_storage.js +5 -4
  48. package/esm/tl/3_utilities.d.ts +1 -1
  49. package/esm/tl/3_utilities.js +3 -3
  50. package/esm/types/0_birthday.d.ts +27 -0
  51. package/esm/types/0_birthday.js +26 -0
  52. package/esm/types/0_giveaway_parameters.d.ts +1 -1
  53. package/esm/types/0_id.d.ts +1 -1
  54. package/esm/types/0_live_stream_channel.d.ts +30 -0
  55. package/esm/types/0_live_stream_channel.js +26 -0
  56. package/esm/types/0_opening_hours.d.ts +25 -0
  57. package/esm/types/0_opening_hours.js +25 -0
  58. package/esm/types/0_video_chat.d.ts +60 -0
  59. package/esm/types/0_video_chat.js +53 -0
  60. package/esm/types/1_chat_p.d.ts +4 -0
  61. package/esm/types/1_chat_p.js +1 -0
  62. package/esm/types/2_business_connection.d.ts +6 -0
  63. package/esm/types/2_chat.d.ts +62 -0
  64. package/esm/types/2_chat.js +66 -0
  65. package/esm/types/2_inactive_chat.d.ts +1 -1
  66. package/esm/types/2_invite_link.d.ts +1 -1
  67. package/esm/types/2_message_reaction_count.d.ts +1 -1
  68. package/esm/types/2_message_reactions.d.ts +1 -1
  69. package/esm/types/3_chat_member_updated.d.ts +1 -1
  70. package/esm/types/4_message.d.ts +3 -3
  71. package/esm/types/5_chat_list_item.d.ts +35 -0
  72. package/esm/types/5_chat_list_item.js +86 -0
  73. package/esm/types/6_update.d.ts +14 -5
  74. package/esm/types/_file_id.d.ts +1 -0
  75. package/esm/utilities/0_bigint.d.ts +1 -0
  76. package/esm/utilities/0_bigint.js +7 -3
  77. package/package.json +1 -1
  78. package/script/3_types.d.ts +6 -1
  79. package/script/3_types.js +6 -1
  80. package/script/4_errors.js +2 -4
  81. package/script/5_client.d.ts +1 -1
  82. package/script/5_client.js +1 -1
  83. package/script/client/0_params.d.ts +33 -7
  84. package/script/client/0_storage_operations.d.ts +182 -0
  85. package/script/client/0_storage_operations.js +615 -0
  86. package/script/client/1_composer.d.ts +2 -0
  87. package/script/client/1_composer.js +28 -0
  88. package/{esm/client/0_types.d.ts → script/client/1_types.d.ts} +3 -3
  89. package/{esm/client/1_account_manager.d.ts → script/client/2_account_manager.d.ts} +1 -1
  90. package/{esm/client/1_bot_info_manager.d.ts → script/client/2_bot_info_manager.d.ts} +1 -1
  91. package/script/client/{1_business_connection_manager.d.ts → 2_business_connection_manager.d.ts} +1 -1
  92. package/{esm/client/1_file_manager.d.ts → script/client/2_file_manager.d.ts} +6 -2
  93. package/script/client/{1_file_manager.js → 2_file_manager.js} +54 -51
  94. package/script/client/{1_network_statistics_manager.d.ts → 2_network_statistics_manager.d.ts} +1 -1
  95. package/{esm/client/1_reaction_manager.d.ts → script/client/2_reaction_manager.d.ts} +1 -1
  96. package/{esm/client/1_update_manager.d.ts → script/client/2_update_manager.d.ts} +1 -1
  97. package/script/client/{2_message_manager.d.ts → 3_message_manager.d.ts} +2 -2
  98. package/script/client/3_video_chat_manager.d.ts +43 -0
  99. package/script/client/3_video_chat_manager.js +198 -0
  100. package/script/client/{3_callback_query_manager.d.ts → 4_callback_query_manager.d.ts} +2 -2
  101. package/script/client/{3_callback_query_manager.js → 4_callback_query_manager.js} +1 -0
  102. package/{esm/client/3_chat_list_manager.d.ts → script/client/4_chat_list_manager.d.ts} +6 -6
  103. package/script/client/{3_chat_list_manager.js → 4_chat_list_manager.js} +72 -95
  104. package/script/client/{3_inline_query_manager.d.ts → 4_inline_query_manager.d.ts} +2 -2
  105. package/script/client/{3_inline_query_manager.js → 4_inline_query_manager.js} +1 -0
  106. package/script/client/{3_story_manager.d.ts → 4_story_manager.d.ts} +3 -3
  107. package/{esm/client/4_client.d.ts → script/client/5_client.d.ts} +105 -31
  108. package/script/client/{4_client.js → 5_client.js} +192 -93
  109. package/script/connection/0_connection.d.ts +6 -15
  110. package/script/connection/0_connection.js +0 -41
  111. package/script/connection/1_connection_web_socket.d.ts +3 -2
  112. package/script/connection/1_connection_web_socket.js +7 -3
  113. package/script/mod.d.ts +1 -1
  114. package/script/mod.js +1 -1
  115. package/script/storage/0_storage.d.ts +9 -145
  116. package/script/storage/0_storage.js +0 -528
  117. package/script/storage/2_storage_indexed_db.d.ts +3 -2
  118. package/script/storage/2_storage_indexed_db.js +9 -8
  119. package/script/storage/2_storage_local_storage.d.ts +3 -2
  120. package/script/storage/2_storage_local_storage.js +5 -4
  121. package/script/storage/2_storage_memory.d.ts +4 -4
  122. package/script/storage/2_storage_memory.js +12 -19
  123. package/script/storage/2_storage_session_storage.d.ts +2 -1
  124. package/script/storage/2_storage_session_storage.js +5 -4
  125. package/script/tl/3_utilities.d.ts +1 -1
  126. package/script/tl/3_utilities.js +3 -3
  127. package/script/types/0_birthday.d.ts +27 -0
  128. package/script/types/0_birthday.js +30 -0
  129. package/script/types/0_giveaway_parameters.d.ts +1 -1
  130. package/script/types/0_id.d.ts +1 -1
  131. package/script/types/0_live_stream_channel.d.ts +30 -0
  132. package/script/types/0_live_stream_channel.js +30 -0
  133. package/script/types/0_opening_hours.d.ts +25 -0
  134. package/script/types/0_opening_hours.js +29 -0
  135. package/script/types/0_video_chat.d.ts +60 -0
  136. package/script/types/0_video_chat.js +57 -0
  137. package/script/types/1_chat_p.d.ts +4 -0
  138. package/script/types/1_chat_p.js +1 -0
  139. package/script/types/2_business_connection.d.ts +6 -0
  140. package/script/types/2_chat.d.ts +62 -0
  141. package/script/types/2_chat.js +70 -0
  142. package/script/types/2_inactive_chat.d.ts +1 -1
  143. package/script/types/2_invite_link.d.ts +1 -1
  144. package/script/types/2_message_reaction_count.d.ts +1 -1
  145. package/script/types/2_message_reactions.d.ts +1 -1
  146. package/script/types/3_chat_member_updated.d.ts +1 -1
  147. package/script/types/4_message.d.ts +3 -3
  148. package/script/types/5_chat_list_item.d.ts +35 -0
  149. package/script/types/5_chat_list_item.js +94 -0
  150. package/script/types/6_update.d.ts +14 -5
  151. package/script/types/_file_id.d.ts +1 -0
  152. package/script/utilities/0_bigint.d.ts +1 -0
  153. package/script/utilities/0_bigint.js +7 -3
  154. package/esm/types/5_chat.d.ts +0 -59
  155. package/esm/types/5_chat.js +0 -126
  156. package/script/types/5_chat.d.ts +0 -59
  157. package/script/types/5_chat.js +0 -134
  158. /package/esm/{3_storage.d.ts → 2_storage.d.ts} +0 -0
  159. /package/esm/{3_storage.js → 2_storage.js} +0 -0
  160. /package/esm/client/{0_types.js → 1_types.js} +0 -0
  161. /package/esm/client/{1_account_manager.js → 2_account_manager.js} +0 -0
  162. /package/esm/client/{1_bot_info_manager.js → 2_bot_info_manager.js} +0 -0
  163. /package/esm/client/{1_business_connection_manager.js → 2_business_connection_manager.js} +0 -0
  164. /package/esm/client/{1_network_statistics_manager.js → 2_network_statistics_manager.js} +0 -0
  165. /package/esm/client/{1_reaction_manager.js → 2_reaction_manager.js} +0 -0
  166. /package/esm/client/{1_update_manager.js → 2_update_manager.js} +0 -0
  167. /package/esm/client/{2_message_manager.js → 3_message_manager.js} +0 -0
  168. /package/esm/client/{3_story_manager.js → 4_story_manager.js} +0 -0
  169. /package/script/{3_storage.d.ts → 2_storage.d.ts} +0 -0
  170. /package/script/{3_storage.js → 2_storage.js} +0 -0
  171. /package/script/client/{0_types.js → 1_types.js} +0 -0
  172. /package/script/client/{1_account_manager.js → 2_account_manager.js} +0 -0
  173. /package/script/client/{1_bot_info_manager.js → 2_bot_info_manager.js} +0 -0
  174. /package/script/client/{1_business_connection_manager.js → 2_business_connection_manager.js} +0 -0
  175. /package/script/client/{1_network_statistics_manager.js → 2_network_statistics_manager.js} +0 -0
  176. /package/script/client/{1_reaction_manager.js → 2_reaction_manager.js} +0 -0
  177. /package/script/client/{1_update_manager.js → 2_update_manager.js} +0 -0
  178. /package/script/client/{2_message_manager.js → 3_message_manager.js} +0 -0
  179. /package/script/client/{3_story_manager.js → 4_story_manager.js} +0 -0
@@ -28,32 +28,35 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
28
28
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
29
29
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
30
  };
31
- var _Client_instances, _a, _Client_client, _Client_guaranteeUpdateDelivery, _Client_updateManager, _Client_networkStatisticsManager, _Client_botInfoManager, _Client_fileManager, _Client_reactionManager, _Client_businessConnectionManager, _Client_messageManager, _Client_storyManager, _Client_callbackQueryManager, _Client_inlineQueryManager, _Client_chatListManager, _Client_accountManager, _Client_parseMode, _Client_publicKeys, _Client_ignoreOutgoing, _Client_storeMessages, _Client_Lauthorize, _Client_LpingLoop, _Client_LhandleMigrationError, _Client_L$initConncetion, _Client_namespaceProxies, _Client_getApiId, _Client_getCdnConnectionPool, _Client_getCdnConnection, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_stateChangeHandler, _Client_storageInited, _Client_initStorage, _Client_connectionInited, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_getSelfId, _Client_pingLoopStarted, _Client_pingLoopAbortController, _Client_pingInterval, _Client_lastUpdates, _Client_startPingLoop, _Client_pingLoop, _Client_invoke, _Client_handleInvokeError, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_lastGetMe, _Client_getMe;
31
+ var _Client_instances, _a, _Client_client, _Client_guaranteeUpdateDelivery, _Client_updateManager, _Client_networkStatisticsManager, _Client_botInfoManager, _Client_fileManager, _Client_reactionManager, _Client_videoChatManager, _Client_businessConnectionManager, _Client_messageManager, _Client_storyManager, _Client_callbackQueryManager, _Client_inlineQueryManager, _Client_chatListManager, _Client_accountManager, _Client_storage_, _Client_messageStorage_, _Client_parseMode, _Client_apiId, _Client_apiHash, _Client_publicKeys, _Client_ignoreOutgoing, _Client_persistCache, _Client_LsignIn, _Client_LpingLoop, _Client_LhandleMigrationError, _Client_L$initConncetion, _Client_namespaceProxies, _Client_getApiId, _Client_getCdnConnectionPool, _Client_getCdnConnection, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_stateChangeHandler, _Client_storageInited, _Client_initStorage, _Client_connectionInited, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_getSelfId, _Client_pingLoopStarted, _Client_pingLoopAbortController, _Client_pingInterval, _Client_lastUpdates, _Client_startPingLoop, _Client_pingLoop, _Client_invoke, _Client_handleInvokeError, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_lastGetMe, _Client_getMe;
32
32
  import { unreachable } from "../0_deps.js";
33
33
  import { AccessError, InputError } from "../0_errors.js";
34
34
  import { cleanObject, drop, getLogger, getRandomId, minute, mustPrompt, mustPromptOneOf, second, ZERO_CHANNEL_ID } from "../1_utilities.js";
35
35
  import { as, chatIdToPeerId, functions, getChatIdPeerType, name, peerToChatId, types } from "../2_tl.js";
36
- import { StorageMemory } from "../3_storage.js";
36
+ import { StorageMemory } from "../2_storage.js";
37
37
  import { constructUser } from "../3_types.js";
38
38
  import { APP_VERSION, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL } from "../4_constants.js";
39
39
  import { AuthKeyUnregistered, ConnectionNotInited, FloodWait, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded } from "../4_errors.js";
40
40
  import { checkPassword } from "./0_password.js";
41
41
  import { getUsername, isMtprotoFunction, resolve } from "./0_utilities.js";
42
- import { AccountManager } from "./1_account_manager.js";
43
- import { BotInfoManager } from "./1_bot_info_manager.js";
44
- import { BusinessConnectionManager } from "./1_business_connection_manager.js";
42
+ import { AccountManager } from "./2_account_manager.js";
43
+ import { BotInfoManager } from "./2_bot_info_manager.js";
44
+ import { BusinessConnectionManager } from "./2_business_connection_manager.js";
45
45
  import { ClientEncrypted } from "./1_client_encrypted.js";
46
46
  import { ClientPlain } from "./1_client_plain.js";
47
47
  import { Composer as Composer_ } from "./1_composer.js";
48
- import { FileManager } from "./1_file_manager.js";
49
- import { NetworkStatisticsManager } from "./1_network_statistics_manager.js";
50
- import { ReactionManager } from "./1_reaction_manager.js";
51
- import { UpdateManager } from "./1_update_manager.js";
52
- import { MessageManager } from "./2_message_manager.js";
53
- import { CallbackQueryManager } from "./3_callback_query_manager.js";
54
- import { ChatListManager } from "./3_chat_list_manager.js";
55
- import { InlineQueryManager } from "./3_inline_query_manager.js";
56
- import { StoryManager } from "./3_story_manager.js";
48
+ import { FileManager } from "./2_file_manager.js";
49
+ import { NetworkStatisticsManager } from "./2_network_statistics_manager.js";
50
+ import { ReactionManager } from "./2_reaction_manager.js";
51
+ import { UpdateManager } from "./2_update_manager.js";
52
+ import { MessageManager } from "./3_message_manager.js";
53
+ import { CallbackQueryManager } from "./4_callback_query_manager.js";
54
+ import { ChatListManager } from "./4_chat_list_manager.js";
55
+ import { InlineQueryManager } from "./4_inline_query_manager.js";
56
+ import { StoryManager } from "./4_story_manager.js";
57
+ import { VideoChatManager } from "./3_video_chat_manager.js";
58
+ import { StorageOperations } from "./0_storage_operations.js";
59
+ import { PhoneCodeInvalid } from "../4_errors.js";
57
60
  export class Composer extends Composer_ {
58
61
  }
59
62
  function skipInvoke() {
@@ -76,21 +79,9 @@ export class Client extends Composer {
76
79
  * @param apiId App's API ID from [my.telegram.org](https://my.telegram.org/apps). Defaults to 0 (unset).
77
80
  * @param apiHash App's API hash from [my.telegram.org/apps](https://my.telegram.org/apps). Defaults to empty string (unset).
78
81
  */
79
- constructor(storage, apiId = 0, apiHash = "", params) {
82
+ constructor(params) {
80
83
  super();
81
84
  _Client_instances.add(this);
82
- Object.defineProperty(this, "apiId", {
83
- enumerable: true,
84
- configurable: true,
85
- writable: true,
86
- value: apiId
87
- });
88
- Object.defineProperty(this, "apiHash", {
89
- enumerable: true,
90
- configurable: true,
91
- writable: true,
92
- value: apiHash
93
- });
94
85
  _Client_client.set(this, void 0);
95
86
  _Client_guaranteeUpdateDelivery.set(this, void 0);
96
87
  _Client_updateManager.set(this, void 0);
@@ -98,6 +89,7 @@ export class Client extends Composer {
98
89
  _Client_botInfoManager.set(this, void 0);
99
90
  _Client_fileManager.set(this, void 0);
100
91
  _Client_reactionManager.set(this, void 0);
92
+ _Client_videoChatManager.set(this, void 0);
101
93
  _Client_businessConnectionManager.set(this, void 0);
102
94
  _Client_messageManager.set(this, void 0);
103
95
  _Client_storyManager.set(this, void 0);
@@ -105,6 +97,8 @@ export class Client extends Composer {
105
97
  _Client_inlineQueryManager.set(this, void 0);
106
98
  _Client_chatListManager.set(this, void 0);
107
99
  _Client_accountManager.set(this, void 0);
100
+ _Client_storage_.set(this, void 0);
101
+ _Client_messageStorage_.set(this, void 0);
108
102
  Object.defineProperty(this, "storage", {
109
103
  enumerable: true,
110
104
  configurable: true,
@@ -118,6 +112,8 @@ export class Client extends Composer {
118
112
  value: void 0
119
113
  });
120
114
  _Client_parseMode.set(this, void 0);
115
+ _Client_apiId.set(this, void 0);
116
+ _Client_apiHash.set(this, void 0);
121
117
  Object.defineProperty(this, "appVersion", {
122
118
  enumerable: true,
123
119
  configurable: true,
@@ -156,8 +152,8 @@ export class Client extends Composer {
156
152
  });
157
153
  _Client_publicKeys.set(this, void 0);
158
154
  _Client_ignoreOutgoing.set(this, void 0);
159
- _Client_storeMessages.set(this, void 0);
160
- _Client_Lauthorize.set(this, void 0);
155
+ _Client_persistCache.set(this, void 0);
156
+ _Client_LsignIn.set(this, void 0);
161
157
  _Client_LpingLoop.set(this, void 0);
162
158
  _Client_LhandleMigrationError.set(this, void 0);
163
159
  _Client_L$initConncetion.set(this, void 0);
@@ -258,9 +254,9 @@ export class Client extends Composer {
258
254
  }
259
255
  unreachable();
260
256
  };
261
- const chat_ = "messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : undefined;
257
+ const chat_ = "messageReactions" in update ? update.messageReactions.chat : "messageReactionCount" in update ? update.messageReactionCount.chat : "chatMember" in update ? update.chatMember.chat : undefined;
262
258
  const chat = chat_ ?? msg?.chat;
263
- const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "message" in update ? update.message.from : "editedMessage" in update ? update.editedMessage?.from : undefined;
259
+ const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "message" in update ? update.message.from : "editedMessage" in update ? update.editedMessage?.from : "chatMember" in update ? update.chatMember.from : "messageReactions" in update ? update.messageReactions.user : undefined;
264
260
  const senderChat = msg?.senderChat;
265
261
  const getReplyToMessageId = (quote, chatId, messageId) => {
266
262
  const isPrivate = chatId > 0;
@@ -636,14 +632,18 @@ export class Client extends Composer {
636
632
  }
637
633
  },
638
634
  };
639
- this.storage = typeof storage === "string" ? new StorageMemory(storage) : storage ?? new StorageMemory();
640
- __classPrivateFieldSet(this, _Client_storeMessages, params?.storeMessages ?? false, "f");
641
- if (!__classPrivateFieldGet(this, _Client_storeMessages, "f")) {
642
- this.messageStorage = new StorageMemory();
635
+ __classPrivateFieldSet(this, _Client_apiId, params?.apiId ?? 0, "f");
636
+ __classPrivateFieldSet(this, _Client_apiHash, params?.apiHash ?? "", "f");
637
+ __classPrivateFieldSet(this, _Client_storage_, params?.storage || new StorageMemory(), "f");
638
+ __classPrivateFieldSet(this, _Client_persistCache, params?.persistCache ?? false, "f");
639
+ if (!__classPrivateFieldGet(this, _Client_persistCache, "f")) {
640
+ __classPrivateFieldSet(this, _Client_messageStorage_, new StorageMemory(), "f");
643
641
  }
644
642
  else {
645
- this.messageStorage = this.storage;
643
+ __classPrivateFieldSet(this, _Client_messageStorage_, __classPrivateFieldGet(this, _Client_storage_, "f"), "f");
646
644
  }
645
+ this.storage = new StorageOperations(__classPrivateFieldGet(this, _Client_storage_, "f"));
646
+ this.messageStorage = new StorageOperations(__classPrivateFieldGet(this, _Client_messageStorage_, "f"));
647
647
  __classPrivateFieldSet(this, _Client_parseMode, params?.parseMode ?? null, "f");
648
648
  this.appVersion = params?.appVersion ?? APP_VERSION;
649
649
  this.deviceModel = params?.deviceModel ?? DEVICE_MODEL;
@@ -658,7 +658,7 @@ export class Client extends Composer {
658
658
  }
659
659
  __classPrivateFieldSet(this, _Client_guaranteeUpdateDelivery, params?.guaranteeUpdateDelivery ?? false, "f");
660
660
  const L = getLogger("Client").client(id++);
661
- __classPrivateFieldSet(this, _Client_Lauthorize, L.branch("authorize"), "f");
661
+ __classPrivateFieldSet(this, _Client_LsignIn, L.branch("signIn"), "f");
662
662
  __classPrivateFieldSet(this, _Client_LpingLoop, L.branch("pingLoop"), "f");
663
663
  __classPrivateFieldSet(this, _Client_LhandleMigrationError, L.branch("[handleMigrationError]"), "f");
664
664
  __classPrivateFieldSet(this, _Client_L$initConncetion, L.branch("#initConnection"), "f");
@@ -697,6 +697,7 @@ export class Client extends Composer {
697
697
  __classPrivateFieldSet(this, _Client_fileManager, new FileManager(c), "f");
698
698
  __classPrivateFieldSet(this, _Client_reactionManager, new ReactionManager(c), "f");
699
699
  __classPrivateFieldSet(this, _Client_businessConnectionManager, new BusinessConnectionManager(c), "f");
700
+ __classPrivateFieldSet(this, _Client_videoChatManager, new VideoChatManager({ ...c, fileManager: __classPrivateFieldGet(this, _Client_fileManager, "f") }), "f");
700
701
  __classPrivateFieldSet(this, _Client_messageManager, new MessageManager({ ...c, fileManager: __classPrivateFieldGet(this, _Client_fileManager, "f") }), "f");
701
702
  __classPrivateFieldSet(this, _Client_callbackQueryManager, new CallbackQueryManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
702
703
  __classPrivateFieldSet(this, _Client_storyManager, new StoryManager({ ...c, fileManager: __classPrivateFieldGet(this, _Client_fileManager, "f"), messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
@@ -811,10 +812,10 @@ export class Client extends Composer {
811
812
  }
812
813
  await this.connect();
813
814
  }
814
- async [(_Client_client = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_networkStatisticsManager = new WeakMap(), _Client_botInfoManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_businessConnectionManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_storyManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_accountManager = new WeakMap(), _Client_parseMode = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_storeMessages = new WeakMap(), _Client_Lauthorize = new WeakMap(), _Client_LpingLoop = new WeakMap(), _Client_LhandleMigrationError = new WeakMap(), _Client_L$initConncetion = new WeakMap(), _Client_namespaceProxies = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_stateChangeHandler = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_pingLoopAbortController = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_instances = new WeakSet(), _Client_getApiId = async function _Client_getApiId() {
815
- const apiId = this.apiId || await this.storage.getApiId();
815
+ async [(_Client_client = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_networkStatisticsManager = new WeakMap(), _Client_botInfoManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_videoChatManager = new WeakMap(), _Client_businessConnectionManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_storyManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_accountManager = new WeakMap(), _Client_storage_ = new WeakMap(), _Client_messageStorage_ = new WeakMap(), _Client_parseMode = new WeakMap(), _Client_apiId = new WeakMap(), _Client_apiHash = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_persistCache = new WeakMap(), _Client_LsignIn = new WeakMap(), _Client_LpingLoop = new WeakMap(), _Client_LhandleMigrationError = new WeakMap(), _Client_L$initConncetion = new WeakMap(), _Client_namespaceProxies = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_stateChangeHandler = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_pingLoopAbortController = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_instances = new WeakSet(), _Client_getApiId = async function _Client_getApiId() {
816
+ const apiId = __classPrivateFieldGet(this, _Client_apiId, "f") || await this.storage.getApiId();
816
817
  if (!apiId) {
817
- throw new Error("apiId not set");
818
+ throw new InputError("apiId not set");
818
819
  }
819
820
  return apiId;
820
821
  }, _Client_getCdnConnectionPool = function _Client_getCdnConnectionPool(connectionCount, dcId) {
@@ -843,7 +844,11 @@ export class Client extends Composer {
843
844
  },
844
845
  };
845
846
  }, _Client_getCdnConnection = function _Client_getCdnConnection(dcId) {
846
- const client = new _a((!dcId || dcId == __classPrivateFieldGet(this, _Client_client, "f").dcId) ? this.storage : this.storage.branch(`download_client_${dcId}`), this.apiId, this.apiHash, {
847
+ const provider = this.storage.provider;
848
+ const client = new _a({
849
+ storage: (!dcId || dcId == __classPrivateFieldGet(this, _Client_client, "f").dcId) ? provider : provider.branch(`download_client_${dcId}`),
850
+ apiId: __classPrivateFieldGet(this, _Client_apiId, "f"),
851
+ apiHash: __classPrivateFieldGet(this, _Client_apiHash, "f"),
847
852
  transportProvider: __classPrivateFieldGet(this, _Client_client, "f").transportProvider,
848
853
  appVersion: this.appVersion,
849
854
  deviceModel: this.deviceModel,
@@ -908,25 +913,19 @@ export class Client extends Composer {
908
913
  __classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.abort();
909
914
  }
910
915
  /**
911
- * Authorizes the client with one of the following:
912
- *
913
- * - Bot token (`string`)
914
- * - User authorization handlers (`AuthorizeUserParams`)
915
- *
916
- * if the current auth key doesn't throw AUTH_KEY_UNREGISTERED when calling [updates.getState](1).
916
+ * Signs in using the provided parameters if not already signed in.
917
+ * If no parameters are provided, the credentials will be prompted in runtime.
917
918
  *
918
919
  * Notes:
919
920
  * 1. Requires the `apiId` and `apiHash` paramters to be passed when constructing the client.
920
- * 2. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
921
- *
922
- * [1]: https://core.telegram.org/method/updates.getState
921
+ * 3. Reconnects the client to the appropriate DC in case of MIGRATE_X errors.
923
922
  */
924
- async authorize(params) {
923
+ async signIn(params) {
925
924
  try {
926
- await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
925
+ await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("signIn");
927
926
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
928
- drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("authorize"));
929
- __classPrivateFieldGet(this, _Client_Lauthorize, "f").debug("already authorized");
927
+ drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("signIn"));
928
+ __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("already signed in");
930
929
  return;
931
930
  }
932
931
  catch (err) {
@@ -935,23 +934,23 @@ export class Client extends Composer {
935
934
  }
936
935
  }
937
936
  const apiId = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getApiId).call(this);
938
- if (!this.apiHash) {
939
- throw new Error("apiHash not set");
937
+ if (!__classPrivateFieldGet(this, _Client_apiHash, "f")) {
938
+ throw new InputError("apiHash not set");
940
939
  }
941
940
  if (typeof params === "undefined") {
942
941
  const loginType = mustPromptOneOf("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
943
942
  if (loginType == "b") {
944
- params = mustPrompt("Bot token:");
943
+ params = { botToken: mustPrompt("Bot token:") };
945
944
  }
946
945
  else {
947
946
  params = { phone: () => mustPrompt("Phone number:"), code: () => mustPrompt("Verification code:"), password: () => mustPrompt("Password:") };
948
947
  }
949
948
  }
950
- __classPrivateFieldGet(this, _Client_Lauthorize, "f").debug("authorizing with", typeof params === "string" ? "bot token" : params instanceof types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
951
- if (typeof params === "string") {
949
+ __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("authorizing with", typeof params === "string" ? "bot token" : params instanceof types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
950
+ if (params && "botToken" in params) {
952
951
  while (true) {
953
952
  try {
954
- const auth = await this.api.auth.importBotAuthorization({ api_id: apiId, api_hash: this.apiHash, bot_auth_token: params, flags: 0 });
953
+ const auth = await this.api.auth.importBotAuthorization({ api_id: apiId, api_hash: __classPrivateFieldGet(this, _Client_apiHash, "f"), bot_auth_token: params.botToken, flags: 0 });
955
954
  await this.storage.setAccountId(Number(auth[as](types.auth.Authorization).user.id));
956
955
  await this.storage.setAccountType("bot");
957
956
  break;
@@ -966,7 +965,7 @@ export class Client extends Composer {
966
965
  }
967
966
  }
968
967
  }
969
- __classPrivateFieldGet(this, _Client_Lauthorize, "f").debug("authorized as bot");
968
+ __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("authorized as bot");
970
969
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
971
970
  await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
972
971
  return;
@@ -980,8 +979,8 @@ export class Client extends Composer {
980
979
  phone = typeof params.phone === "string" ? params.phone : await params.phone();
981
980
  const sendCode = () => this.api.auth.sendCode({
982
981
  phone_number: phone,
983
- api_id: this.apiId,
984
- api_hash: this.apiHash,
982
+ api_id: __classPrivateFieldGet(this, _Client_apiId, "f"),
983
+ api_hash: __classPrivateFieldGet(this, _Client_apiHash, "f"),
985
984
  settings: new types.CodeSettings(),
986
985
  }).then((v) => v[as](types.auth.SentCode));
987
986
  try {
@@ -1007,7 +1006,7 @@ export class Client extends Composer {
1007
1006
  }
1008
1007
  }
1009
1008
  }
1010
- __classPrivateFieldGet(this, _Client_Lauthorize, "f").debug("verification code sent");
1009
+ __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("verification code sent");
1011
1010
  let err;
1012
1011
  code: while (true) {
1013
1012
  const code = typeof params.code === "string" ? params.code : await params.code();
@@ -1019,13 +1018,13 @@ export class Client extends Composer {
1019
1018
  });
1020
1019
  await this.storage.setAccountId(Number(auth[as](types.auth.Authorization).user.id));
1021
1020
  await this.storage.setAccountType("user");
1022
- __classPrivateFieldGet(this, _Client_Lauthorize, "f").debug("authorized as user");
1021
+ __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("signed in as user");
1023
1022
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
1024
- await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
1023
+ await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("signIn");
1025
1024
  return;
1026
1025
  }
1027
1026
  catch (err_) {
1028
- if (err_ instanceof types.Rpc_error && err_.error_message == "PHONE_CODE_INVALID") {
1027
+ if (err_ instanceof PhoneCodeInvalid) {
1029
1028
  continue code;
1030
1029
  }
1031
1030
  else {
@@ -1048,9 +1047,9 @@ export class Client extends Composer {
1048
1047
  const auth = await this.api.auth.checkPassword({ password: input });
1049
1048
  await this.storage.setAccountId(Number(auth[as](types.auth.Authorization).user.id));
1050
1049
  await this.storage.setAccountType("user");
1051
- __classPrivateFieldGet(this, _Client_Lauthorize, "f").debug("authorized as user");
1050
+ __classPrivateFieldGet(this, _Client_LsignIn, "f").debug("signed in as user");
1052
1051
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
1053
- await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
1052
+ await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("signIn");
1054
1053
  return;
1055
1054
  }
1056
1055
  catch (err) {
@@ -1073,12 +1072,26 @@ export class Client extends Composer {
1073
1072
  }
1074
1073
  }
1075
1074
  }
1075
+ async signOut() {
1076
+ try {
1077
+ await Promise.all([
1078
+ this.storage.reset(),
1079
+ this.api.auth.logOut().then(() => {
1080
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, false);
1081
+ }),
1082
+ ]);
1083
+ }
1084
+ finally {
1085
+ __classPrivateFieldSet(this, _Client_lastGetMe, null, "f");
1086
+ await this.reconnect();
1087
+ }
1088
+ }
1076
1089
  /**
1077
- * Same as calling `.connect()` followed by `.authorize(params)`.
1090
+ * Same as calling `.connect()` followed by `.signIn(params)`.
1078
1091
  */
1079
1092
  async start(params) {
1080
1093
  await this.connect();
1081
- await this.authorize(params);
1094
+ await this.signIn(params);
1082
1095
  }
1083
1096
  /**
1084
1097
  * Alias for `invoke` with its second parameter being `true`.
@@ -1087,7 +1100,7 @@ export class Client extends Composer {
1087
1100
  return this.invoke(function_, true);
1088
1101
  }
1089
1102
  exportAuthString() {
1090
- return this.storage.exportAuthString(this.apiId);
1103
+ return this.storage.exportAuthString(__classPrivateFieldGet(this, _Client_apiId, "f"));
1091
1104
  }
1092
1105
  async importAuthString(authString) {
1093
1106
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initStorage).call(this);
@@ -1103,7 +1116,7 @@ export class Client extends Composer {
1103
1116
  return new types.InputPeerSelf();
1104
1117
  }
1105
1118
  const inputPeer = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getInputPeerInner).call(this, id);
1106
- if ((inputPeer instanceof types.InputPeerUser || inputPeer instanceof types.InputPeerChannel && inputPeer.access_hash == 0n) && await this.storage.getAccountType() == "bot") {
1119
+ if (((inputPeer instanceof types.InputPeerUser || inputPeer instanceof types.InputPeerChannel) && inputPeer.access_hash == 0n) && await this.storage.getAccountType() == "bot") {
1107
1120
  if ("channel_id" in inputPeer) {
1108
1121
  inputPeer.access_hash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChannelAccessHash).call(this, inputPeer.channel_id);
1109
1122
  }
@@ -2290,6 +2303,89 @@ export class Client extends Composer {
2290
2303
  async unblockUser(userId) {
2291
2304
  await __classPrivateFieldGet(this, _Client_messageManager, "f").unblockUser(userId);
2292
2305
  }
2306
+ //
2307
+ // ========================= VIDEO CHATS ========================= //
2308
+ //
2309
+ /**
2310
+ * Start a video chat. User-only.
2311
+ *
2312
+ * @method vc
2313
+ * @param chatId The chat to start the video chat in.
2314
+ * @returns The started video chat.
2315
+ */
2316
+ async startVideoChat(chatId, params) {
2317
+ return await __classPrivateFieldGet(this, _Client_videoChatManager, "f").startVideoChat(chatId, params);
2318
+ }
2319
+ /**
2320
+ * Schedule a video chat. User-only.
2321
+ *
2322
+ * @method vc
2323
+ * @param chatId The chat to schedule the video chat in.
2324
+ * @param startAt A point in time within the future in which the video chat will be started.
2325
+ * @returns The scheduled video chat.
2326
+ */
2327
+ async scheduleVideoChat(chatId, startAt, params) {
2328
+ return await __classPrivateFieldGet(this, _Client_videoChatManager, "f").scheduleVideoChat(chatId, startAt, params);
2329
+ }
2330
+ /**
2331
+ * Join a video chat. User-only.
2332
+ *
2333
+ * @method vc
2334
+ * @param id The identifier of a video chat retrieved from getChat, startVideoChat, or scheduleVideoChat.
2335
+ * @param params_ WebRTC connection parameters.
2336
+ * @returns Parameters to be passed to the used WebRTC library.
2337
+ */
2338
+ async joinVideoChat(id, params_, params) {
2339
+ return await __classPrivateFieldGet(this, _Client_videoChatManager, "f").joinVideoChat(id, params_, params);
2340
+ }
2341
+ /**
2342
+ * Leave a video chat. User-only.
2343
+ *
2344
+ * @method vc
2345
+ * @param id The identifier of a video chat retrieved from getChat, startVideoChat, or scheduleVideoChat.
2346
+ */
2347
+ async leaveVideoChat(id) {
2348
+ return await __classPrivateFieldGet(this, _Client_videoChatManager, "f").leaveVideoChat(id);
2349
+ }
2350
+ /**
2351
+ * Join a live stream. User-only.
2352
+ *
2353
+ * @method vc
2354
+ * @param id The identifier of a video chat retrieved from getChat, startVideoChat, or scheduleVideoChat.
2355
+ */
2356
+ async joinLiveStream(id) {
2357
+ return await __classPrivateFieldGet(this, _Client_videoChatManager, "f").joinLiveStream(id);
2358
+ }
2359
+ /**
2360
+ * Get a video chat. User-only.
2361
+ *
2362
+ * @method vc
2363
+ * @param id The identifier of a video chat retrieved from getChat, startVideoChat, or scheduleVideoChat.
2364
+ */
2365
+ async getVideoChat(id) {
2366
+ return await __classPrivateFieldGet(this, _Client_videoChatManager, "f").getVideoChat(id);
2367
+ }
2368
+ /**
2369
+ * Get live stream channels. User-only.
2370
+ *
2371
+ * @method vc
2372
+ * @param id The identifier of a video chat retrieved from getChat, startVideoChat, or scheduleVideoChat.
2373
+ */
2374
+ async getLiveStreamChannels(id) {
2375
+ return await __classPrivateFieldGet(this, _Client_videoChatManager, "f").getLiveStreamChannels(id);
2376
+ }
2377
+ /**
2378
+ * Download a live stream chunk. User-only.
2379
+ *
2380
+ * @method vc
2381
+ * @param id The identifier of a video chat retrieved from getChat, startVideoChat, or scheduleVideoChat.
2382
+ * @param channelId Stream channel ID.
2383
+ * @param scale Stream channel scale.
2384
+ * @param timestamp Millisecond timestamp of the chunk to download.
2385
+ */
2386
+ async *downloadLiveStreamChunk(id, channelId, scale, timestamp, params) {
2387
+ yield* __classPrivateFieldGet(this, _Client_videoChatManager, "f").downloadLiveStreamChunk(id, channelId, scale, timestamp, params);
2388
+ }
2293
2389
  }
2294
2390
  _a = Client, _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
2295
2391
  await this.middleware()(await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
@@ -2328,6 +2424,9 @@ _a = Client, _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(up
2328
2424
  })());
2329
2425
  }
2330
2426
  }
2427
+ if (VideoChatManager.canHandleUpdate(update)) {
2428
+ promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, await __classPrivateFieldGet(this, _Client_videoChatManager, "f").handleUpdate(update)));
2429
+ }
2331
2430
  if (CallbackQueryManager.canHandleUpdate(update)) {
2332
2431
  promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, await __classPrivateFieldGet(this, _Client_callbackQueryManager, "f").handleUpdate(update)));
2333
2432
  }
@@ -18,24 +18,15 @@
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
20
  import { MaybePromise } from "../1_utilities.js";
21
- declare abstract class Foundation {
22
- abstract get connected(): boolean;
21
+ export interface Connection {
22
+ get connected(): boolean;
23
23
  stateChangeHandler?: (connected: boolean) => void;
24
- abstract open(): MaybePromise<void>;
25
- abstract write(p: Uint8Array): MaybePromise<void>;
26
- abstract close(): MaybePromise<void>;
24
+ open(): MaybePromise<void>;
25
+ write(p: Uint8Array): MaybePromise<void>;
26
+ close(): MaybePromise<void>;
27
27
  callback?: {
28
28
  read(count: number): void;
29
29
  write(count: number): void;
30
30
  };
31
+ read(p: Uint8Array): MaybePromise<void>;
31
32
  }
32
- export declare abstract class ConnectionUnframed extends Foundation {
33
- readonly type: "framed";
34
- abstract read(p: Uint8Array): MaybePromise<void>;
35
- }
36
- export declare abstract class ConnectionFramed extends Foundation {
37
- readonly type: "framed";
38
- abstract read(): MaybePromise<Uint8Array>;
39
- }
40
- export type Connection = ConnectionUnframed | ConnectionFramed;
41
- export {};
@@ -17,41 +17,4 @@
17
17
  * You should have received a copy of the GNU Lesser General Public License
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
- class Foundation {
21
- constructor() {
22
- Object.defineProperty(this, "stateChangeHandler", {
23
- enumerable: true,
24
- configurable: true,
25
- writable: true,
26
- value: void 0
27
- });
28
- Object.defineProperty(this, "callback", {
29
- enumerable: true,
30
- configurable: true,
31
- writable: true,
32
- value: void 0
33
- });
34
- }
35
- }
36
- export class ConnectionUnframed extends Foundation {
37
- constructor() {
38
- super(...arguments);
39
- Object.defineProperty(this, "type", {
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- value: "framed"
44
- });
45
- }
46
- }
47
- export class ConnectionFramed extends Foundation {
48
- constructor() {
49
- super(...arguments);
50
- Object.defineProperty(this, "type", {
51
- enumerable: true,
52
- configurable: true,
53
- writable: true,
54
- value: "framed"
55
- });
56
- }
57
- }
20
+ export {};
@@ -1,7 +1,8 @@
1
- import { ConnectionUnframed } from "./0_connection.js";
2
- export declare class ConnectionWebSocket extends ConnectionUnframed implements ConnectionUnframed {
1
+ import { Connection } from "./0_connection.js";
2
+ export declare class ConnectionWebSocket implements Connection {
3
3
  #private;
4
4
  private readonly url;
5
+ stateChangeHandler?: Connection["stateChangeHandler"];
5
6
  constructor(url: string | URL);
6
7
  get connected(): boolean;
7
8
  open(): Promise<void>;
@@ -32,12 +32,10 @@ var _ConnectionWebSocket_instances, _ConnectionWebSocket_webSocket, _ConnectionW
32
32
  import * as dntShim from "../_dnt.shims.js";
33
33
  import { concat, unreachable } from "../0_deps.js";
34
34
  import { getLogger, Mutex } from "../1_utilities.js";
35
- import { ConnectionUnframed } from "./0_connection.js";
36
35
  const L = getLogger("ConnectionWebSocket");
37
36
  const errConnectionNotOpen = new Error("Connection not open");
38
- export class ConnectionWebSocket extends ConnectionUnframed {
37
+ export class ConnectionWebSocket {
39
38
  constructor(url) {
40
- super();
41
39
  _ConnectionWebSocket_instances.add(this);
42
40
  Object.defineProperty(this, "url", {
43
41
  enumerable: true,
@@ -50,6 +48,12 @@ export class ConnectionWebSocket extends ConnectionUnframed {
50
48
  _ConnectionWebSocket_wMutex.set(this, new Mutex());
51
49
  _ConnectionWebSocket_buffer.set(this, new Uint8Array());
52
50
  _ConnectionWebSocket_nextResolve.set(this, null);
51
+ Object.defineProperty(this, "stateChangeHandler", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
53
57
  _ConnectionWebSocket_wasConnected.set(this, false);
54
58
  _ConnectionWebSocket_isConnecting.set(this, false);
55
59
  _ConnectionWebSocket_connectionError.set(this, null);
package/esm/mod.d.ts CHANGED
@@ -21,7 +21,7 @@ export * from "./0_errors.js";
21
21
  export { getColorFromPeerId, getColorName, getRandomId, type LoggingProvider, setLoggingProvider, setLogVerbosity } from "./1_utilities.js";
22
22
  export { checkPassword } from "./client/0_password.js";
23
23
  export * from "./2_connection.js";
24
- export * from "./3_storage.js";
24
+ export * from "./2_storage.js";
25
25
  export * from "./3_transport.js";
26
26
  export * from "./2_tl.js";
27
27
  export * from "./3_types.js";
package/esm/mod.js CHANGED
@@ -21,7 +21,7 @@ export * from "./0_errors.js";
21
21
  export { getColorFromPeerId, getColorName, getRandomId, setLoggingProvider, setLogVerbosity } from "./1_utilities.js";
22
22
  export { checkPassword } from "./client/0_password.js";
23
23
  export * from "./2_connection.js";
24
- export * from "./3_storage.js";
24
+ export * from "./2_storage.js";
25
25
  export * from "./3_transport.js";
26
26
  export * from "./2_tl.js";
27
27
  export * from "./3_types.js";