@tencent-connect/openclaw-qqbot 1.7.2 → 2.0.0

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 (291) hide show
  1. package/README.md +25 -8
  2. package/README.zh.md +24 -8
  3. package/bin/qqbot-cli.js +5 -2
  4. package/dist/index.cjs +15549 -0
  5. package/dist/index.cjs.map +1 -0
  6. package/dist/index.d.cts +890 -0
  7. package/index.ts +56 -19
  8. package/openclaw.plugin.json +19 -3
  9. package/package.json +14 -23
  10. package/preload.cjs +17 -14
  11. package/scripts/link-sdk-core.cjs +133 -50
  12. package/scripts/upgrade-via-npm.sh +42 -11
  13. package/scripts/upgrade-via-source.sh +4 -4
  14. package/skills/qqbot-channel/SKILL.md +34 -12
  15. package/src/adapter/contract.ts +69 -0
  16. package/src/adapter/gateway.ts +61 -0
  17. package/src/adapter/index.ts +15 -0
  18. package/src/adapter/lint.ts +144 -0
  19. package/src/adapter/media.ts +112 -0
  20. package/src/adapter/pairing.ts +99 -0
  21. package/src/adapter/resolve.ts +333 -0
  22. package/src/adapter/setup.ts +55 -0
  23. package/src/adapter/webhook.ts +248 -0
  24. package/src/adapter/workspace.ts +29 -0
  25. package/src/bot-instance.ts +60 -0
  26. package/src/channel.ts +202 -413
  27. package/src/commands/bot-approve.ts +143 -0
  28. package/src/commands/bot-clear-storage.ts +114 -0
  29. package/src/commands/bot-group-always.ts +62 -0
  30. package/src/commands/bot-help.ts +40 -0
  31. package/src/commands/bot-logs.ts +248 -0
  32. package/src/commands/bot-me.ts +18 -0
  33. package/src/commands/bot-pairing.ts +57 -0
  34. package/src/commands/bot-ping.ts +33 -0
  35. package/src/commands/bot-streaming.ts +55 -0
  36. package/src/commands/bot-upgrade.ts +56 -0
  37. package/src/commands/bot-version.ts +41 -0
  38. package/src/commands/config-util.ts +96 -0
  39. package/src/commands/index.ts +49 -0
  40. package/src/config.ts +46 -19
  41. package/src/dispatch/body-assembler.ts +356 -0
  42. package/src/dispatch/ctx-builder.ts +110 -0
  43. package/src/dispatch/dispatch.ts +352 -0
  44. package/src/dispatch/envelope-builder.ts +112 -0
  45. package/src/dispatch/index.ts +2 -0
  46. package/src/{approval-handler.ts → features/approval-handler.ts} +40 -94
  47. package/src/features/approval-utils.ts +41 -0
  48. package/src/features/credential-backup.ts +82 -0
  49. package/src/features/history-store.ts +19 -0
  50. package/src/features/msgid-cache.ts +55 -0
  51. package/src/features/onboarding.ts +38 -0
  52. package/src/{proactive.ts → features/proactive.ts} +68 -49
  53. package/src/features/ref-index-store.ts +282 -0
  54. package/src/{update-checker.ts → features/update-checker.ts} +15 -35
  55. package/src/gateway/event-handlers.ts +241 -0
  56. package/src/gateway/index.ts +3 -0
  57. package/src/gateway/lifecycle.ts +221 -0
  58. package/src/gateway/middleware-setup.ts +139 -0
  59. package/src/gateway/qqbot-gateway.ts +342 -0
  60. package/src/middleware/access-control.ts +130 -0
  61. package/src/middleware/attachment.ts +314 -0
  62. package/src/middleware/policy-injector.ts +66 -0
  63. package/src/openclaw-plugin-sdk.d.ts +81 -10
  64. package/src/outbound/cron-scheduler.ts +130 -0
  65. package/src/outbound/debounce.ts +102 -0
  66. package/src/outbound/deliver-pipeline.ts +235 -0
  67. package/src/outbound/image-size.ts +123 -0
  68. package/src/outbound/index.ts +3 -0
  69. package/src/outbound/local-file-router.ts +145 -0
  70. package/src/outbound/media-send.ts +377 -0
  71. package/src/outbound/outbound-service.ts +222 -0
  72. package/src/outbound/reply-limiter.ts +128 -0
  73. package/src/outbound/sanitize.ts +32 -0
  74. package/src/outbound/streaming-controller.ts +228 -0
  75. package/src/outbound/target.ts +63 -0
  76. package/src/outbound/tts-provider.ts +84 -0
  77. package/src/request-context.ts +9 -8
  78. package/src/runtime.ts +31 -6
  79. package/src/setup/account-key.ts +41 -0
  80. package/src/setup/finalize.ts +110 -0
  81. package/src/setup/login.ts +197 -0
  82. package/src/setup/surface.ts +40 -0
  83. package/src/tools/platform.ts +149 -0
  84. package/src/tools/remind.ts +2 -0
  85. package/src/types-augment.d.ts +54 -0
  86. package/src/types.ts +51 -9
  87. package/src/utils/mention.ts +52 -0
  88. package/src/utils/pkg-version.ts +84 -47
  89. package/src/utils/platform.ts +31 -7
  90. package/src/utils/plugin-logger.ts +104 -0
  91. package/src/utils/ssrf-guard.ts +32 -2
  92. package/src/utils/stt.ts +137 -0
  93. package/src/utils/voice-text.ts +61 -0
  94. package/tsconfig.json +2 -1
  95. package/tsup.config.ts +57 -0
  96. package/dist/index.d.ts +0 -18
  97. package/dist/index.js +0 -27
  98. package/dist/src/admin-resolver.d.ts +0 -33
  99. package/dist/src/admin-resolver.js +0 -157
  100. package/dist/src/api.d.ts +0 -309
  101. package/dist/src/api.js +0 -923
  102. package/dist/src/approval-handler.d.ts +0 -47
  103. package/dist/src/approval-handler.js +0 -372
  104. package/dist/src/channel.d.ts +0 -29
  105. package/dist/src/channel.js +0 -528
  106. package/dist/src/config.d.ts +0 -60
  107. package/dist/src/config.js +0 -288
  108. package/dist/src/credential-backup.d.ts +0 -31
  109. package/dist/src/credential-backup.js +0 -66
  110. package/dist/src/deliver-debounce.d.ts +0 -74
  111. package/dist/src/deliver-debounce.js +0 -174
  112. package/dist/src/gateway.d.ts +0 -18
  113. package/dist/src/gateway.js +0 -2025
  114. package/dist/src/group-history.d.ts +0 -136
  115. package/dist/src/group-history.js +0 -226
  116. package/dist/src/image-server.d.ts +0 -87
  117. package/dist/src/image-server.js +0 -570
  118. package/dist/src/inbound-attachments.d.ts +0 -60
  119. package/dist/src/inbound-attachments.js +0 -248
  120. package/dist/src/known-users.d.ts +0 -100
  121. package/dist/src/known-users.js +0 -263
  122. package/dist/src/message-gating.d.ts +0 -53
  123. package/dist/src/message-gating.js +0 -107
  124. package/dist/src/message-queue.d.ts +0 -91
  125. package/dist/src/message-queue.js +0 -257
  126. package/dist/src/onboarding.d.ts +0 -10
  127. package/dist/src/onboarding.js +0 -203
  128. package/dist/src/outbound-deliver.d.ts +0 -48
  129. package/dist/src/outbound-deliver.js +0 -392
  130. package/dist/src/outbound.d.ts +0 -220
  131. package/dist/src/outbound.js +0 -975
  132. package/dist/src/proactive.d.ts +0 -170
  133. package/dist/src/proactive.js +0 -399
  134. package/dist/src/ref-index-store.d.ts +0 -101
  135. package/dist/src/ref-index-store.js +0 -298
  136. package/dist/src/reply-dispatcher.d.ts +0 -35
  137. package/dist/src/reply-dispatcher.js +0 -311
  138. package/dist/src/request-context.d.ts +0 -25
  139. package/dist/src/request-context.js +0 -37
  140. package/dist/src/runtime.d.ts +0 -3
  141. package/dist/src/runtime.js +0 -13
  142. package/dist/src/session-store.d.ts +0 -52
  143. package/dist/src/session-store.js +0 -254
  144. package/dist/src/slash-commands.d.ts +0 -82
  145. package/dist/src/slash-commands.js +0 -2233
  146. package/dist/src/startup-greeting.d.ts +0 -30
  147. package/dist/src/startup-greeting.js +0 -97
  148. package/dist/src/streaming.d.ts +0 -247
  149. package/dist/src/streaming.js +0 -899
  150. package/dist/src/stt.d.ts +0 -21
  151. package/dist/src/stt.js +0 -70
  152. package/dist/src/tools/channel.d.ts +0 -16
  153. package/dist/src/tools/channel.js +0 -231
  154. package/dist/src/tools/remind.d.ts +0 -2
  155. package/dist/src/tools/remind.js +0 -255
  156. package/dist/src/transport/index.d.ts +0 -10
  157. package/dist/src/transport/index.js +0 -9
  158. package/dist/src/transport/webhook-transport.d.ts +0 -67
  159. package/dist/src/transport/webhook-transport.js +0 -245
  160. package/dist/src/transport/webhook-verify.d.ts +0 -48
  161. package/dist/src/transport/webhook-verify.js +0 -98
  162. package/dist/src/types.d.ts +0 -462
  163. package/dist/src/types.js +0 -22
  164. package/dist/src/typing-keepalive.d.ts +0 -27
  165. package/dist/src/typing-keepalive.js +0 -64
  166. package/dist/src/update-checker.d.ts +0 -36
  167. package/dist/src/update-checker.js +0 -171
  168. package/dist/src/utils/audio-convert.d.ts +0 -98
  169. package/dist/src/utils/audio-convert.js +0 -783
  170. package/dist/src/utils/chunked-upload.d.ts +0 -68
  171. package/dist/src/utils/chunked-upload.js +0 -341
  172. package/dist/src/utils/file-utils.d.ts +0 -61
  173. package/dist/src/utils/file-utils.js +0 -172
  174. package/dist/src/utils/image-size.d.ts +0 -51
  175. package/dist/src/utils/image-size.js +0 -234
  176. package/dist/src/utils/media-send.d.ts +0 -158
  177. package/dist/src/utils/media-send.js +0 -502
  178. package/dist/src/utils/media-tags.d.ts +0 -14
  179. package/dist/src/utils/media-tags.js +0 -165
  180. package/dist/src/utils/payload.d.ts +0 -112
  181. package/dist/src/utils/payload.js +0 -186
  182. package/dist/src/utils/pkg-version.d.ts +0 -5
  183. package/dist/src/utils/pkg-version.js +0 -61
  184. package/dist/src/utils/platform.d.ts +0 -137
  185. package/dist/src/utils/platform.js +0 -390
  186. package/dist/src/utils/ssrf-guard.d.ts +0 -25
  187. package/dist/src/utils/ssrf-guard.js +0 -91
  188. package/dist/src/utils/text-parsing.d.ts +0 -31
  189. package/dist/src/utils/text-parsing.js +0 -74
  190. package/dist/src/utils/upload-cache.d.ts +0 -34
  191. package/dist/src/utils/upload-cache.js +0 -93
  192. package/node_modules/@eshaz/web-worker/LICENSE +0 -201
  193. package/node_modules/@eshaz/web-worker/README.md +0 -134
  194. package/node_modules/@eshaz/web-worker/browser.js +0 -17
  195. package/node_modules/@eshaz/web-worker/cjs/browser.js +0 -16
  196. package/node_modules/@eshaz/web-worker/cjs/node.js +0 -219
  197. package/node_modules/@eshaz/web-worker/index.d.ts +0 -4
  198. package/node_modules/@eshaz/web-worker/node.js +0 -223
  199. package/node_modules/@eshaz/web-worker/package.json +0 -54
  200. package/node_modules/@wasm-audio-decoders/common/index.js +0 -5
  201. package/node_modules/@wasm-audio-decoders/common/package.json +0 -36
  202. package/node_modules/@wasm-audio-decoders/common/src/WASMAudioDecoderCommon.js +0 -231
  203. package/node_modules/@wasm-audio-decoders/common/src/WASMAudioDecoderWorker.js +0 -129
  204. package/node_modules/@wasm-audio-decoders/common/src/puff/README +0 -67
  205. package/node_modules/@wasm-audio-decoders/common/src/puff/build_puff.js +0 -31
  206. package/node_modules/@wasm-audio-decoders/common/src/puff/puff.c +0 -863
  207. package/node_modules/@wasm-audio-decoders/common/src/puff/puff.h +0 -35
  208. package/node_modules/@wasm-audio-decoders/common/src/utilities.js +0 -3
  209. package/node_modules/@wasm-audio-decoders/common/types.d.ts +0 -7
  210. package/node_modules/mpg123-decoder/README.md +0 -265
  211. package/node_modules/mpg123-decoder/dist/mpg123-decoder.min.js +0 -185
  212. package/node_modules/mpg123-decoder/dist/mpg123-decoder.min.js.map +0 -1
  213. package/node_modules/mpg123-decoder/index.js +0 -8
  214. package/node_modules/mpg123-decoder/package.json +0 -58
  215. package/node_modules/mpg123-decoder/src/EmscriptenWasm.js +0 -464
  216. package/node_modules/mpg123-decoder/src/MPEGDecoder.js +0 -200
  217. package/node_modules/mpg123-decoder/src/MPEGDecoderWebWorker.js +0 -21
  218. package/node_modules/mpg123-decoder/types.d.ts +0 -30
  219. package/node_modules/silk-wasm/LICENSE +0 -21
  220. package/node_modules/silk-wasm/README.md +0 -85
  221. package/node_modules/silk-wasm/lib/index.cjs +0 -16
  222. package/node_modules/silk-wasm/lib/index.d.ts +0 -70
  223. package/node_modules/silk-wasm/lib/index.mjs +0 -16
  224. package/node_modules/silk-wasm/lib/silk.wasm +0 -0
  225. package/node_modules/silk-wasm/lib/utils.d.ts +0 -4
  226. package/node_modules/silk-wasm/package.json +0 -39
  227. package/node_modules/simple-yenc/.github/FUNDING.yml +0 -1
  228. package/node_modules/simple-yenc/.prettierignore +0 -1
  229. package/node_modules/simple-yenc/LICENSE +0 -7
  230. package/node_modules/simple-yenc/README.md +0 -163
  231. package/node_modules/simple-yenc/dist/esm.js +0 -1
  232. package/node_modules/simple-yenc/dist/index.js +0 -1
  233. package/node_modules/simple-yenc/package.json +0 -50
  234. package/node_modules/simple-yenc/rollup.config.js +0 -27
  235. package/node_modules/simple-yenc/src/simple-yenc.js +0 -302
  236. package/node_modules/ws/LICENSE +0 -20
  237. package/node_modules/ws/README.md +0 -548
  238. package/node_modules/ws/browser.js +0 -8
  239. package/node_modules/ws/index.js +0 -13
  240. package/node_modules/ws/lib/buffer-util.js +0 -131
  241. package/node_modules/ws/lib/constants.js +0 -19
  242. package/node_modules/ws/lib/event-target.js +0 -292
  243. package/node_modules/ws/lib/extension.js +0 -203
  244. package/node_modules/ws/lib/limiter.js +0 -55
  245. package/node_modules/ws/lib/permessage-deflate.js +0 -528
  246. package/node_modules/ws/lib/receiver.js +0 -706
  247. package/node_modules/ws/lib/sender.js +0 -602
  248. package/node_modules/ws/lib/stream.js +0 -161
  249. package/node_modules/ws/lib/subprotocol.js +0 -62
  250. package/node_modules/ws/lib/validation.js +0 -152
  251. package/node_modules/ws/lib/websocket-server.js +0 -554
  252. package/node_modules/ws/lib/websocket.js +0 -1393
  253. package/node_modules/ws/package.json +0 -69
  254. package/node_modules/ws/wrapper.mjs +0 -8
  255. package/scripts/postinstall-link-sdk.js +0 -170
  256. package/skills/qqbot-media/SKILL.md +0 -60
  257. package/src/admin-resolver.ts +0 -181
  258. package/src/api.ts +0 -1333
  259. package/src/credential-backup.ts +0 -72
  260. package/src/deliver-debounce.ts +0 -229
  261. package/src/gateway.ts +0 -2272
  262. package/src/group-history.ts +0 -328
  263. package/src/image-server.ts +0 -675
  264. package/src/inbound-attachments.ts +0 -321
  265. package/src/known-users.ts +0 -353
  266. package/src/message-gating.ts +0 -190
  267. package/src/message-queue.ts +0 -354
  268. package/src/onboarding.ts +0 -282
  269. package/src/outbound-deliver.ts +0 -486
  270. package/src/outbound.ts +0 -1179
  271. package/src/ref-index-store.ts +0 -412
  272. package/src/reply-dispatcher.ts +0 -334
  273. package/src/session-store.ts +0 -303
  274. package/src/slash-commands.ts +0 -2431
  275. package/src/startup-greeting.ts +0 -120
  276. package/src/streaming.ts +0 -1077
  277. package/src/stt.ts +0 -86
  278. package/src/tools/channel.ts +0 -275
  279. package/src/transport/index.ts +0 -11
  280. package/src/transport/webhook-transport.ts +0 -332
  281. package/src/transport/webhook-verify.ts +0 -119
  282. package/src/typing-keepalive.ts +0 -59
  283. package/src/utils/audio-convert.ts +0 -887
  284. package/src/utils/chunked-upload.ts +0 -483
  285. package/src/utils/file-utils.ts +0 -193
  286. package/src/utils/image-size.ts +0 -266
  287. package/src/utils/media-send.ts +0 -636
  288. package/src/utils/media-tags.ts +0 -183
  289. package/src/utils/payload.ts +0 -265
  290. package/src/utils/text-parsing.ts +0 -85
  291. package/src/utils/upload-cache.ts +0 -128
