@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,223 @@
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
+ }
@@ -0,0 +1,54 @@
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
+ }
@@ -0,0 +1,5 @@
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 };
@@ -0,0 +1,36 @@
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
+ }
@@ -0,0 +1,231 @@
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
+ }
@@ -0,0 +1,129 @@
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
+ }