@harmonia-audio/native 0.1.5 → 0.1.7

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 (3) hide show
  1. package/index.js +128 -66
  2. package/package.json +22 -21
  3. package/harmonia.node +0 -0
package/index.js CHANGED
@@ -1,84 +1,146 @@
1
- import { createRequire } from 'module';
2
- const require = createRequire(import.meta.url);
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
+
3
7
  const { platform, arch } = process;
4
8
 
5
9
  let nativeBinding = null;
10
+ let loadError = null;
6
11
 
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');
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;
17
28
  }
18
- } catch (e) {
19
- // Игнорируем ошибки здесь, попробуем фолбэк
20
29
  }
21
30
 
22
- if (!nativeBinding) {
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-пакета
23
42
  try {
24
- // Фолбэк для локальной сборки (napi build)
25
- nativeBinding = require('./harmonia.node');
43
+ return require(packageName);
26
44
  } catch (e) {
27
- throw new Error(`[Harmonia] Failed to load native binding for ${platform}-${arch}. Ensure the .node file exists in the package.`);
45
+ loadError = e;
28
46
  }
47
+ return null;
29
48
  }
30
49
 
31
- /**
32
- * Автоматический экспорт всех свойств из нативного модуля.
33
- * Это гарантирует, что OpusEncoder, AudioThread, BiquadFilter,
34
- * и все DSP функции (applyVolume и т.д.) будут доступны.
35
- */
36
- export const {
37
- // Кодеки
38
- OpusEncoder,
39
- OpusDecoder,
40
- opusPacketGetNbChannelsNative,
41
- opusPacketGetNbFramesNative,
42
- opusPacketGetSamplesPerFrameNative,
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;
43
63
 
44
- // Криптография
45
- sodiumInitialize,
46
- randomBytes,
47
- secretboxEncrypt,
48
- secretboxDecrypt,
49
- xchacha20Encrypt,
50
- xchacha20Decrypt,
51
- aes256gcmAvailable,
52
- aes256gcmEncrypt,
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;
53
82
 
54
- // RTP & Сеть
55
- buildRtpHeader,
56
- parseRtpHeader,
57
- getRtpPayloadOffset,
58
- RtpPacketBuilder,
59
- configureSocketForAudio,
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;
60
95
 
61
- // Потоки и буферы
62
- AudioThread,
63
- AudioRingBuffer,
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;
64
128
 
65
- // DSP & Эффекты (то, что ты заметил)
66
- applyVolume,
67
- stereoWiden,
68
- monoDownmix,
69
- mixAudioStreams,
70
- BiquadFilter,
71
- Compressor,
72
- NoiseGate,
73
- Delay,
74
- LoudnessNormalizer,
75
- ConvolutionReverb,
76
- PhaseVocoder,
129
+ default:
130
+ throw new Error(
131
+ `Unsupported OS: ${platform}, architecture: ${arch}`,
132
+ );
133
+ }
77
134
 
78
- // VAD & Системное
79
- VoiceActivityDetector,
80
- checkIoUringSupport
81
- } = nativeBinding;
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
+ }
82
145
 
83
- // Дефолтный экспорт для полной совместимости
84
- export default nativeBinding;
146
+ module.exports = nativeBinding;
package/package.json CHANGED
@@ -1,45 +1,46 @@
1
1
  {
2
2
  "name": "@harmonia-audio/native",
3
- "version": "0.1.5",
4
- "private": false,
3
+ "version": "0.1.7",
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.5",
32
- "@harmonia-audio/native-win32-x64-msvc": "0.1.5",
33
- "@harmonia-audio/native-linux-x64-gnu": "0.1.5",
34
- "@harmonia-audio/native-linux-x64-musl": "0.1.5",
35
- "@harmonia-audio/native-linux-arm64-gnu": "0.1.5",
36
- "@harmonia-audio/native-linux-arm64-musl": "0.1.5",
37
- "@harmonia-audio/native-darwin-arm64": "0.1.5",
38
- "@harmonia-audio/native-freebsd-x64": "0.1.5"
32
+ "@harmonia-audio/native-darwin-x64": "0.1.7",
33
+ "@harmonia-audio/native-darwin-arm64": "0.1.7",
34
+ "@harmonia-audio/native-win32-x64-msvc": "0.1.7",
35
+ "@harmonia-audio/native-linux-x64-gnu": "0.1.7",
36
+ "@harmonia-audio/native-linux-x64-musl": "0.1.7",
37
+ "@harmonia-audio/native-linux-arm64-musl": "0.1.7",
38
+ "@harmonia-audio/native-freebsd-x64": "0.1.7"
39
39
  },
40
- "scripts": {
41
- "artifacts": "napi artifacts",
42
- "build": "if [ \"$SKIP_NATIVE_BUILD\" = \"true\" ]; then echo 'Skipping native build...' && node fix-dts.js; 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
+ }
package/harmonia.node DELETED
Binary file