@mtkruto/node 0.1.500 → 0.1.600

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 (91) hide show
  1. package/esm/3_types.d.ts +6 -1
  2. package/esm/3_types.js +6 -1
  3. package/esm/client/0_params.d.ts +28 -6
  4. package/esm/client/1_file_manager.d.ts +5 -1
  5. package/esm/client/1_file_manager.js +50 -49
  6. package/esm/client/2_video_chat_manager.d.ts +43 -0
  7. package/esm/client/2_video_chat_manager.js +194 -0
  8. package/esm/client/3_callback_query_manager.js +1 -0
  9. package/esm/client/3_chat_list_manager.d.ts +3 -3
  10. package/esm/client/3_chat_list_manager.js +75 -98
  11. package/esm/client/3_inline_query_manager.js +1 -0
  12. package/esm/client/4_client.d.ts +67 -3
  13. package/esm/client/4_client.js +92 -3
  14. package/esm/storage/0_storage.d.ts +14 -0
  15. package/esm/storage/0_storage.js +39 -2
  16. package/esm/tl/3_utilities.d.ts +1 -1
  17. package/esm/tl/3_utilities.js +3 -3
  18. package/esm/types/0_birthday.d.ts +27 -0
  19. package/esm/types/0_birthday.js +26 -0
  20. package/esm/types/0_giveaway_parameters.d.ts +1 -1
  21. package/esm/types/0_live_stream_channel.d.ts +30 -0
  22. package/esm/types/0_live_stream_channel.js +26 -0
  23. package/esm/types/0_opening_hours.d.ts +25 -0
  24. package/esm/types/0_opening_hours.js +25 -0
  25. package/esm/types/0_video_chat.d.ts +60 -0
  26. package/esm/types/0_video_chat.js +53 -0
  27. package/esm/types/1_chat_p.d.ts +4 -0
  28. package/esm/types/1_chat_p.js +1 -0
  29. package/esm/types/2_business_connection.d.ts +6 -0
  30. package/esm/types/2_chat.d.ts +62 -0
  31. package/esm/types/2_chat.js +66 -0
  32. package/esm/types/2_inactive_chat.d.ts +1 -1
  33. package/esm/types/2_invite_link.d.ts +1 -1
  34. package/esm/types/2_message_reaction_count.d.ts +1 -1
  35. package/esm/types/2_message_reactions.d.ts +1 -1
  36. package/esm/types/3_chat_member_updated.d.ts +1 -1
  37. package/esm/types/4_message.d.ts +3 -3
  38. package/esm/types/5_chat_list_item.d.ts +35 -0
  39. package/esm/types/5_chat_list_item.js +86 -0
  40. package/esm/types/6_update.d.ts +14 -5
  41. package/esm/types/_file_id.d.ts +1 -0
  42. package/esm/utilities/0_bigint.d.ts +1 -0
  43. package/esm/utilities/0_bigint.js +7 -3
  44. package/package.json +1 -1
  45. package/script/3_types.d.ts +6 -1
  46. package/script/3_types.js +6 -1
  47. package/script/client/0_params.d.ts +28 -6
  48. package/script/client/1_file_manager.d.ts +5 -1
  49. package/script/client/1_file_manager.js +50 -49
  50. package/script/client/2_video_chat_manager.d.ts +43 -0
  51. package/script/client/2_video_chat_manager.js +198 -0
  52. package/script/client/3_callback_query_manager.js +1 -0
  53. package/script/client/3_chat_list_manager.d.ts +3 -3
  54. package/script/client/3_chat_list_manager.js +72 -95
  55. package/script/client/3_inline_query_manager.js +1 -0
  56. package/script/client/4_client.d.ts +67 -3
  57. package/script/client/4_client.js +92 -3
  58. package/script/storage/0_storage.d.ts +14 -0
  59. package/script/storage/0_storage.js +39 -2
  60. package/script/tl/3_utilities.d.ts +1 -1
  61. package/script/tl/3_utilities.js +3 -3
  62. package/script/types/0_birthday.d.ts +27 -0
  63. package/script/types/0_birthday.js +30 -0
  64. package/script/types/0_giveaway_parameters.d.ts +1 -1
  65. package/script/types/0_live_stream_channel.d.ts +30 -0
  66. package/script/types/0_live_stream_channel.js +30 -0
  67. package/script/types/0_opening_hours.d.ts +25 -0
  68. package/script/types/0_opening_hours.js +29 -0
  69. package/script/types/0_video_chat.d.ts +60 -0
  70. package/script/types/0_video_chat.js +57 -0
  71. package/script/types/1_chat_p.d.ts +4 -0
  72. package/script/types/1_chat_p.js +1 -0
  73. package/script/types/2_business_connection.d.ts +6 -0
  74. package/script/types/2_chat.d.ts +62 -0
  75. package/script/types/2_chat.js +70 -0
  76. package/script/types/2_inactive_chat.d.ts +1 -1
  77. package/script/types/2_invite_link.d.ts +1 -1
  78. package/script/types/2_message_reaction_count.d.ts +1 -1
  79. package/script/types/2_message_reactions.d.ts +1 -1
  80. package/script/types/3_chat_member_updated.d.ts +1 -1
  81. package/script/types/4_message.d.ts +3 -3
  82. package/script/types/5_chat_list_item.d.ts +35 -0
  83. package/script/types/5_chat_list_item.js +94 -0
  84. package/script/types/6_update.d.ts +14 -5
  85. package/script/types/_file_id.d.ts +1 -0
  86. package/script/utilities/0_bigint.d.ts +1 -0
  87. package/script/utilities/0_bigint.js +7 -3
  88. package/esm/types/5_chat.d.ts +0 -59
  89. package/esm/types/5_chat.js +0 -126
  90. package/script/types/5_chat.d.ts +0 -59
  91. package/script/types/5_chat.js +0 -134
