@ryantest/openclaw-qqbot 0.0.1

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 (197) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +483 -0
  3. package/README.zh.md +478 -0
  4. package/bin/qqbot-cli.js +243 -0
  5. package/clawdbot.plugin.json +16 -0
  6. package/dist/index.d.ts +17 -0
  7. package/dist/index.js +26 -0
  8. package/dist/src/admin-resolver.d.ts +27 -0
  9. package/dist/src/admin-resolver.js +122 -0
  10. package/dist/src/api.d.ts +156 -0
  11. package/dist/src/api.js +599 -0
  12. package/dist/src/channel.d.ts +11 -0
  13. package/dist/src/channel.js +354 -0
  14. package/dist/src/config.d.ts +25 -0
  15. package/dist/src/config.js +161 -0
  16. package/dist/src/credential-backup.d.ts +31 -0
  17. package/dist/src/credential-backup.js +66 -0
  18. package/dist/src/gateway.d.ts +18 -0
  19. package/dist/src/gateway.js +1265 -0
  20. package/dist/src/image-server.d.ts +68 -0
  21. package/dist/src/image-server.js +462 -0
  22. package/dist/src/inbound-attachments.d.ts +58 -0
  23. package/dist/src/inbound-attachments.js +234 -0
  24. package/dist/src/known-users.d.ts +100 -0
  25. package/dist/src/known-users.js +263 -0
  26. package/dist/src/message-queue.d.ts +50 -0
  27. package/dist/src/message-queue.js +115 -0
  28. package/dist/src/onboarding.d.ts +10 -0
  29. package/dist/src/onboarding.js +203 -0
  30. package/dist/src/outbound-deliver.d.ts +48 -0
  31. package/dist/src/outbound-deliver.js +462 -0
  32. package/dist/src/outbound.d.ts +203 -0
  33. package/dist/src/outbound.js +1102 -0
  34. package/dist/src/proactive.d.ts +170 -0
  35. package/dist/src/proactive.js +399 -0
  36. package/dist/src/ref-index-store.d.ts +70 -0
  37. package/dist/src/ref-index-store.js +273 -0
  38. package/dist/src/reply-dispatcher.d.ts +35 -0
  39. package/dist/src/reply-dispatcher.js +311 -0
  40. package/dist/src/runtime.d.ts +3 -0
  41. package/dist/src/runtime.js +10 -0
  42. package/dist/src/session-store.d.ts +52 -0
  43. package/dist/src/session-store.js +254 -0
  44. package/dist/src/slash-commands.d.ts +71 -0
  45. package/dist/src/slash-commands.js +1179 -0
  46. package/dist/src/startup-greeting.d.ts +30 -0
  47. package/dist/src/startup-greeting.js +78 -0
  48. package/dist/src/stt.d.ts +21 -0
  49. package/dist/src/stt.js +70 -0
  50. package/dist/src/tools/channel.d.ts +16 -0
  51. package/dist/src/tools/channel.js +234 -0
  52. package/dist/src/tools/remind.d.ts +2 -0
  53. package/dist/src/tools/remind.js +247 -0
  54. package/dist/src/types.d.ts +175 -0
  55. package/dist/src/types.js +1 -0
  56. package/dist/src/typing-keepalive.d.ts +27 -0
  57. package/dist/src/typing-keepalive.js +64 -0
  58. package/dist/src/update-checker.d.ts +34 -0
  59. package/dist/src/update-checker.js +166 -0
  60. package/dist/src/user-messages.d.ts +8 -0
  61. package/dist/src/user-messages.js +8 -0
  62. package/dist/src/utils/audio-convert.d.ts +89 -0
  63. package/dist/src/utils/audio-convert.js +704 -0
  64. package/dist/src/utils/file-utils.d.ts +55 -0
  65. package/dist/src/utils/file-utils.js +150 -0
  66. package/dist/src/utils/image-size.d.ts +51 -0
  67. package/dist/src/utils/image-size.js +234 -0
  68. package/dist/src/utils/media-tags.d.ts +14 -0
  69. package/dist/src/utils/media-tags.js +164 -0
  70. package/dist/src/utils/payload.d.ts +112 -0
  71. package/dist/src/utils/payload.js +186 -0
  72. package/dist/src/utils/platform.d.ts +137 -0
  73. package/dist/src/utils/platform.js +390 -0
  74. package/dist/src/utils/text-parsing.d.ts +32 -0
  75. package/dist/src/utils/text-parsing.js +80 -0
  76. package/dist/src/utils/upload-cache.d.ts +34 -0
  77. package/dist/src/utils/upload-cache.js +93 -0
  78. package/index.ts +31 -0
  79. package/moltbot.plugin.json +16 -0
  80. package/node_modules/@eshaz/web-worker/LICENSE +201 -0
  81. package/node_modules/@eshaz/web-worker/README.md +134 -0
  82. package/node_modules/@eshaz/web-worker/browser.js +17 -0
  83. package/node_modules/@eshaz/web-worker/cjs/browser.js +16 -0
  84. package/node_modules/@eshaz/web-worker/cjs/node.js +219 -0
  85. package/node_modules/@eshaz/web-worker/index.d.ts +4 -0
  86. package/node_modules/@eshaz/web-worker/node.js +223 -0
  87. package/node_modules/@eshaz/web-worker/package.json +54 -0
  88. package/node_modules/@wasm-audio-decoders/common/index.js +5 -0
  89. package/node_modules/@wasm-audio-decoders/common/package.json +36 -0
  90. package/node_modules/@wasm-audio-decoders/common/src/WASMAudioDecoderCommon.js +231 -0
  91. package/node_modules/@wasm-audio-decoders/common/src/WASMAudioDecoderWorker.js +129 -0
  92. package/node_modules/@wasm-audio-decoders/common/src/puff/README +67 -0
  93. package/node_modules/@wasm-audio-decoders/common/src/puff/build_puff.js +31 -0
  94. package/node_modules/@wasm-audio-decoders/common/src/puff/puff.c +863 -0
  95. package/node_modules/@wasm-audio-decoders/common/src/puff/puff.h +35 -0
  96. package/node_modules/@wasm-audio-decoders/common/src/utilities.js +3 -0
  97. package/node_modules/@wasm-audio-decoders/common/types.d.ts +7 -0
  98. package/node_modules/mpg123-decoder/README.md +265 -0
  99. package/node_modules/mpg123-decoder/dist/mpg123-decoder.min.js +185 -0
  100. package/node_modules/mpg123-decoder/dist/mpg123-decoder.min.js.map +1 -0
  101. package/node_modules/mpg123-decoder/index.js +8 -0
  102. package/node_modules/mpg123-decoder/package.json +58 -0
  103. package/node_modules/mpg123-decoder/src/EmscriptenWasm.js +464 -0
  104. package/node_modules/mpg123-decoder/src/MPEGDecoder.js +200 -0
  105. package/node_modules/mpg123-decoder/src/MPEGDecoderWebWorker.js +21 -0
  106. package/node_modules/mpg123-decoder/types.d.ts +30 -0
  107. package/node_modules/silk-wasm/LICENSE +21 -0
  108. package/node_modules/silk-wasm/README.md +85 -0
  109. package/node_modules/silk-wasm/lib/index.cjs +16 -0
  110. package/node_modules/silk-wasm/lib/index.d.ts +70 -0
  111. package/node_modules/silk-wasm/lib/index.mjs +16 -0
  112. package/node_modules/silk-wasm/lib/silk.wasm +0 -0
  113. package/node_modules/silk-wasm/lib/utils.d.ts +4 -0
  114. package/node_modules/silk-wasm/package.json +39 -0
  115. package/node_modules/simple-yenc/.github/FUNDING.yml +1 -0
  116. package/node_modules/simple-yenc/.prettierignore +1 -0
  117. package/node_modules/simple-yenc/LICENSE +7 -0
  118. package/node_modules/simple-yenc/README.md +163 -0
  119. package/node_modules/simple-yenc/dist/esm.js +1 -0
  120. package/node_modules/simple-yenc/dist/index.js +1 -0
  121. package/node_modules/simple-yenc/package.json +50 -0
  122. package/node_modules/simple-yenc/rollup.config.js +27 -0
  123. package/node_modules/simple-yenc/src/simple-yenc.js +302 -0
  124. package/node_modules/ws/LICENSE +20 -0
  125. package/node_modules/ws/README.md +548 -0
  126. package/node_modules/ws/browser.js +8 -0
  127. package/node_modules/ws/index.js +13 -0
  128. package/node_modules/ws/lib/buffer-util.js +131 -0
  129. package/node_modules/ws/lib/constants.js +19 -0
  130. package/node_modules/ws/lib/event-target.js +292 -0
  131. package/node_modules/ws/lib/extension.js +203 -0
  132. package/node_modules/ws/lib/limiter.js +55 -0
  133. package/node_modules/ws/lib/permessage-deflate.js +528 -0
  134. package/node_modules/ws/lib/receiver.js +706 -0
  135. package/node_modules/ws/lib/sender.js +602 -0
  136. package/node_modules/ws/lib/stream.js +161 -0
  137. package/node_modules/ws/lib/subprotocol.js +62 -0
  138. package/node_modules/ws/lib/validation.js +152 -0
  139. package/node_modules/ws/lib/websocket-server.js +554 -0
  140. package/node_modules/ws/lib/websocket.js +1393 -0
  141. package/node_modules/ws/package.json +69 -0
  142. package/node_modules/ws/wrapper.mjs +8 -0
  143. package/openclaw.plugin.json +16 -0
  144. package/package.json +76 -0
  145. package/scripts/cleanup-legacy-plugins.sh +124 -0
  146. package/scripts/proactive-api-server.ts +369 -0
  147. package/scripts/send-proactive.ts +293 -0
  148. package/scripts/set-markdown.sh +156 -0
  149. package/scripts/test-sendmedia.ts +116 -0
  150. package/scripts/upgrade-via-alt-pkg.sh +307 -0
  151. package/scripts/upgrade-via-npm.ps1 +296 -0
  152. package/scripts/upgrade-via-npm.sh +301 -0
  153. package/scripts/upgrade-via-source.sh +774 -0
  154. package/skills/qqbot-channel/SKILL.md +263 -0
  155. package/skills/qqbot-channel/references/api_references.md +521 -0
  156. package/skills/qqbot-media/SKILL.md +56 -0
  157. package/skills/qqbot-remind/SKILL.md +149 -0
  158. package/src/admin-resolver.ts +140 -0
  159. package/src/api.ts +819 -0
  160. package/src/bot-logs-2026-03-21T11-21-47(2).txt +46 -0
  161. package/src/channel.ts +381 -0
  162. package/src/config.ts +187 -0
  163. package/src/credential-backup.ts +72 -0
  164. package/src/gateway.log +43 -0
  165. package/src/gateway.ts +1404 -0
  166. package/src/image-server.ts +539 -0
  167. package/src/inbound-attachments.ts +304 -0
  168. package/src/known-users.ts +353 -0
  169. package/src/message-queue.ts +169 -0
  170. package/src/onboarding.ts +274 -0
  171. package/src/openclaw-2026-03-21.log +3729 -0
  172. package/src/openclaw-plugin-sdk.d.ts +522 -0
  173. package/src/outbound-deliver.ts +552 -0
  174. package/src/outbound.ts +1266 -0
  175. package/src/proactive.ts +530 -0
  176. package/src/ref-index-store.ts +357 -0
  177. package/src/reply-dispatcher.ts +334 -0
  178. package/src/runtime.ts +14 -0
  179. package/src/session-store.ts +303 -0
  180. package/src/slash-commands.ts +1305 -0
  181. package/src/startup-greeting.ts +98 -0
  182. package/src/stt.ts +86 -0
  183. package/src/tools/channel.ts +281 -0
  184. package/src/tools/remind.ts +296 -0
  185. package/src/types.ts +183 -0
  186. package/src/typing-keepalive.ts +59 -0
  187. package/src/update-checker.ts +179 -0
  188. package/src/user-messages.ts +7 -0
  189. package/src/utils/audio-convert.ts +803 -0
  190. package/src/utils/file-utils.ts +167 -0
  191. package/src/utils/image-size.ts +266 -0
  192. package/src/utils/media-tags.ts +182 -0
  193. package/src/utils/payload.ts +265 -0
  194. package/src/utils/platform.ts +435 -0
  195. package/src/utils/text-parsing.ts +82 -0
  196. package/src/utils/upload-cache.ts +128 -0
  197. package/tsconfig.json +16 -0