@@ -1,223 +0,0 @@
1
- /**
2
- * Copyright 2020 Google LLC
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import URL from 'url';
18
- import VM from 'vm';
19
- import threads from 'worker_threads';
20
-
21
- const WORKER = Symbol.for('worker');
22
- const EVENTS = Symbol.for('events');
23
-
24
- class EventTarget {
25
- constructor() {
26
- Object.defineProperty(this, EVENTS, {
27
- value: new Map()
28
- });
29
- }
30
- dispatchEvent(event) {
31
- event.target = event.currentTarget = this;
32
- if (this['on'+event.type]) {
33
- try {
34
- this['on'+event.type](event);
35
- }
36
- catch (err) {
37
- console.error(err);
38
- }
39
- }
40
- const list = this[EVENTS].get(event.type);
41
- if (list == null) return;
42
- list.forEach(handler => {
43
- try {
44
- handler.call(this, event);
45
- }
46
- catch (err) {
47
- console.error(err);
48
- }
49
- });
50
- }
51
- addEventListener(type, fn) {
52
- let events = this[EVENTS].get(type);
53
- if (!events) this[EVENTS].set(type, events = []);
54
- events.push(fn);
55
- }
56
- removeEventListener(type, fn) {
57
- let events = this[EVENTS].get(type);
58
- if (events) {
59
- const index = events.indexOf(fn);
60
- if (index !== -1) events.splice(index, 1);
61
- }
62
- }
63
- }
64
-
65
- function Event(type, target) {
66
- this.type = type;
67
- this.timeStamp = Date.now();
68
- this.target = this.currentTarget = this.data = null;
69
- }
70
-
71
- // this module is used self-referentially on both sides of the
72
- // thread boundary, but behaves differently in each context.
73
- export default threads.isMainThread ? mainThread() : workerThread();
74
-
75
- const baseUrl = URL.pathToFileURL(process.cwd() + '/');
76
-
77
- function mainThread() {
78
-
79
- /**
80
- * A web-compatible Worker implementation atop Node's worker_threads.
81
- * - uses DOM-style events (Event.data, Event.type, etc)
82
- * - supports event handler properties (worker.onmessage)
83
- * - Worker() constructor accepts a module URL
84
- * - accepts the {type:'module'} option
85
- * - emulates WorkerGlobalScope within the worker
86
- * @param {string} url The URL or module specifier to load
87
- * @param {object} [options] Worker construction options
88
- * @param {string} [options.name] Available as `self.name` within the Worker
89
- * @param {string} [options.type="classic"] Pass "module" to create a Module Worker.
90
- */
91
- class Worker extends EventTarget {
92
- constructor(url, options) {
93
- super();
94
- const { name, type } = options || {};
95
- url += '';
96
- let mod;
97
- if (/^data:/.test(url)) {
98
- mod = url;
99
- }
100
- else {
101
- mod = URL.fileURLToPath(new URL.URL(url, baseUrl));
102
- }
103
- const worker = new threads.Worker(
104
- __filename,
105
- { workerData: { mod, name, type } }
106
- );
107
- Object.defineProperty(this, WORKER, {
108
- value: worker
109
- });
110
- worker.on('message', data => {
111
- const event = new Event('message');
112
- event.data = data;
113
- this.dispatchEvent(event);
114
- });
115
- worker.on('error', error => {
116
- error.type = 'error';
117
- this.dispatchEvent(error);
118
- });
119
- worker.on('exit', () => {
120
- this.dispatchEvent(new Event('close'));
121
- });
122
- }
123
- postMessage(data, transferList) {
124
- this[WORKER].postMessage(data, transferList);
125
- }
126
- terminate() {
127
- this[WORKER].terminate();
128
- }
129
- }
130
- Worker.prototype.onmessage = Worker.prototype.onerror = Worker.prototype.onclose = null;
131
- return Worker;
132
- }
133
-
134
- function workerThread() {
135
- let { mod, name, type } = threads.workerData || {};
136
- if (!mod) return mainThread();
137
-
138
- // turn global into a mock WorkerGlobalScope
139
- const self = global.self = global;
140
-
141
- // enqueue messages to dispatch after modules are loaded
142
- let q = [];
143
- function flush() {
144
- const buffered = q;
145
- q = null;
146
- buffered.forEach(event => { self.dispatchEvent(event); });
147
- }
148
- threads.parentPort.on('message', data => {
149
- const event = new Event('message');
150
- event.data = data;
151
- if (q == null) self.dispatchEvent(event);
152
- else q.push(event);
153
- });
154
- threads.parentPort.on('error', err => {
155
- err.type = 'Error';
156
- self.dispatchEvent(err);
157
- });
158
-
159
- class WorkerGlobalScope extends EventTarget {
160
- postMessage(data, transferList) {
161
- threads.parentPort.postMessage(data, transferList);
162
- }
163
- // Emulates https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope/close
164
- close() {
165
- process.exit();
166
- }
167
- }
168
- let proto = Object.getPrototypeOf(global);
169
- delete proto.constructor;
170
- Object.defineProperties(WorkerGlobalScope.prototype, proto);
171
- proto = Object.setPrototypeOf(global, new WorkerGlobalScope());
172
- ['postMessage', 'addEventListener', 'removeEventListener', 'dispatchEvent'].forEach(fn => {
173
- proto[fn] = proto[fn].bind(global);
174
- });
175
- global.name = name;
176
-
177
- const isDataUrl = /^data:/.test(mod);
178
- if (type === 'module') {
179
- import(mod)
180
- .catch(err => {
181
- if (isDataUrl && err.message === 'Not supported') {
182
- console.warn('Worker(): Importing data: URLs requires Node 12.10+. Falling back to classic worker.');
183
- return evaluateDataUrl(mod, name);
184
- }
185
- console.error(err);
186
- })
187
- .then(flush);
188
- }
189
- else {
190
- try {
191
- if (/^data:/.test(mod)) {
192
- evaluateDataUrl(mod, name);
193
- }
194
- else {
195
- require(mod);
196
- }
197
- }
198
- catch (err) {
199
- console.error(err);
200
- }
201
- Promise.resolve().then(flush);
202
- }
203
- }
204
-
205
- function evaluateDataUrl(url, name) {
206
- const { data } = parseDataUrl(url);
207
- return VM.runInThisContext(data, {
208
- filename: 'worker.<'+(name || 'data:')+'>'
209
- });
210
- }
211
-
212
- function parseDataUrl(url) {
213
- let [m, type, encoding, data] = url.match(/^data: *([^;,]*)(?: *; *([^,]*))? *,(.*)$/) || [];
214
- if (!m) throw Error('Invalid Data URL.');
215
- if (encoding) switch (encoding.toLowerCase()) {
216
- case 'base64':
217
- data = Buffer.from(data, 'base64').toString();
218
- break;
219
- default:
220
- throw Error('Unknown Data URL encoding "' + encoding + '"');
221
- }
222
- return { type, data };
223
- }
@@ -1,54 +0,0 @@
1
- {
2
- "name": "@eshaz/web-worker",
3
- "version": "1.2.2",
4
- "description": "Consistent Web Workers in browser and Node.",
5
- "main": "./cjs/node.js",
6
- "browser": "./cjs/browser.js",
7
- "types": "index.d.ts",
8
- "files": [
9
- "cjs",
10
- "browser.js",
11
- "node.js",
12
- "index.d.ts"
13
- ],
14
- "scripts": {
15
- "prepare": "babel node.js browser.js -d cjs",
16
- "test": "eslint '*.js' test && node --experimental-modules ./node_modules/.bin/ava"
17
- },
18
- "babel": {
19
- "plugins": [
20
- "@babel/plugin-syntax-dynamic-import",
21
- "babel-plugin-commonjs-lite"
22
- ]
23
- },
24
- "repository": "https://github.com/eshaz/web-worker",
25
- "keywords": [
26
- "worker",
27
- "worker_threads",
28
- "webworker",
29
- "web worker",
30
- "web-worker",
31
- "threads"
32
- ],
33
- "authors": [],
34
- "license": "Apache-2.0",
35
- "homepage": "https://github.com/eshaz/web-worker",
36
- "eslintConfig": {
37
- "extends": "developit",
38
- "rules": {
39
- "no-console": 0
40
- }
41
- },
42
- "devDependencies": {
43
- "@babel/cli": "^7.7.7",
44
- "@babel/core": "^7.7.7",
45
- "@babel/plugin-syntax-dynamic-import": "^7.7.4",
46
- "@babel/plugin-transform-modules-commonjs": "^7.7.5",
47
- "@babel/preset-env": "^7.7.7",
48
- "ava": "^2.4.0",
49
- "babel-plugin-commonjs-lite": "gist:3e38560d5bed35da1fd708d635e4acb3",
50
- "eslint": "^6.8.0",
51
- "eslint-config-developit": "^1.1.1",
52
- "eslint-plugin-compat": "^4.1.4"
53
- }
54
- }
@@ -1,5 +0,0 @@
1
- import WASMAudioDecoderCommon from "./src/WASMAudioDecoderCommon.js";
2
- import WASMAudioDecoderWorker from "./src/WASMAudioDecoderWorker.js";
3
- import { assignNames } from "./src/utilities.js";
4
-
5
- export { WASMAudioDecoderCommon, WASMAudioDecoderWorker, assignNames };
@@ -1,36 +0,0 @@
1
- {
2
- "name": "@wasm-audio-decoders/common",
3
- "version": "9.0.7",
4
- "description": "Web Assembly Audio Decoders Common",
5
- "module": "index.js",
6
- "main": "index.js",
7
- "exports": {
8
- "types": "./types.d.ts",
9
- "default": "./index.js"
10
- },
11
- "types": "types.d.ts",
12
- "sideEffects": false,
13
- "files": [
14
- "index.js",
15
- "types.d.ts",
16
- "src/*"
17
- ],
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/eshaz/wasm-audio-decoders.git"
21
- },
22
- "type": "module",
23
- "author": {
24
- "name": "Ethan Halsall",
25
- "email": "ethanhalsall@pm.me"
26
- },
27
- "license": "MIT",
28
- "bugs": {
29
- "url": "https://github.com/eshaz/wasm-audio-decoders/issues"
30
- },
31
- "homepage": "https://github.com/eshaz/wasm-audio-decoders/tree/master/src/common",
32
- "dependencies": {
33
- "@eshaz/web-worker": "1.2.2",
34
- "simple-yenc": "^1.0.4"
35
- }
36
- }
@@ -1,231 +0,0 @@
1
- import { decode } from "simple-yenc";
2
-
3
- export default function WASMAudioDecoderCommon() {
4
- // setup static methods
5
- const uint8Array = Uint8Array;
6
- const float32Array = Float32Array;
7
-
8
- if (!WASMAudioDecoderCommon.modules) {
9
- Object.defineProperties(WASMAudioDecoderCommon, {
10
- modules: {
11
- value: new WeakMap(),
12
- },
13
-
14
- setModule: {
15
- value(Ref, module) {
16
- WASMAudioDecoderCommon.modules.set(Ref, Promise.resolve(module));
17
- },
18
- },
19
-
20
- getModule: {
21
- value(Ref, wasmString) {
22
- let module = WASMAudioDecoderCommon.modules.get(Ref);
23
-
24
- if (!module) {
25
- if (!wasmString) {
26
- wasmString = Ref.wasm;
27
- module = WASMAudioDecoderCommon.inflateDynEncodeString(
28
- wasmString,
29
- ).then((data) => WebAssembly.compile(data));
30
- } else {
31
- module = WebAssembly.compile(decode(wasmString));
32
- }
33
-
34
- WASMAudioDecoderCommon.modules.set(Ref, module);
35
- }
36
-
37
- return module;
38
- },
39
- },
40
-
41
- concatFloat32: {
42
- value(buffers, length) {
43
- let ret = new float32Array(length),
44
- i = 0,
45
- offset = 0;
46
-
47
- while (i < buffers.length) {
48
- ret.set(buffers[i], offset);
49
- offset += buffers[i++].length;
50
- }
51
-
52
- return ret;
53
- },
54
- },
55
-
56
- getDecodedAudio: {
57
- value: (errors, channelData, samplesDecoded, sampleRate, bitDepth) => ({
58
- errors,
59
- channelData,
60
- samplesDecoded,
61
- sampleRate,
62
- bitDepth,
63
- }),
64
- },
65
-
66
- getDecodedAudioMultiChannel: {
67
- value(
68
- errors,
69
- input,
70
- channelsDecoded,
71
- samplesDecoded,
72
- sampleRate,
73
- bitDepth,
74
- ) {
75
- let channelData = [],
76
- i,
77
- j;
78
-
79
- for (i = 0; i < channelsDecoded; i++) {
80
- const channel = [];
81
- for (j = 0; j < input.length; ) channel.push(input[j++][i] || []);
82
- channelData.push(
83
- WASMAudioDecoderCommon.concatFloat32(channel, samplesDecoded),
84
- );
85
- }
86
-
87
- return WASMAudioDecoderCommon.getDecodedAudio(
88
- errors,
89
- channelData,
90
- samplesDecoded,
91
- sampleRate,
92
- bitDepth,
93
- );
94
- },
95
- },
96
-
97
- /*
98
- ******************
99
- * Compression Code
100
- ******************
101
- */
102
-
103
- inflateDynEncodeString: {
104
- value(source) {
105
- source = decode(source);
106
-
107
- return new Promise((resolve) => {
108
- // prettier-ignore
109
- const puffString = String.raw`dynEncode012804c7886d(‰›•)((()>+ˆ*§§)§ˆ,§§§§)§ˆ+§§§)§+.-()(*)-+)(ˆ.7*§)i¸¸,3§(i¸¸,3/G+.••—š¡*(,˜ŽŽ(,3‡‡‰˜‡Š‰›+)2å:-œ),§H(P*DI*H(P*@I++hH)H*r,hH(H(P*<J,i)’^*<H,H(P*4’U((I-H(H*i0’J,^*DH+H-H*œšI+H,I*4)33H(H*H)“^*DH(H+H)^*@H+i§H)œi§›™3æ*).§K(iH“I/+§H,iHn,§H+i(H+i(rCJ0I,H*I-+hH,,hH(H-V)(i)œ’J.H.W)(i)’c)(H,i)“I,H-i*’I-4)33i(I.*hH(V)(H+n5(H(i*’I-i(I,i)I.+hH,i*’J+iHn,hi(I-i*I,+hH,H/’H-c)(H,iFn,hi(I,+hH,H0n5-H*V)(J(,hH/H(i)œ’J(H(V)(J(i)’c)(H)H(i)œ’H,c)(3H*i*’I*H,i)’I,4(3(-H(H,’W)(H-’I-H,i*’I,4)3(3(3H,H-’I1H+I,H.i)œH1V)(“J.i(v5(33H.-H(H,’i(c)(H,i*’I,4)333–)-§i*I*+§H*iHn,hiž73H,H(i)8(H+šJ+H)P*(H*’V)(J-“r,§H)P*,H.i)œ’H+H,“i)œ’V)(-H*i*’I*H+i)œI+H-H.’I.H,H-’i)œI,4)333Ã+)-§iø7i(^*(iü7I,*h+hH+iDn,h*hilI+i)I,+hH+,hH+iô7’H,c)(i)H+i´8’W)(œH,’I,H+i*’I+4)-+hH(H)8*J-i(p5.*h*h*hH-i')u,hH(P*(J+,hH(P*0J,H(P*,n50H+H,’H-b((3H(P*0i)’I.4)3H-i¨*n5*H-iÅ*s,hiž73H-i)œJ+V)&+I,H(H+V)æ,8(I.H(H*8*J-i(p51H-i)œJ+i¸7’V)(H(H+iø7’V)(8(’J/H(P*0J+s,hi73H+H,H.’J,’I.H(P*(m5(H.H(P*,s5.+hH,m5*H(P*(J.H+’H.H+H/“’U((b((H(H(P*0i)’J+^*0H,i)“I,4(3(3H(H.^*03H-i¨*o5)33i(73(3(3-H,H+i)žc)(H,i*’I,H+i)’I+4)33i)I-3H-3!2)0§K(i2“J,L(H,H(^*(H,H*^*4H,i(^*0H,i(^*DH,j(_*<H,H)P*(^*,H,H+P*(^*8*h*h+hH,i)8(I3i§I**h*h*h*h*h*h*hH,i*8(6+(),03H,j(_*@i*I-H,P*<J.i,’J(H,P*8J/s50H,H.i+’J0^*<i¦I*H.H,P*4J1’J.U(*H.U((J2›i')o5/H.U()I.H,H(^*<H0H1’U((H.i0œJ.i§›i0ži')™o5/H/H.H2šJ*H(’J.q50H,P*0J/H*’I-H,P*(J0,hH,P*,H-q,hi)I-423+hH*m5+H/H0’H(H1’U((b((H/i)’I/H(i)’I(H*i)“I*4(3(3H,H.^*<H,H-^*04*3iØ1U((5+i(I(i¨7i1^*(i$6iè1^*(i°7iè6^*(i¬7iÈ6^*(+hH(iÈ*n,hiÈ*I(+hH(i¨,n,hi¨,I(+hH(iØ,n,hiØ,I(+hH(iè,o,hH,i-’H(’i0c)(H(i*’I(4)33iè1i1H,i-’iÈ*8)Bi(I(+hH(ido,hH,i-’H(’i-c)(H(i*’I(4)33iÈ6iè6H,i-’iF8)BiØ1i)b((41-H,i-’H(’i/c)(H(i*’I(4)3(3(-H,i-’H(’i1c)(H(i*’I(4)3(3(-H,i-’H(’i0c)(H(i*’I(4)3(3(3H,H/^*0H,H(^*<3i(I*4*3H,H,i¸)’^*TH,H,iø-’^*PH,H,iX’^*LH,H,i(’^*HH,i-8(I(H,i-8(I-i¥I*H,i,8(I.H(iErH-iErš5)H(i©*’I1H-i)’I0i(i;H.i,’J(i(H(i(rCJ(“J*H*i;sCI*i¨1I-H(I/+hH/,hH,i-’H-V)(i)œ’H,i+8(c)(H/i)“I/H-i*’I-H*i)’I*4)-H(i)œi¨1’I/+hH(H*o,hH,i-’H/V)(i)œ’i(c)(H/i*’I/H(i)’I(4)33i¤I*H,iø-’H,i¸)’H,i-’i;8)5+H0H1’I2i(I-+hH-H2p,hH,H,iP’8*J*i(p5-H*i7u,hH,i-’H-i)œ’H*c)(H-i)’I-4*3i(I/i+I.i+I(*h*h*hH*i8“6*(*)3H-m,hi£I*403H-i)œH,’W)-I/i*I(4)3i3I.i/I(3H2H,H(8(H.’J(H-’J.p,hi¢I*4.3H,i-’H-i)œ’I*+hH(,hH*H/c)(H*i*’I*H(i)“I(4)-H.I-4+3(3(33H,W)1m,hiŸI*4,3H,iø-’H,i¸)’H,i-’H18)J(,hi¡I*H(i(p5,H1H,V)ú-H,V)ø-’o5,3H,i(’H,iX’H,i-’H1i)œ’H08)J(,hi I*H(i(p5,H0H,V)šH,V)˜’o5,3H,H,iP’H,iH’8+I*4+3(3(3H,i$6i¬78+I*3H*H3šm5(3i)I-H*i(r5)3H)H,P*0^*(H+H,P*<^*(H*I-3H,i2’L(H-33Á)+(i¨03b+(,(-(.(/(0(1(2(3(5(7(9(;(?(C(G(K(S([(c(k({(‹(›(«(Ë(ë( (*)(iø03O)()()()(*(*(*(*(+(+(+(+(,(,(,(,(-(-(-(-(i¨13M8(9(:(((0(/(1(.(2(-(3(,(4(+(5(*(6()(7(T7œ‰šœ‡Ž‰œš›*S7•œ‰Š”U”—Љ”›S0›‘–U œ`;
110
-
111
- WASMAudioDecoderCommon.getModule(WASMAudioDecoderCommon, puffString)
112
- .then((wasm) => WebAssembly.instantiate(wasm, {}))
113
- .then(({ exports }) => {
114
- // required for minifiers that mangle the __heap_base property
115
- const instanceExports = new Map(Object.entries(exports));
116
-
117
- const puff = instanceExports.get("puff");
118
- const memory = instanceExports.get("memory")["buffer"];
119
- const dataArray = new uint8Array(memory);
120
- const heapView = new DataView(memory);
121
-
122
- let heapPos = instanceExports.get("__heap_base");
123
-
124
- // source length
125
- const sourceLength = source.length;
126
- const sourceLengthPtr = heapPos;
127
- heapPos += 4;
128
- heapView.setInt32(sourceLengthPtr, sourceLength, true);
129
-
130
- // source data
131
- const sourcePtr = heapPos;
132
- heapPos += sourceLength;
133
- dataArray.set(source, sourcePtr);
134
-
135
- // destination length
136
- const destLengthPtr = heapPos;
137
- heapPos += 4;
138
- heapView.setInt32(
139
- destLengthPtr,
140
- dataArray.byteLength - heapPos,
141
- true,
142
- );
143
-
144
- // destination data fills in the rest of the heap
145
- puff(heapPos, destLengthPtr, sourcePtr, sourceLengthPtr);
146
-
147
- resolve(
148
- dataArray.slice(
149
- heapPos,
150
- heapPos + heapView.getInt32(destLengthPtr, true),
151
- ),
152
- );
153
- });
154
- });
155
- },
156
- },
157
- });
158
- }
159
-
160
- Object.defineProperty(this, "wasm", {
161
- enumerable: true,
162
- get: () => this._wasm,
163
- });
164
-
165
- this.getOutputChannels = (outputData, channelsDecoded, samplesDecoded) => {
166
- let output = [],
167
- i = 0;
168
-
169
- while (i < channelsDecoded)
170
- output.push(
171
- outputData.slice(
172
- i * samplesDecoded,
173
- i++ * samplesDecoded + samplesDecoded,
174
- ),
175
- );
176
-
177
- return output;
178
- };
179
-
180
- this.allocateTypedArray = (len, TypedArray, setPointer = true) => {
181
- const ptr = this._wasm.malloc(TypedArray.BYTES_PER_ELEMENT * len);
182
- if (setPointer) this._pointers.add(ptr);
183
-
184
- return {
185
- ptr: ptr,
186
- len: len,
187
- buf: new TypedArray(this._wasm.HEAP, ptr, len),
188
- };
189
- };
190
-
191
- this.free = () => {
192
- this._pointers.forEach((ptr) => {
193
- this._wasm.free(ptr);
194
- });
195
- this._pointers.clear();
196
- };
197
-
198
- this.codeToString = (ptr) => {
199
- const characters = [],
200
- heap = new Uint8Array(this._wasm.HEAP);
201
- for (let character = heap[ptr]; character !== 0; character = heap[++ptr])
202
- characters.push(character);
203
-
204
- return String.fromCharCode.apply(null, characters);
205
- };
206
-
207
- this.addError = (
208
- errors,
209
- message,
210
- frameLength,
211
- frameNumber,
212
- inputBytes,
213
- outputSamples,
214
- ) => {
215
- errors.push({
216
- message: message,
217
- frameLength: frameLength,
218
- frameNumber: frameNumber,
219
- inputBytes: inputBytes,
220
- outputSamples: outputSamples,
221
- });
222
- };
223
-
224
- this.instantiate = (_EmscriptenWASM, _module) => {
225
- if (_module) WASMAudioDecoderCommon.setModule(_EmscriptenWASM, _module);
226
- this._wasm = new _EmscriptenWASM(WASMAudioDecoderCommon).instantiate();
227
- this._pointers = new Set();
228
-
229
- return this._wasm.ready.then(() => this);
230
- };
231
- }
@@ -1,129 +0,0 @@
1
- import NodeWorker from "@eshaz/web-worker";
2
- import WASMAudioDecoderCommon from "./WASMAudioDecoderCommon.js";
3
-
4
- const getWorker = () => globalThis.Worker || NodeWorker;
5
-
6
- export default class WASMAudioDecoderWorker extends getWorker() {
7
- constructor(options, name, Decoder, EmscriptenWASM) {
8
- if (!WASMAudioDecoderCommon.modules) new WASMAudioDecoderCommon();
9
-
10
- let source = WASMAudioDecoderCommon.modules.get(Decoder);
11
-
12
- if (!source) {
13
- let type = "text/javascript",
14
- isNode,
15
- webworkerSourceCode =
16
- "'use strict';" +
17
- // dependencies need to be manually resolved when stringifying this function
18
- `(${((_Decoder, _WASMAudioDecoderCommon, _EmscriptenWASM) => {
19
- // We're in a Web Worker
20
-
21
- // setup Promise that will be resolved once the WebAssembly Module is received
22
- let decoder,
23
- moduleResolve,
24
- modulePromise = new Promise((resolve) => {
25
- moduleResolve = resolve;
26
- });
27
-
28
- self.onmessage = ({ data: { id, command, data } }) => {
29
- let messagePromise = modulePromise,
30
- messagePayload = { id },
31
- transferList;
32
-
33
- if (command === "init") {
34
- Object.defineProperties(_Decoder, {
35
- WASMAudioDecoderCommon: { value: _WASMAudioDecoderCommon },
36
- EmscriptenWASM: { value: _EmscriptenWASM },
37
- module: { value: data.module },
38
- isWebWorker: { value: true },
39
- });
40
-
41
- decoder = new _Decoder(data.options);
42
- moduleResolve();
43
- } else if (command === "free") {
44
- decoder.free();
45
- } else if (command === "ready") {
46
- messagePromise = messagePromise.then(() => decoder.ready);
47
- } else if (command === "reset") {
48
- messagePromise = messagePromise.then(() => decoder.reset());
49
- } else {
50
- // "decode":
51
- // "decodeFrame":
52
- // "decodeFrames":
53
- Object.assign(
54
- messagePayload,
55
- decoder[command](
56
- // detach buffers
57
- Array.isArray(data)
58
- ? data.map((data) => new Uint8Array(data))
59
- : new Uint8Array(data),
60
- ),
61
- );
62
- // The "transferList" parameter transfers ownership of channel data to main thread,
63
- // which avoids copying memory.
64
- transferList = messagePayload.channelData
65
- ? messagePayload.channelData.map((channel) => channel.buffer)
66
- : [];
67
- }
68
-
69
- messagePromise.then(() =>
70
- self.postMessage(messagePayload, transferList),
71
- );
72
- };
73
- }).toString()})(${Decoder}, ${WASMAudioDecoderCommon}, ${EmscriptenWASM})`;
74
-
75
- try {
76
- isNode = typeof process.versions.node !== "undefined";
77
- } catch {}
78
-
79
- source = isNode
80
- ? `data:${type};base64,${Buffer.from(webworkerSourceCode).toString(
81
- "base64",
82
- )}`
83
- : URL.createObjectURL(new Blob([webworkerSourceCode], { type }));
84
-
85
- WASMAudioDecoderCommon.modules.set(Decoder, source);
86
- }
87
-
88
- super(source, { name });
89
-
90
- this._id = Number.MIN_SAFE_INTEGER;
91
- this._enqueuedOperations = new Map();
92
-
93
- this.onmessage = ({ data }) => {
94
- const { id, ...rest } = data;
95
- this._enqueuedOperations.get(id)(rest);
96
- this._enqueuedOperations.delete(id);
97
- };
98
-
99
- new EmscriptenWASM(WASMAudioDecoderCommon).getModule().then((module) => {
100
- this.postToDecoder("init", { module, options });
101
- });
102
- }
103
-
104
- async postToDecoder(command, data) {
105
- return new Promise((resolve) => {
106
- this.postMessage({
107
- command,
108
- id: this._id,
109
- data,
110
- });
111
-
112
- this._enqueuedOperations.set(this._id++, resolve);
113
- });
114
- }
115
-
116
- get ready() {
117
- return this.postToDecoder("ready");
118
- }
119
-
120
- async free() {
121
- await this.postToDecoder("free").finally(() => {
122
- this.terminate();
123
- });
124
- }
125
-
126
- async reset() {
127
- await this.postToDecoder("reset");
128
- }
129
- }