package/esm/3_types.d.ts CHANGED
@@ -20,6 +20,7 @@
20
20
  export * from "./types/_file_id.js";
21
21
  export * from "./types/_getters.js";
22
22
  export * from "./types/0_authorization_state.js";
23
+ export * from "./types/0_birthday.js";
23
24
  export * from "./types/0_bot_command.js";
24
25
  export * from "./types/0_callback_query_answer.js";
25
26
  export * from "./types/0_callback_query_question.js";
@@ -35,6 +36,7 @@ export * from "./types/0_giveaway_parameters.js";
35
36
  export * from "./types/0_id.js";
36
37
  export * from "./types/0_keyboard_button_poll_type.js";
37
38
  export * from "./types/0_link_preview.js";
39
+ export * from "./types/0_live_stream_channel.js";
38
40
  export * from "./types/0_location.js";
39
41
  export * from "./types/0_login_url.js";
40
42
  export * from "./types/0_mask_position.js";
@@ -43,6 +45,7 @@ export * from "./types/0_message_reference.js";
43
45
  export * from "./types/0_message_search_filter.js";
44
46
  export * from "./types/0_mini_app_info.js";
45
47
  export * from "./types/0_network_statistics_entry.js";
48
+ export * from "./types/0_opening_hours.js";
46
49
  export * from "./types/0_parse_mode.js";
47
50
  export * from "./types/0_poll_option.js";
48
51
  export * from "./types/0_price_tag.js";
@@ -51,6 +54,7 @@ export * from "./types/0_restriction_reason.js";
51
54
  export * from "./types/0_self_destruct_option.js";
52
55
  export * from "./types/0_story_reference.js";
53
56
  export * from "./types/0_thumbnail.js";
57
+ export * from "./types/0_video_chat.js";
54
58
  export * from "./types/0_voice.js";
55
59
  export * from "./types/1_animation.js";
56
60
  export * from "./types/1_audio.js";
@@ -96,6 +100,7 @@ export * from "./types/3_story.js";
96
100
  export * from "./types/4_inline_query_result.js";
97
101
  export * from "./types/4_message.js";
98
102
  export * from "./types/5_callback_query.js";
99
- export * from "./types/5_chat.js";
103
+ export * from "./types/5_chat_list_item.js";
104
+ export * from "./types/2_chat.js";
100
105
  export * from "./types/5_inline_query_answer.js";
101
106
  export * from "./types/6_update.js";
package/esm/3_types.js CHANGED
@@ -20,6 +20,7 @@
20
20
  export * from "./types/_file_id.js";
21
21
  export * from "./types/_getters.js";
22
22
  export * from "./types/0_authorization_state.js";
23
+ export * from "./types/0_birthday.js";
23
24
  export * from "./types/0_bot_command.js";
24
25
  export * from "./types/0_callback_query_answer.js";
25
26
  export * from "./types/0_callback_query_question.js";
@@ -35,6 +36,7 @@ export * from "./types/0_giveaway_parameters.js";
35
36
  export * from "./types/0_id.js";
36
37
  export * from "./types/0_keyboard_button_poll_type.js";
37
38
  export * from "./types/0_link_preview.js";
39
+ export * from "./types/0_live_stream_channel.js";
38
40
  export * from "./types/0_location.js";
39
41
  export * from "./types/0_login_url.js";
40
42
  export * from "./types/0_mask_position.js";