@@ -0,0 +1,35 @@
1
+ /* puff.h
2
+ Copyright (C) 2002-2013 Mark Adler, all rights reserved
3
+ version 2.3, 21 Jan 2013
4
+
5
+ This software is provided 'as-is', without any express or implied
6
+ warranty. In no event will the author be held liable for any damages
7
+ arising from the use of this software.
8
+
9
+ Permission is granted to anyone to use this software for any purpose,
10
+ including commercial applications, and to alter it and redistribute it
11
+ freely, subject to the following restrictions:
12
+
13
+ 1. The origin of this software must not be misrepresented; you must not
14
+ claim that you wrote the original software. If you use this software
15
+ in a product, an acknowledgment in the product documentation would be
16
+ appreciated but is not required.
17
+ 2. Altered source versions must be plainly marked as such, and must not be
18
+ misrepresented as being the original software.
19
+ 3. This notice may not be removed or altered from any source distribution.
20
+
21
+ Mark Adler madler@alumni.caltech.edu
22
+ */
23
+
24
+
25
+ /*
26
+ * See puff.c for purpose and usage.
27
+ */
28
+ #ifndef NIL
29
+ # define NIL ((unsigned char *)0) /* for no output option */
30
+ #endif
31
+
32
+ int puff(unsigned char *dest, /* pointer to destination pointer */
33
+ unsigned long *destlen, /* amount of output space */
34
+ const unsigned char *source, /* pointer to source data pointer */
35
+ unsigned long *sourcelen); /* amount of input available */
@@ -0,0 +1,3 @@
1
+ export const assignNames = (Class, name) => {
2
+ Object.defineProperty(Class, "name", { value: name });
3
+ };
@@ -0,0 +1,7 @@
1
+ export interface DecodeError {
2
+ message: string;
3
+ frameLength: number;
4
+ frameNumber: number;
5
+ inputBytes: number;
6
+ outputSamples: number;
7
+ }
@@ -0,0 +1,265 @@
1
+ # `mpg123-decoder`
2
+
3
+ `mpg123-decoder` is a Web Assembly MPEG Layer (I/II/III) audio decoder.
4
+ * 77.1 KiB minified bundle size
5
+ * Browser and NodeJS support
6
+ * Built in Web Worker support
7
+ * Based on [`mpg123`](https://www.mpg123.de/)
8
+
9
+ See the [homepage](https://github.com/eshaz/wasm-audio-decoders) of this repository for more Web Assembly audio decoders like this one.
10
+
11
+ ### [Checkout the demo here](https://eshaz.github.io/wasm-audio-decoders/)
12
+
13
+ ## Installing
14
+ * Install from [NPM](https://www.npmjs.com/package/mpg123-decoder).
15
+
16
+ Run `npm i mpg123-decoder`
17
+
18
+ ```javascript
19
+ import { MPEGDecoder } from 'mpg123-decoder';
20
+
21
+ const decoder = new MPEGDecoder();
22
+ ```
23
+
24
+ * Or download the [build](https://github.com/eshaz/wasm-audio-decoders/tree/main/src/mpg123-decoder/dist) and include it as a script.
25
+ ```html
26
+ <script src="mpg123-decoder.min.js" charset="UTF-8"></script>
27
+ <script>
28
+ const decoder = new window["mpg123-decoder"].MPEGDecoder();
29
+ </script>
30
+ ```
31
+ * Note that the script must be read using UTF-8 character encoding. If running in a browser, the `<script>` tag must include the `charset="UTF-8"` attribute; or, the loading HTML must include `<meta charset="utf-8" />`.
32
+
33
+ ## Usage
34
+
35
+ 1. Create a new instance and wait for the WASM to finish compiling. Decoding can be done on the main thread synchronously, or in a webworker asynchronously.
36
+
37
+ **Main thread synchronous decoding**
38
+ ```javascript
39
+ import { MPEGDecoder } from 'mpg123-decoder';
40
+
41
+ const decoder = new MPEGDecoder();
42
+
43
+ // wait for the WASM to be compiled
44
+ await decoder.ready;
45
+ ```
46
+
47
+ **Web Worker asynchronous decoding**
48
+ ```javascript
49
+ import { MPEGDecoderWebWorker } from 'mpg123-decoder';
50
+
51
+ const decoder = new MPEGDecoderWebWorker();
52
+
53
+ // wait for the WASM to be compiled
54
+ await decoder.ready;
55
+ ```
56
+
57
+ 1. Begin decoding MPEG data.
58
+
59
+ ```javascript
60
+ // Decode Uint8Array of MPEG data
61
+ const {channelData, samplesDecoded, sampleRate} = decoder.decode(mpegData);
62
+
63
+ // Decode an individual MPEG frame
64
+ const {channelData, samplesDecoded, sampleRate} = decoder.decodeFrame(mpegFrame);
65
+
66
+ // Decode an array of individual MPEG frames
67
+ const {channelData, samplesDecoded, sampleRate} = decoder.decodeFrames(mpegFrameArray);
68
+ ```
69
+
70
+ 1. When done decoding, reset the decoder to decode a new stream, or free up the memory being used by the WASM module if you have no more audio to decode.
71
+
72
+ ```javascript
73
+ // `reset()` clears the decoder state and allows you do decode a new stream of MPEG data.
74
+ await decoder.reset();
75
+
76
+ // `free()` de-allocates the memory used by the decoder. You will need to create a new instance after calling `free()` to start decoding again.
77
+ decoder.free();
78
+ ```
79
+
80
+ ## API
81
+
82
+ Decoded audio is always returned in the below structure.
83
+
84
+ ```javascript
85
+ {
86
+ channelData: [
87
+ leftAudio, // Float32Array of PCM samples for the left channel
88
+ rightAudio // Float32Array of PCM samples for the right channel
89
+ ],
90
+ samplesDecoded: 1234, // number of PCM samples that were decoded per channel
91
+ sampleRate: 44100, // sample rate of the decoded PCM
92
+ errors: [ // array containing descriptions for any decode errors
93
+ {
94
+ message: "-1 MPG123_ERR",
95
+ frameLength: 1008, // length of the frame or data in bytes that encountered an error
96
+ frameNumber: 0, // position of error relative to total frames decoded
97
+ inputBytes: 2160, // position of error relative to total input bytes
98
+ outputSamples: 1152, // position of error relative to total output samples
99
+ }
100
+ ]
101
+ }
102
+ ```
103
+
104
+ Each Float32Array within `channelData` can be used directly in the WebAudio API for playback.
105
+
106
+ Decoding will proceed through any errors. Any errors encountered may result in gaps in the decoded audio.
107
+
108
+ ## `MPEGDecoder`
109
+
110
+ Class that decodes MPEG data or frames synchronously on the main thread.
111
+
112
+ ### Options
113
+ ```javascript
114
+ const decoder = new MPEGDecoder({ enableGapless: true });
115
+ ```
116
+
117
+ * `enableGapless` *optional, defaults to `true`*
118
+ * Set to `false` to disable gapless decoding.
119
+ * Gapless decoding reads the XING / Lame header to determine delay (start) and padding (end) samples and trims the output accordingly.
120
+
121
+ ### Getters
122
+ * `decoder.ready` *async*
123
+ * Returns a promise that is resolved when the WASM is compiled and ready to use.
124
+
125
+ ### Methods
126
+
127
+ * `decoder.decode(mpegData)`
128
+ * `mpegData` Uint8Array of MPEG audio data.
129
+ * `decoder.decodeFrame(mpegFrame)`
130
+ * `mpegFrame` Uint8Array containing a single MPEG frame.
131
+ * `decoder.decodeFrames(mpegFrames)`
132
+ * `mpegFrames` Array of Uint8Arrays containing MPEG frames.
133
+ * `decoder.reset()` *async*
134
+ * Resets the decoder so that a new stream of MPEG data can be decoded.
135
+ * `decoder.free()`
136
+ * De-allocates the memory used by the decoder.
137
+ * After calling `free()`, the current instance is made unusable, and a new instance will need to be created to decode additional MPEG data.
138
+
139
+ ## `MPEGDecoderWebWorker`
140
+
141
+ Class that decodes MPEG data or frames asynchronously within a WebWorker. Decoding is performed in a separate, non-blocking thread. Each new instance spawns a new worker allowing you to run multiple workers for concurrent decoding of multiple streams.
142
+
143
+ ### Options
144
+ ```javascript
145
+ const decoder = new MPEGDecoderWebWorker({ enableGapless: true });
146
+ ```
147
+
148
+ * `enableGapless` *optional, defaults to `true`*
149
+ * Set to `false` to disable gapless decoding.
150
+ * Gapless decoding reads the XING / Lame header to determine delay (start) and padding (end) samples and trims the output accordingly.
151
+
152
+ ### Getters
153
+ * `decoder.ready` *async*
154
+ * Returns a promise that is resolved when the WASM is compiled and ready to use.
155
+
156
+ ### Methods
157
+
158
+ * `decoder.decode(mpegData)` *async*
159
+ * `mpegData` Uint8Array of MPEG audio data.
160
+ * `decoder.decodeFrame(mpegFrame)` *async*
161
+ * `mpegFrame` Uint8Array containing a single MPEG frame.
162
+ * `decoder.decodeFrames(mpegFrames)` *async*
163
+ * `mpegFrames` Array of Uint8Arrays containing MPEG frames.
164
+ * `decoder.reset()` *async*
165
+ * Resets the decoder so that a new stream of MPEG data can be decoded.
166
+ * `decoder.free()` *async*
167
+ * De-allocates the memory used by the decoder and terminates the web worker.
168
+ * After calling `free()`, the current instance is made unusable, and a new instance will need to be created to decode additional MPEG data.
169
+
170
+ ### Properly using the Web Worker interface
171
+
172
+ `MPEGDecoderWebWorker` uses async functions to send operations to the web worker without blocking the main thread. To fully take advantage of the concurrency provided by web workers, your code should avoid using `await` on decode operations where it will block the main thread.
173
+
174
+ Each method call on a `MPEGDecoderWebWorker` instance will queue up an operation to the web worker. Operations will complete within the web worker thread one at a time and in the same order in which the methods were called.
175
+
176
+ * **Good** Main thread is not blocked during each decode operation. The example `playAudio` function is called when each decode operation completes. Also, the next decode operation can begin while `playAudio` is doing work on the main thread.
177
+ ```javascript
178
+ const playAudio = ({ channelData, samplesDecoded, sampleRate }) => {
179
+ // does something to play the audio data.
180
+ }
181
+
182
+ decoder.decodeFrame(frameData1).then(playAudio);
183
+ decoder.decodeFrame(frameData2).then(playAudio);
184
+ decoder.decodeFrame(frameData3).then(playAudio);
185
+
186
+ // do some other operations while the audio is decoded
187
+ ```
188
+
189
+ * **Bad** Main thread is being blocked by `await` during each decode operation. Synchronous code is halted while decoding completes, negating the benefits of using a webworker.
190
+ ```javascript
191
+ const decoded1 = await decoder.decodeFrame(frameData1); // blocks the main thread
192
+ playAudio(decoded1);
193
+
194
+ const decoded2 = await decoder.decodeFrame(frameData2); // blocks the main thread
195
+ playAudio(decoded2);
196
+
197
+ const decoded3 = await decoder.decodeFrame(frameData3); // blocks the main thread
198
+ playAudio(decoded3);
199
+ ```
200
+
201
+ ## Examples
202
+
203
+ ### Decoding multiple files using a **single** instance of `MPEGDecoderWebWorker`
204
+
205
+ This example shows how to decode multiple files using a single `MPEGDecoderWebWorker` instance. This code iterates over an array of input files (Array of Uint8Arrays) and queues up each file to be decoded one at a time.
206
+
207
+ First, wait for the decoder to become ready by calling `decoder.ready`.
208
+
209
+ For each iteration, `decode()` is called, it's result is pushed to the `decodedFiles` array, and `decoder.reset()` is called to prepare the decoder for a new file. These operations are queued up to the decoder instance and will complete one after another.
210
+
211
+ Finally, a call to `decoder.free()` is queued to clean up the memory stored by the decoder. This resolves when it and all of the other operations before it complete.
212
+
213
+ It's important to note that there is only one `await` operations in this example. Decoding can happen asynchronously and you only need to `await` when you need to use the results of the decode operation.
214
+
215
+ ```javascript
216
+ const inputFiles = [file1, file2, file3] // Array of Uint8Array file data
217
+
218
+ const decoder = new MPEGDecoderWebWorker();
219
+
220
+ const decodedFiles = [];
221
+
222
+ const decodePromise = decoder.ready // wait for the decoder to be ready
223
+ .then(() => {
224
+ for (const file of inputFiles) {
225
+ decoder.decode(file) // queue the decode operation
226
+ .then((result) => decodedFiles.push(result)); // save the decode result after decode completes
227
+ decoder.reset(); // queue the reset operation
228
+ }
229
+ })
230
+ .then(() => decoder.free()); // queue the free operation that will execute after the above operations
231
+
232
+ // do sync operations here
233
+
234
+ // await when you need to have the all of the audio data decoded
235
+ await decodePromise;
236
+ ```
237
+ ### Decoding multiple files using **multiple** instances of `MPEGDecoderWebWorker`
238
+
239
+ This example shows how to decode multiple files using multiple instances of `MPEGDecoderWebWorker`. This code iterates over an array of input files (Array of Uint8Arrays) and spawns a new `MPEGDecoderWebWorker` instance for each file and decodes the file. If you want to take full advantage of multi-core devices, this is the approach you will want to take since it will parallelize the decoding
240
+
241
+ For each input file, a new decoder is created, and the file is decoded using the `decode()` after `decoder.ready` is resolved. The result of the `decode()` operation is returned, and a `finally()` function on the promise calls `decoder.free()` to free up the instance after the decode operations are completed.
242
+
243
+ Finally, `Promise.all()` wraps this array of promises and resolves when all decode operations are complete.
244
+
245
+ It's important to note that there is only one `await` operation in this example. Decoding can happen asynchronously and you only need to `await` when you need to use the results of the decode operation.
246
+
247
+ ```javascript
248
+ const inputFiles = [file1, file2, file3] // Array of Uint8Array file data
249
+
250
+ // loops through each Uint8Array in `inputFiles` and decodes the files in separate threads
251
+ const decodePromise = Promise.all(
252
+ inputFiles.map((file) => {
253
+ const decoder = new MPEGDecoderWebWorker();
254
+
255
+ return decoder.ready
256
+ .then(() => decoder.decode(file)) // decode the input file
257
+ .finally(() => decoder.free()); // free the decoder after resolving the decode result
258
+ })
259
+ );
260
+
261
+ // do sync operations here
262
+
263
+ // await when you need to have the all of the audio data decoded
264
+ const decodedFiles = await decodePromise;
265
+ ```