@harmonia-audio/native 0.1.4 → 0.1.6

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.
package/index.js CHANGED
@@ -1,84 +1,146 @@
1
- import { createRequire } from 'module';
2
- const require = createRequire(import.meta.url);
3
- const { platform, arch } = process;
4
-
5
- let nativeBinding = null;
6
-
7
- // Логика выбора бинарника в зависимости от ОС
8
- try {
9
- if (platform === 'win32' && arch === 'x64') {
10
- nativeBinding = require('./harmonia.win32-x64-msvc.node');
11
- } else if (platform === 'linux') {
12
- if (arch === 'x64') nativeBinding = require('./harmonia.linux-x64-gnu.node');
13
- else if (arch === 'arm64') nativeBinding = require('./harmonia.linux-arm64-gnu.node');
14
- } else if (platform === 'darwin') {
15
- if (arch === 'x64') nativeBinding = require('./harmonia.darwin-x64.node');
16
- else if (arch === 'arm64') nativeBinding = require('./harmonia.darwin-arm64.node');
17
- }
18
- } catch (e) {
19
- // Игнорируем ошибки здесь, попробуем фолбэк
20
- }
21
-
22
- if (!nativeBinding) {
23
- try {
24
- // Фолбэк для локальной сборки (napi build)
25
- nativeBinding = require('./harmonia.node');
26
- } catch (e) {
27
- throw new Error(`[Harmonia] Failed to load native binding for ${platform}-${arch}. Ensure the .node file exists in the package.`);
28
- }
29
- }
30
-
31
- /**
32
- * Автоматический экспорт всех свойств из нативного модуля.
33
- * Это гарантирует, что OpusEncoder, AudioThread, BiquadFilter,
34
- * и все DSP функции (applyVolume и т.д.) будут доступны.
35
- */
36
- export const {
37
- // Кодеки
38
- OpusEncoder,
39
- OpusDecoder,
40
- opusPacketGetNbChannelsNative,
41
- opusPacketGetNbFramesNative,
42
- opusPacketGetSamplesPerFrameNative,
43
-
44
- // Криптография
45
- sodiumInitialize,
46
- randomBytes,
47
- secretboxEncrypt,
48
- secretboxDecrypt,
49
- xchacha20Encrypt,
50
- xchacha20Decrypt,
51
- aes256gcmAvailable,
52
- aes256gcmEncrypt,
53
-
54
- // RTP & Сеть
55
- buildRtpHeader,
56
- parseRtpHeader,
57
- getRtpPayloadOffset,
58
- RtpPacketBuilder,
59
- configureSocketForAudio,
60
-
61
- // Потоки и буферы
62
- AudioThread,
63
- AudioRingBuffer,
64
-
65
- // DSP & Эффекты (то, что ты заметил)
66
- applyVolume,
67
- stereoWiden,
68
- monoDownmix,
69
- mixAudioStreams,
70
- BiquadFilter,
71
- Compressor,
72
- NoiseGate,
73
- Delay,
74
- LoudnessNormalizer,
75
- ConvolutionReverb,
76
- PhaseVocoder,
77
-
78
- // VAD & Системное
79
- VoiceActivityDetector,
80
- checkIoUringSupport
81
- } = nativeBinding;
82
-
83
- // Дефолтный экспорт для полной совместимости
84
- export default nativeBinding;
1
+ /* eslint-disable */
2
+ /* auto-generated by harmonia — cross-platform native loader */
3
+
4
+ const { existsSync, readFileSync } = require('fs');
5
+ const { join } = require('path');
6
+
7
+ const { platform, arch } = process;
8
+
9
+ let nativeBinding = null;
10
+ let loadError = null;
11
+
12
+ function isMusl() {
13
+ if (!process.report || typeof process.report.getReport !== 'function') {
14
+ try {
15
+ const lddPath = require('child_process')
16
+ .execSync('which ldd')
17
+ .toString()
18
+ .trim();
19
+ return readFileSync(lddPath, 'utf8').includes('musl');
20
+ } catch {
21
+ return true;
22
+ }
23
+ } else {
24
+ const report = process.report.getReport();
25
+ const header =
26
+ typeof report === 'string' ? JSON.parse(report).header : report.header;
27
+ return !header.glibcVersionRuntime;
28
+ }
29
+ }
30
+
31
+ function tryLoad(localName, packageName) {
32
+ // 1. Попытка загрузить локальный .node (dev-сборка)
33
+ const localPath = join(__dirname, `${localName}.node`);
34
+ if (existsSync(localPath)) {
35
+ try {
36
+ return require(localPath);
37
+ } catch (e) {
38
+ loadError = e;
39
+ }
40
+ }
41
+ // 2. Попытка загрузить из платформенного npm-пакета
42
+ try {
43
+ return require(packageName);
44
+ } catch (e) {
45
+ loadError = e;
46
+ }
47
+ return null;
48
+ }
49
+
50
+ switch (platform) {
51
+ case 'win32':
52
+ switch (arch) {
53
+ case 'x64':
54
+ nativeBinding = tryLoad(
55
+ 'harmonia.win32-x64-msvc',
56
+ '@harmonia-audio/native-win32-x64-msvc',
57
+ );
58
+ break;
59
+ default:
60
+ throw new Error(`Unsupported architecture on Windows: ${arch}`);
61
+ }
62
+ break;
63
+
64
+ case 'darwin':
65
+ switch (arch) {
66
+ case 'x64':
67
+ nativeBinding = tryLoad(
68
+ 'harmonia.darwin-x64',
69
+ '@harmonia-audio/native-darwin-x64',
70
+ );
71
+ break;
72
+ case 'arm64':
73
+ nativeBinding = tryLoad(
74
+ 'harmonia.darwin-arm64',
75
+ '@harmonia-audio/native-darwin-arm64',
76
+ );
77
+ break;
78
+ default:
79
+ throw new Error(`Unsupported architecture on macOS: ${arch}`);
80
+ }
81
+ break;
82
+
83
+ case 'freebsd':
84
+ switch (arch) {
85
+ case 'x64':
86
+ nativeBinding = tryLoad(
87
+ 'harmonia.freebsd-x64',
88
+ '@harmonia-audio/native-freebsd-x64',
89
+ );
90
+ break;
91
+ default:
92
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
93
+ }
94
+ break;
95
+
96
+ case 'linux':
97
+ switch (arch) {
98
+ case 'x64':
99
+ if (isMusl()) {
100
+ nativeBinding = tryLoad(
101
+ 'harmonia.linux-x64-musl',
102
+ '@harmonia-audio/native-linux-x64-musl',
103
+ );
104
+ } else {
105
+ nativeBinding = tryLoad(
106
+ 'harmonia.linux-x64-gnu',
107
+ '@harmonia-audio/native-linux-x64-gnu',
108
+ );
109
+ }
110
+ break;
111
+ case 'arm64':
112
+ if (isMusl()) {
113
+ nativeBinding = tryLoad(
114
+ 'harmonia.linux-arm64-musl',
115
+ '@harmonia-audio/native-linux-arm64-musl',
116
+ );
117
+ } else {
118
+ nativeBinding = tryLoad(
119
+ 'harmonia.linux-arm64-gnu',
120
+ '@harmonia-audio/native-linux-arm64-gnu',
121
+ );
122
+ }
123
+ break;
124
+ default:
125
+ throw new Error(`Unsupported architecture on Linux: ${arch}`);
126
+ }
127
+ break;
128
+
129
+ default:
130
+ throw new Error(
131
+ `Unsupported OS: ${platform}, architecture: ${arch}`,
132
+ );
133
+ }
134
+
135
+ if (!nativeBinding) {
136
+ if (loadError) {
137
+ throw loadError;
138
+ }
139
+ throw new Error(
140
+ `Failed to load native binding for ${platform}-${arch}. ` +
141
+ 'Ensure the correct optional dependency is installed:\n' +
142
+ ' npm install @harmonia-audio/native',
143
+ );
144
+ }
145
+
146
+ module.exports = nativeBinding;
package/package.json CHANGED
@@ -1,45 +1,46 @@
1
1
  {
2
2
  "name": "@harmonia-audio/native",
3
- "version": "0.1.4",
4
- "private": false,
3
+ "version": "0.1.6",
4
+ "description": "Native Rust bindings for harmonia audio library",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "files": [
9
9
  "index.js",
10
- "index.d.ts",
11
- "*.node"
10
+ "index.d.ts"
12
11
  ],
13
12
  "napi": {
14
13
  "binaryName": "harmonia",
15
14
  "packageName": "@harmonia-audio/native",
16
15
  "targets": [
17
16
  "x86_64-apple-darwin",
17
+ "aarch64-apple-darwin",
18
18
  "x86_64-pc-windows-msvc",
19
19
  "x86_64-unknown-linux-gnu",
20
20
  "x86_64-unknown-linux-musl",
21
- "aarch64-unknown-linux-gnu",
22
21
  "aarch64-unknown-linux-musl",
23
- "aarch64-apple-darwin",
24
22
  "x86_64-unknown-freebsd"
25
23
  ]
26
24
  },
27
- "devDependencies": {
28
- "@napi-rs/cli": "^3.0.0"
25
+ "scripts": {
26
+ "artifacts": "napi artifacts",
27
+ "build": "napi build --platform --release && node fix-dts.js",
28
+ "build:debug": "napi build --platform && node fix-dts.js",
29
+ "prepublishOnly": "node fix-dts.js"
29
30
  },
30
31
  "optionalDependencies": {
31
- "@harmonia-audio/native-darwin-x64": "0.1.4",
32
- "@harmonia-audio/native-win32-x64-msvc": "0.1.4",
33
- "@harmonia-audio/native-linux-x64-gnu": "0.1.4",
34
- "@harmonia-audio/native-linux-x64-musl": "0.1.4",
35
- "@harmonia-audio/native-linux-arm64-gnu": "0.1.4",
36
- "@harmonia-audio/native-linux-arm64-musl": "0.1.4",
37
- "@harmonia-audio/native-darwin-arm64": "0.1.4",
38
- "@harmonia-audio/native-freebsd-x64": "0.1.4"
32
+ "@harmonia-audio/native-darwin-x64": "0.1.6",
33
+ "@harmonia-audio/native-darwin-arm64": "0.1.6",
34
+ "@harmonia-audio/native-win32-x64-msvc": "0.1.6",
35
+ "@harmonia-audio/native-linux-x64-gnu": "0.1.6",
36
+ "@harmonia-audio/native-linux-x64-musl": "0.1.6",
37
+ "@harmonia-audio/native-linux-arm64-musl": "0.1.6",
38
+ "@harmonia-audio/native-freebsd-x64": "0.1.6"
39
39
  },
40
- "scripts": {
41
- "artifacts": "napi artifacts",
42
- "build": "if [ \"$SKIP_NATIVE_BUILD\" = \"true\" ]; then echo 'Skipping native build...'; else napi build --platform --release && node fix-dts.js; fi",
43
- "build:debug": "napi build --platform && node fix-dts.js"
40
+ "devDependencies": {
41
+ "@napi-rs/cli": "^3.0.0"
42
+ },
43
+ "engines": {
44
+ "node": ">=20.0.0"
44
45
  }
45
- }
46
+ }
Binary file
package/harmonia.node DELETED
Binary file