@@ -43,6 +45,7 @@ export * from "./types/0_message_reference.js";
43
45
  export * from "./types/0_message_search_filter.js";
44
46
  export * from "./types/0_mini_app_info.js";
45
47
  export * from "./types/0_network_statistics_entry.js";
48
+ export * from "./types/0_opening_hours.js";
46
49
  export * from "./types/0_parse_mode.js";
47
50
  export * from "./types/0_poll_option.js";
48
51
  export * from "./types/0_price_tag.js";
@@ -51,6 +54,7 @@ export * from "./types/0_restriction_reason.js";
51
54
  export * from "./types/0_self_destruct_option.js";
52
55
  export * from "./types/0_story_reference.js";
53
56
  export * from "./types/0_thumbnail.js";
57
+ export * from "./types/0_video_chat.js";
54
58
  export * from "./types/0_voice.js";
55
59
  export * from "./types/1_animation.js";
56
60
  export * from "./types/1_audio.js";
@@ -96,6 +100,7 @@ export * from "./types/3_story.js";
96
100
  export * from "./types/4_inline_query_result.js";
97
101
  export * from "./types/4_message.js";
98
102
  export * from "./types/5_callback_query.js";
99
- export * from "./types/5_chat.js";
103
+ export * from "./types/5_chat_list_item.js";
104
+ export * from "./types/2_chat.js";
100
105
  export * from "./types/5_inline_query_answer.js";
101
106
  export * from "./types/6_update.js";
@@ -18,7 +18,7 @@
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
- import { BotCommandScope, Chat, ChatMemberRights, FileSource, ID, InlineQueryResultButton, LinkPreview, Message, MessageEntity, MessageSearchFilter, ParseMode, ReplyMarkup, ReplyQuote, SelfDestructOption, StoryInteractiveArea, StoryPrivacy } from "../3_types.js";
21
+ import { BotCommandScope, ChatListItem, ChatMemberRights, FileSource, ID, InlineQueryResultButton, LinkPreview, Message, MessageEntity, MessageSearchFilter, ParseMode, ReplyMarkup, ReplyQuote, SelfDestructOption, StoryInteractiveArea, StoryPrivacy } from "../3_types.js";
22
22
  export interface AnswerCallbackQueryParams {
23
23
  /** A text to be shown to the user. */
24
24
  text?: string;
@@ -48,7 +48,7 @@ export interface _SendCommon extends _BusinessConnectionIdCommon {
48
48
  replyQuote?: ReplyQuote;
49
49
  /** The identifier of a thread to send the message to. */
50
50
  messageThreadId?: number;
51
- /** The identifier of the chat to send the message on behalf of. User-only. */
51
+ /** The identifier of a chat to send the message on behalf of. User-only. */
52
52
  sendAs?: ID;
53
53
  /** The reply markup of the message. Bot-only. */
54
54
  replyMarkup?: ReplyMarkup;
@@ -276,7 +276,7 @@ export interface GetChatsParams {
276
276
  /** The chat list to get the chats from. Defaults to main. */
277
277
  from?: "main" | "archived";
278
278
  /** The last chat to get chats after. */
279
- after?: Chat;
279
+ after?: ChatListItem;
280
280
  /** The maximum number of results to return. Must be in the range of 1-100. Defaults to 100. */
281
281
  limit?: number;
282
282
  }
@@ -287,7 +287,7 @@ export interface PinMessageParams {
287
287
  disableNotification?: boolean;
288
288
  }
289
289
  export interface BanChatMemberParams {
290
- /** A point of time in the future to automatically withdraw the ban. */
290
+ /** A point in time within the future in which the ban will be reverted. */
291
291
  untilDate?: Date;
292
292
  /** Whether to delete all of the user's messages. */
293
293
  deleteMessages?: boolean;
@@ -295,7 +295,7 @@ export interface BanChatMemberParams {
295
295
  export interface SetChatMemberRightsParams {
296
296
  /** The member's new rights. All fields default to `true` if the chat's default member rights allow. This means that this method is the same as unbanChatMember if this parameter is not provided or all of its fields are `true`. */
297
297
  rights?: ChatMemberRights;
298
- /** A point of time in the future to automatically withdraw the restrictions. */
298
+ /** A point in time within the future in which the restriction will be reverted. */
299
299
  untilDate?: Date;
300
300
  }
301
301
  export interface CreateStoryParams extends _CaptionCommon, _UploadCommon {
@@ -325,7 +325,7 @@ export interface SearchMessagesParams {
325
325
  export interface CreateInviteLinkParams {
326
326
  /** An optional title to be attached to the link that can only be seen by admins. */
327
327
  title?: string;
328
- /** The point of time in which the invite link must no longer work. */
328
+ /** A point in time within the future in which the invite link will be invalidated. */
329
329
  expireAt?: Date;
330
330
  /** The times the invite link can be used. Cannot be specified while `requireApproval` is `true`. */
331
331
  limit?: number;
@@ -359,3 +359,25 @@ export interface SendInlineQueryParams {
359
359
  query?: string;
360
360
  offset?: string;
361
361
  }
362
+ export interface StartVideoChatParams {
363
+ /** The video chat's title. */
364
+ title?: string;
365
+ /** Whether this is going to be a live stream. */
366
+ liveStream?: boolean;
367
+ }
368
+ export interface ScheduleVideoChatParams extends StartVideoChatParams {
369
+ }
370
+ export interface JoinVideoChatParams {
371
+ /** The identifier of a chat to join the video chat on behalf of. */
372
+ joinAs?: ID;
373
+ /** Invite hash. */
374
+ inviteHash?: string;
375
+ /** Whether to enable audio. Enabled by default. */
376
+ audio?: boolean;
377
+ /** Whether to enable video. Enabled by default. */
378
+ video?: boolean;
379
+ }
380
+ export interface DownloadLiveStreamChunkParams {
381
+ /** Video quality. */
382
+ quality?: "low" | "medium" | "high";
383
+ }
@@ -1,4 +1,4 @@
1
- import { types } from "../2_tl.js";
1
+ import { enums, types } from "../2_tl.js";
2
2
  import { FileSource, Sticker } from "../3_types.js";
3
3
  import { DownloadParams, UploadParams } from "./0_params.js";
4
4
  import { C } from "./0_types.js";
@@ -6,6 +6,10 @@ export declare class FileManager {
6
6
  #private;
7
7
  constructor(c: C);
8
8
  upload(file: FileSource, params?: UploadParams, checkName?: null | ((name: string) => string), allowStream?: boolean): Promise<import("../tl/2_types.js").InputFile_ | import("../tl/2_types.js").InputFileBig_>;
9
+ downloadInner(location: enums.InputFileLocation, dcId: number, params?: {
10
+ chunkSize?: number;
11
+ offset?: number;
12
+ }): AsyncGenerator<Uint8Array, void, unknown>;
9
13
  static validateChunkSize(chunkSize: number, max: number): void;
10
14
  download(fileId: string, params?: DownloadParams): AsyncGenerator<Uint8Array, void, unknown>;
11
15
  getStickerSetName(inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  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");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _FileManager_instances, _a, _FileManager_c, _FileManager_Lupload, _FileManager_UPLOAD_MAX_CHUNK_SIZE, _FileManager_DOWNLOAD_MAX_CHUNK_SIZE, _FileManager_BIG_FILE_THRESHOLD, _FileManager_UPLOAD_REQUEST_PER_CONNECTION, _FileManager_uploadStream, _FileManager_uploadBuffer, _FileManager_handleUploadError, _FileManager_getFileContents, _FileManager_downloadInner, _FileManager_CUSTOM_EMOJI_TTL;
12
+ var _FileManager_instances, _a, _FileManager_c, _FileManager_Lupload, _FileManager_UPLOAD_MAX_CHUNK_SIZE, _FileManager_DOWNLOAD_MAX_CHUNK_SIZE, _FileManager_BIG_FILE_THRESHOLD, _FileManager_UPLOAD_REQUEST_PER_CONNECTION, _FileManager_uploadStream, _FileManager_uploadBuffer, _FileManager_handleUploadError, _FileManager_getFileContents, _FileManager_CUSTOM_EMOJI_TTL;
13
13
  /**
14
14
  * MTKruto - Cross-runtime JavaScript library for building Telegram clients
15
15
  * Copyright (C) 2023-2024 Roj <https://roj.im/>
@@ -84,6 +84,51 @@ export class FileManager {
84
84
  return new types.InputFileBig({ id: fileId, parts: result.parts, name });
85
85
  }
86
86
  }
87
+ async *downloadInner(location, dcId, params) {
88
+ const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
89
+ if (id != null && __classPrivateFieldGet(this, _FileManager_c, "f").storage.supportsFiles) {
90
+ const file = await __classPrivateFieldGet(this, _FileManager_c, "f").storage.getFile(id);
91
+ const partOffset = file == null ? 0 : params?.offset ? Math.ceil(10 / file[1]) - 1 : 0;
92
+ if (file != null && file[0] > 0) {
93
+ yield* __classPrivateFieldGet(this, _FileManager_c, "f").storage.iterFileParts(id, file[0], partOffset);
94
+ return;
95
+ }
96
+ }
97
+ const chunkSize = params?.chunkSize ?? __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE);
98
+ _a.validateChunkSize(chunkSize, __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE));
99
+ const connection = __classPrivateFieldGet(this, _FileManager_c, "f").getCdnConnection(dcId);
100
+ await connection.connect();
101
+ const limit = chunkSize;
102
+ let offset = params?.offset ? BigInt(params.offset) : 0n;
103
+ let part = 0;
104
+ try {
105
+ while (true) {
106
+ const file = await connection.api.upload.getFile({ location, offset, limit });
107
+ if (file instanceof types.upload.File) {
108
+ yield file.bytes;
109
+ if (id != null) {
110
+ await __classPrivateFieldGet(this, _FileManager_c, "f").storage.saveFilePart(id, part, file.bytes);
111
+ }
112
+ ++part;
113
+ if (file.bytes.length < limit) {
114
+ if (id != null) {
115
+ await __classPrivateFieldGet(this, _FileManager_c, "f").storage.setFilePartCount(id, part + 1, chunkSize);
116
+ }
117
+ break;
118
+ }
119
+ else {
120
+ offset += BigInt(file.bytes.length);
121
+ }
122
+ }
123
+ else {
124
+ unreachable();
125
+ }
126
+ }
127
+ }
128
+ finally {
129
+ drop(connection.disconnect());
130
+ }
131
+ }
87
132
  static validateChunkSize(chunkSize, max) {
88
133
  if (chunkSize <= 0) {
89
134
  throw new InputError("chunkSize must be bigger than zero.");
@@ -109,7 +154,7 @@ export class FileManager {
109
154
  const big = fileId_.location.source.type == PhotoSourceType.ChatPhotoBig;
110
155
  const peer = await __classPrivateFieldGet(this, _FileManager_c, "f").getInputPeer(Number(fileId_.location.source.chatId)); // TODO: use access hash from source?
111
156
  const location = new types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photo_id: fileId_.location.id });
112
- yield* __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params);
157
+ yield* this.downloadInner(location, fileId_.dcId, params);
113
158
  break;
114
159
  }
115
160
  case FileType.Photo: {
@@ -119,7 +164,7 @@ export class FileManager {
119
164
  file_reference: fileId_.fileReference ?? new Uint8Array(),
120
165
  thumb_size: "thumbnailType" in fileId_.location.source ? String.fromCharCode(fileId_.location.source.thumbnailType) : "",
121
166
  });
122
- yield* __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params);
167
+ yield* this.downloadInner(location, fileId_.dcId, params);
123
168
  break;
124
169
  }
125
170
  case FileType.Thumbnail: {
@@ -129,7 +174,7 @@ export class FileManager {
129
174
  file_reference: fileId_.fileReference ?? new Uint8Array(),
130
175
  thumb_size: "thumbnailType" in fileId_.location.source ? String.fromCharCode(fileId_.location.source.thumbnailType) : unreachable(),
131
176
  });
132
- yield* __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params);
177
+ yield* this.downloadInner(location, fileId_.dcId, params);
133
178
  break;
134
179
  }
135
180
  }
@@ -141,7 +186,7 @@ export class FileManager {
141
186
  file_reference: fileId_.fileReference ?? new Uint8Array(),
142
187
  thumb_size: "",
143
188
  });
144
- yield* __classPrivateFieldGet(this, _FileManager_instances, "m", _FileManager_downloadInner).call(this, location, fileId_.dcId, params);
189
+ yield* this.downloadInner(location, fileId_.dcId, params);
145
190
  }
146
191
  else {
147
192
  unreachable();
@@ -373,50 +418,6 @@ _a = FileManager, _FileManager_c = new WeakMap(), _FileManager_Lupload = new Wea
373
418
  }
374
419
  }
375
420
  return { size: params?.fileSize ? params.fileSize : size, name, contents };
376
- }, _FileManager_downloadInner = async function* _FileManager_downloadInner(location, dcId, params) {
377
- const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
378
- if (id != null && __classPrivateFieldGet(this, _FileManager_c, "f").storage.supportsFiles) {
379
- const file = await __classPrivateFieldGet(this, _FileManager_c, "f").storage.getFile(id);
380
- const partOffset = file == null ? 0 : params?.offset ? Math.ceil(10 / file[1]) - 1 : 0;
381
- if (file != null && file[0] > 0) {
382
- yield* __classPrivateFieldGet(this, _FileManager_c, "f").storage.iterFileParts(id, file[0], partOffset);
383
- return;
384
- }
385
- }
386
- const chunkSize = params?.chunkSize ?? __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE);
387
- _a.validateChunkSize(chunkSize, __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE));
388
- const connection = __classPrivateFieldGet(this, _FileManager_c, "f").getCdnConnection(dcId);
389
- await connection.connect();
390
- const limit = chunkSize;
391
- let offset = params?.offset ? BigInt(params.offset) : 0n;
392
- let part = 0;
393
- try {
394
- while (true) {
395
- const file = await connection.api.upload.getFile({ location, offset, limit });
396
- if (file instanceof types.upload.File) {
397
- yield file.bytes;
398
- if (id != null) {
399
- await __classPrivateFieldGet(this, _FileManager_c, "f").storage.saveFilePart(id, part, file.bytes);
400
- }
401
- ++part;
402
- if (file.bytes.length < limit) {
403
- if (id != null) {
404
- await __classPrivateFieldGet(this, _FileManager_c, "f").storage.setFilePartCount(id, part + 1, chunkSize);
405
- }
406
- break;
407
- }
408
- else {
409
- offset += BigInt(file.bytes.length);
410
- }
411
- }
412
- else {
413
- unreachable();
414
- }
415
- }
416
- }
417
- finally {
418
- drop(connection.disconnect());
419
- }
420
421
  };
421
422
  _FileManager_UPLOAD_MAX_CHUNK_SIZE = { value: 512 * kilobyte };
422
423
  _FileManager_DOWNLOAD_MAX_CHUNK_SIZE = { value: 1 * megabyte };
@@ -0,0 +1,43 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2024 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+ import { enums, types } from "../2_tl.js";
21
+ import { ID, Update, VideoChatActive, VideoChatScheduled } from "../3_types.js";
22
+ import { DownloadLiveStreamChunkParams, JoinVideoChatParams, StartVideoChatParams } from "./0_params.js";
23
+ import { C as C_ } from "./0_types.js";
24
+ import { FileManager } from "./1_file_manager.js";
25
+ interface C extends C_ {
26
+ fileManager: FileManager;
27
+ }
28
+ type VideoChatManagerUpdate = types.UpdateGroupCall;
29
+ export declare class VideoChatManager {
30
+ #private;
31
+ constructor(c: C);
32
+ startVideoChat(chatId: ID, params?: StartVideoChatParams): Promise<VideoChatActive>;
33
+ scheduleVideoChat(chatId: ID, startAt: Date, params?: StartVideoChatParams): Promise<VideoChatScheduled>;
34
+ joinVideoChat(id: string, params: string, params_?: JoinVideoChatParams): Promise<string>;
35
+ leaveVideoChat(id: string): Promise<void>;
36
+ joinLiveStream(id: string): Promise<void>;
37
+ getVideoChat(id: string): Promise<import("../3_types.js").VideoChat>;
38
+ static canHandleUpdate(update: enums.Update): update is VideoChatManagerUpdate;
39
+ handleUpdate(update: VideoChatManagerUpdate): Promise<Update>;
40
+ getLiveStreamChannels(id: string): Promise<import("../3_types.js").LiveStreamChannel[]>;
41
+ downloadLiveStreamChunk(id: string, channel: number, scale: number, timestamp: number, params?: DownloadLiveStreamChunkParams): AsyncGenerator<Uint8Array, void, unknown>;
42
+ }
43
+ export {};
@@ -0,0 +1,194 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2024 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
21
+ if (kind === "m") throw new TypeError("Private method is not writable");
22
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
23
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
24
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
25
+ };
26
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
27
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
30
+ };
31
+ var _VideoChatManager_instances, _VideoChatManager_c, _VideoChatManager_createGroupCall, _VideoChatManager_getInputGroupCall, _VideoChatManager_getCall;
32
+ import { unreachable } from "../0_deps.js";
33
+ import { InputError } from "../0_errors.js";
34
+ import { getRandomId, toUnixTimestamp, ZERO_CHANNEL_ID } from "../1_utilities.js";
35
+ import { as, types } from "../2_tl.js";
36
+ import { constructLiveStreamChannel, constructVideoChat } from "../3_types.js";
37
+ export class VideoChatManager {
38
+ constructor(c) {
39
+ _VideoChatManager_instances.add(this);
40
+ _VideoChatManager_c.set(this, void 0);
41
+ __classPrivateFieldSet(this, _VideoChatManager_c, c, "f");
42
+ }
43
+ async startVideoChat(chatId, params) {
44
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.assertUser("startVideoChat");
45
+ return await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_createGroupCall).call(this, chatId, params?.title, params?.liveStream || undefined);
46
+ }
47
+ async scheduleVideoChat(chatId, startAt, params) {
48
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.assertUser("scheduleVideoChat");
49
+ return await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_createGroupCall).call(this, chatId, params?.title, params?.liveStream || undefined, startAt);
50
+ }
51
+ async joinVideoChat(id, params, params_) {
52
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.assertUser("joinVideoChat");
53
+ const call = await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getInputGroupCall).call(this, id);
54
+ const { updates } = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").api.phone.joinGroupCall({
55
+ call,
56
+ join_as: params_?.joinAs ? await __classPrivateFieldGet(this, _VideoChatManager_c, "f").getInputPeer(params_.joinAs) : new types.InputPeerSelf(),
57
+ params: new types.DataJSON({ data: params }),
58
+ invite_hash: params_?.inviteHash,
59
+ muted: params_?.audio ? undefined : true,
60
+ video_stopped: params_?.video ? undefined : true,
61
+ }).then((v) => v[as](types.Updates));
62
+ const updateGroupCall = updates
63
+ .find((v) => v instanceof types.UpdateGroupCallConnection);
64
+ if (!updateGroupCall)
65
+ unreachable();
66
+ return updateGroupCall.params.data;
67
+ }
68
+ async leaveVideoChat(id) {
69
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.assertUser("leaveVideoChat");
70
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").api.phone.leaveGroupCall({ call: await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getInputGroupCall).call(this, id), source: 0 });
71
+ }
72
+ async joinLiveStream(id) {
73
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.assertUser("joinLiveStream");
74
+ const call = await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getInputGroupCall).call(this, id);
75
+ const { updates } = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").api.phone.joinGroupCall({
76
+ call,
77
+ join_as: new types.InputPeerSelf(),
78
+ params: new types.DataJSON({
79
+ data: JSON.stringify({
80
+ fingerprints: [],
81
+ pwd: "",
82
+ ssrc: getRandomId(true),
83
+ "ssrc-groups": [],
84
+ ufrag: "",
85
+ }),
86
+ }),
87
+ }).then((v) => v[as](types.Updates));
88
+ const updateGroupCall = updates
89
+ .find((v) => v instanceof types.UpdateGroupCallConnection);
90
+ if (!updateGroupCall)
91
+ unreachable();
92
+ }
93
+ async getVideoChat(id) {
94
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.assertUser("getVideoChat");
95
+ return constructVideoChat(await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getCall).call(this, id));
96
+ }
97
+ static canHandleUpdate(update) {
98
+ return update instanceof types.UpdateGroupCall;
99
+ }
100
+ async handleUpdate(update) {
101
+ let chatId = Number(-update.chat_id);
102
+ const fullChat = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.getFullChat(chatId).then((v) => v == null ? __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.getFullChat(chatId = ZERO_CHANNEL_ID - Number(update.chat_id)) : v);
103
+ let updateFullChat = false;
104
+ if (update.call instanceof types.GroupCallDiscarded) {
105
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.setGroupCall(update.call.id, null);
106
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.setGroupCallAccessHash(update.call.id, null);
107
+ if (fullChat != null) {
108
+ fullChat.call = undefined;
109
+ updateFullChat = true;
110
+ }
111
+ }
112
+ else {
113
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.setGroupCall(update.call.id, update.call);
114
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.setGroupCallAccessHash(update.call.id, update.call.access_hash);
115
+ if (fullChat != null) {
116
+ if (!("call" in fullChat) || !fullChat.call || fullChat.call.id != update.call.id) {
117
+ fullChat.call = new types.InputGroupCall(update.call);
118
+ updateFullChat = true;
119
+ }
120
+ }
121
+ }
122
+ if (updateFullChat) {
123
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.setFullChat(chatId, fullChat);
124
+ }
125
+ return { videoChat: constructVideoChat(update.call) };
126
+ }
127
+ async getLiveStreamChannels(id) {
128
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.assertUser("getLiveStreamChannels");
129
+ const call = await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getCall).call(this, id);
130
+ if (!(call instanceof types.GroupCall) || !call.rtmp_stream) {
131
+ throw new InputError("Not a live stream.");
132
+ }
133
+ const client = __classPrivateFieldGet(this, _VideoChatManager_c, "f").getCdnConnection(call.stream_dc_id);
134
+ await client.connect();
135
+ try {
136
+ const streams = await client.api.phone.getGroupCallStreamChannels({ call: await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getInputGroupCall).call(this, id) });
137
+ return streams.channels.map(constructLiveStreamChannel);
138
+ }
139
+ finally {
140
+ await client.disconnect();
141
+ }
142
+ }
143
+ async *downloadLiveStreamChunk(id, channel, scale, timestamp, params) {
144
+ await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.assertUser("downloadLiveStreamChunk");
145
+ const call = await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getCall).call(this, id);
146
+ if (!(call instanceof types.GroupCall) || !call.rtmp_stream) {
147
+ throw new InputError("Not a live stream.");
148
+ }
149
+ const quality = params?.quality ?? "low";
150
+ const location = new types.InputGroupCallStream({
151
+ call: new types.InputGroupCall(call),
152
+ scale,
153
+ time_ms: BigInt(timestamp),
154
+ video_channel: channel,
155
+ video_quality: quality == "low" ? 0 : quality == "medium" ? 1 : quality == "high" ? 2 : (() => {
156
+ throw new InputError("Got invalid quality.");
157
+ })(),
158
+ });
159
+ yield* __classPrivateFieldGet(this, _VideoChatManager_c, "f").fileManager.downloadInner(location, call.stream_dc_id ?? unreachable());
160
+ }
161
+ }
162
+ _VideoChatManager_c = new WeakMap(), _VideoChatManager_instances = new WeakSet(), _VideoChatManager_createGroupCall = async function _VideoChatManager_createGroupCall(chatId, title, liveStream, scheduleDate) {
163
+ const peer = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").getInputPeer(chatId);
164
+ if (peer instanceof types.InputPeerUser) {
165
+ throw new InputError("Video chats are only available for groups and channels.");
166
+ }
167
+ const { updates } = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").api.phone.createGroupCall({
168
+ peer,
169
+ random_id: getRandomId(true),
170
+ title,
171
+ rtmp_stream: liveStream,
172
+ schedule_date: scheduleDate ? toUnixTimestamp(scheduleDate) : undefined,
173
+ }).then((v) => v[as](types.Updates));
174
+ const updateGroupCall = updates
175
+ .find((v) => v instanceof types.UpdateGroupCall);
176
+ if (!updateGroupCall) {
177
+ unreachable();
178
+ }
179
+ return constructVideoChat(updateGroupCall.call);
180
+ }, _VideoChatManager_getInputGroupCall = async function _VideoChatManager_getInputGroupCall(id_) {
181
+ const id = BigInt(id_);
182
+ const accessHash = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.getGroupCallAccessHash(id);
183
+ if (accessHash == null) {
184
+ throw new InputError("Video chat not found.");
185
+ }
186
+ return new types.InputGroupCall({ id, access_hash: accessHash });
187
+ }, _VideoChatManager_getCall = async function _VideoChatManager_getCall(id) {
188
+ let groupCall = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").storage.getGroupCall(BigInt(id));
189
+ if (groupCall == null) {
190
+ const call = await __classPrivateFieldGet(this, _VideoChatManager_instances, "m", _VideoChatManager_getInputGroupCall).call(this, id);
191
+ groupCall = await __classPrivateFieldGet(this, _VideoChatManager_c, "f").api.phone.getGroupCall({ call, limit: 1 }).then((v) => v.call);
192
+ }
193
+ return groupCall;
194
+ };
@@ -50,6 +50,7 @@ export class CallbackQueryManager {
50
50
  });
51
51
  }
52
52
  async sendCallbackQuery(chatId, messageId, question) {
53
+ await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").storage.assertUser("sendCallbackQuery");
53
54
  checkMessageId(messageId);
54
55
  validateCallbackQueryQuestion(question);
55
56
  const peer = await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").getInputPeer(chatId), peerId = peerToChatId(peer), questionKey = JSON.stringify(question);
@@ -18,7 +18,7 @@
18
18
  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
19
  */
20
20
  import { enums, types } from "../2_tl.js";
21
- import { Chat, ID } from "../3_types.js";
21
+ import { ChatListItem, ID } from "../3_types.js";
22
22
  import { C as C_ } from "./0_types.js";
23
23
  import { FileManager } from "./1_file_manager.js";
24
24
  import { MessageManager } from "./2_message_manager.js";
@@ -31,9 +31,9 @@ export declare class ChatListManager {
31
31
  #private;
32
32
  constructor(c: C);
33
33
  reassignChatLastMessage(chatId: number, add?: boolean, sendUpdate?: boolean): Promise<() => Promise<void>>;
34
- getChats(from?: "archived" | "main", after?: Chat, limit?: number): Promise<Chat[]>;
34
+ getChats(from?: "archived" | "main", after?: ChatListItem, limit?: number): Promise<ChatListItem[]>;
35
35
  static canHandleUpdate(update: enums.Update): update is ChatListManagerUpdate;
36
36
  handleUpdate(update: ChatListManagerUpdate): Promise<void>;
37
- getChat(chatId: ID): Promise<Chat>;
37
+ getChat(chatId: ID): Promise<import("../3_types.js").Chat>;
38
38
  }
39
39
  export {};