diff --git a/.github/workflows/node-builds.yml b/.github/workflows/node-builds.yml index 2999f4556..34ec64d6a 100644 --- a/.github/workflows/node-builds.yml +++ b/.github/workflows/node-builds.yml @@ -6,62 +6,14 @@ permissions: on: workflow_dispatch: - inputs: - tag: - required: true - type: string workflow_call: - inputs: - tag: - required: true - type: string env: CARGO_TERM_COLOR: always - TAG_NAME: ${{ inputs.tag || github.ref_name }} APP_NAME: rtc-node jobs: - bump_version: - runs-on: macos-15 - outputs: - commit_sha: ${{ steps.commit.outputs.commit_long_sha }} - steps: - - uses: actions/checkout@v6 - - - uses: pnpm/action-setup@v4 - with: - package_json_file: livekit-ffi-node-bindings/package.json - - - name: Setup node - uses: actions/setup-node@v6 - with: - node-version: 24 - cache: pnpm - cache-dependency-path: livekit-ffi-node-bindings/pnpm-lock.yaml - - - working-directory: livekit-ffi-node-bindings - run: pnpm install - - - name: Set package version from tag - working-directory: livekit-ffi-node-bindings - run: | - # Extract version from tag (e.g., rust-sdks/livekit-ffi@0.12.43 -> 0.12.43) - VERSION=$(echo "${{ env.TAG_NAME }}" | sed 's/.*@//') - echo "Setting package version to $VERSION" - npm version $VERSION --no-git-tag-version - pnpm run ci:version - - - name: Add changes - id: commit - uses: EndBug/add-and-commit@v9 - with: - add: '["**/package.json"]' - default_author: github_actions - message: bump livekit-ffi-node-binding version - build: - needs: bump_version strategy: fail-fast: false matrix: @@ -94,8 +46,6 @@ jobs: - uses: actions/checkout@v6 with: submodules: recursive - ref: ${{ needs.bump_version.outputs.commit_sha }} - fetch-depth: 0 - uses: pnpm/action-setup@v4 with: package_json_file: livekit-ffi-node-bindings/package.json @@ -204,17 +154,13 @@ jobs: path: livekit-ffi-node-bindings/native.* if-no-files-found: error - commit_and_release: - needs: [bump_version, build] - name: Commit and Release + release: + needs: [build] + name: Release runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - - run: git fetch origin ${{ needs.bump_version.outputs.commit_sha }} - - - run: git reset --hard ${{ needs.bump_version.outputs.commit_sha }} - - uses: pnpm/action-setup@v4 with: package_json_file: livekit-ffi-node-bindings/package.json @@ -241,13 +187,6 @@ jobs: name: js-bindings path: livekit-ffi-node-bindings - - name: Add changes - uses: EndBug/add-and-commit@v9 - with: - add: '["livekit-ffi-node-bindings/native.js", "livekit-ffi-node-bindings/native.d.ts"]' - default_author: github_actions - message: update js bindings for release - - name: Move artifacts run: pnpm run ci:artifacts working-directory: livekit-ffi-node-bindings @@ -258,4 +197,4 @@ jobs: - name: Publish working-directory: livekit-ffi-node-bindings - run: pnpm publish -r + run: pnpm publish -r --no-git-checks diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bd3984935..434a71ba3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -81,8 +81,6 @@ jobs: if: ${{ needs.release-plz-release.outputs.ffi_tag != '' }} uses: ./.github/workflows/node-builds.yml needs: release-plz-release - with: - tag: ${{ needs.release-plz-release.outputs.ffi_tag }} # Create a PR with the new versions and changelog, preparing the next release. release-plz-pr: @@ -128,3 +126,50 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }} + + - name: Checkout release-plz PR branch + id: checkout-pr + run: | + PR_BRANCH=$(gh pr list --author "github-actions[bot]" --state open --json headRefName --jq '[.[] | select(.headRefName | startswith("release-plz-"))][0].headRefName // empty') + if [ -z "$PR_BRANCH" ]; then + echo "No release-plz PR found, skipping" + echo "found=false" >> $GITHUB_OUTPUT + exit 0 + fi + echo "found=true" >> $GITHUB_OUTPUT + git fetch origin "$PR_BRANCH" + git checkout "$PR_BRANCH" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup pnpm + if: steps.checkout-pr.outputs.found == 'true' + uses: pnpm/action-setup@v4 + with: + package_json_file: livekit-ffi-node-bindings/package.json + + - name: Setup node + if: steps.checkout-pr.outputs.found == 'true' + uses: actions/setup-node@v6 + with: + node-version: 24 + cache: pnpm + cache-dependency-path: livekit-ffi-node-bindings/pnpm-lock.yaml + + - name: Update node package.json versions + if: steps.checkout-pr.outputs.found == 'true' + working-directory: livekit-ffi-node-bindings + run: | + pnpm install + FFI_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' ../livekit-ffi/Cargo.toml) + echo "Setting node package version to $FFI_VERSION" + npm version $FFI_VERSION --no-git-tag-version + pnpm run ci:version + + - name: Add changes + if: steps.checkout-pr.outputs.found == 'true' + uses: EndBug/add-and-commit@v9 + with: + add: '["livekit-ffi-node-bindings/package.json", "livekit-ffi-node-bindings/npm/*/package.json"]' + default_author: github_actions + message: bump node ffi bindings version diff --git a/livekit-ffi-node-bindings/.gitignore b/livekit-ffi-node-bindings/.gitignore index aafaddeb5..aa22c2783 100644 --- a/livekit-ffi-node-bindings/.gitignore +++ b/livekit-ffi-node-bindings/.gitignore @@ -196,4 +196,8 @@ Cargo.lock !.yarn/sdks !.yarn/versions + +# don't commit the build artifacts from napi *.node +native.d.ts +native.js diff --git a/livekit-ffi-node-bindings/native.d.ts b/livekit-ffi-node-bindings/native.d.ts deleted file mode 100644 index a1483a6c7..000000000 --- a/livekit-ffi-node-bindings/native.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* auto-generated by NAPI-RS */ -/* eslint-disable */ -export declare class FfiHandle { - constructor(handle: bigint) - dispose(): void - get handle(): bigint -} - -export declare function livekitCopyBuffer(ptr: bigint, len: number): Uint8Array - -export declare function livekitDispose(): Promise - -export declare function livekitFfiRequest(data: Uint8Array): Uint8Array - -export declare function livekitInitialize(callback: (data: Uint8Array) => void, captureLogs: boolean, sdkVersion: string): void - -export declare function livekitRetrievePtr(handle: Uint8Array): bigint diff --git a/livekit-ffi-node-bindings/native.js b/livekit-ffi-node-bindings/native.js deleted file mode 100644 index d79a70df2..000000000 --- a/livekit-ffi-node-bindings/native.js +++ /dev/null @@ -1,584 +0,0 @@ -// prettier-ignore -/* eslint-disable */ -// @ts-nocheck -/* auto-generated by NAPI-RS */ - -const { readFileSync } = require('node:fs') -let nativeBinding = null -const loadErrors = [] - -const isMusl = () => { - let musl = false - if (process.platform === 'linux') { - musl = isMuslFromFilesystem() - if (musl === null) { - musl = isMuslFromReport() - } - if (musl === null) { - musl = isMuslFromChildProcess() - } - } - return musl -} - -const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-') - -const isMuslFromFilesystem = () => { - try { - return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl') - } catch { - return null - } -} - -const isMuslFromReport = () => { - let report = null - if (typeof process.report?.getReport === 'function') { - process.report.excludeNetwork = true - report = process.report.getReport() - } - if (!report) { - return null - } - if (report.header && report.header.glibcVersionRuntime) { - return false - } - if (Array.isArray(report.sharedObjects)) { - if (report.sharedObjects.some(isFileMusl)) { - return true - } - } - return false -} - -const isMuslFromChildProcess = () => { - try { - return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl') - } catch (e) { - // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false - return false - } -} - -function requireNative() { - if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) { - try { - return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH); - } catch (err) { - loadErrors.push(err) - } - } else if (process.platform === 'android') { - if (process.arch === 'arm64') { - try { - return require('./rtc-node.android-arm64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-android-arm64') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-android-arm64/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm') { - try { - return require('./rtc-node.android-arm-eabi.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-android-arm-eabi') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-android-arm-eabi/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`)) - } - } else if (process.platform === 'win32') { - if (process.arch === 'x64') { - if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') { - try { - return require('./rtc-node.win32-x64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-win32-x64-gnu') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-win32-x64-gnu/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./rtc-node.win32-x64-msvc.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-win32-x64-msvc') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-win32-x64-msvc/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'ia32') { - try { - return require('./rtc-node.win32-ia32-msvc.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-win32-ia32-msvc') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-win32-ia32-msvc/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm64') { - try { - return require('./rtc-node.win32-arm64-msvc.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-win32-arm64-msvc') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-win32-arm64-msvc/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`)) - } - } else if (process.platform === 'darwin') { - try { - return require('./rtc-node.darwin-universal.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-darwin-universal') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-darwin-universal/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - if (process.arch === 'x64') { - try { - return require('./rtc-node.darwin-x64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-darwin-x64') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-darwin-x64/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm64') { - try { - return require('./rtc-node.darwin-arm64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-darwin-arm64') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-darwin-arm64/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`)) - } - } else if (process.platform === 'freebsd') { - if (process.arch === 'x64') { - try { - return require('./rtc-node.freebsd-x64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-freebsd-x64') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-freebsd-x64/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm64') { - try { - return require('./rtc-node.freebsd-arm64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-freebsd-arm64') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-freebsd-arm64/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`)) - } - } else if (process.platform === 'linux') { - if (process.arch === 'x64') { - if (isMusl()) { - try { - return require('./rtc-node.linux-x64-musl.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-x64-musl') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-x64-musl/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./rtc-node.linux-x64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-x64-gnu') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-x64-gnu/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'arm64') { - if (isMusl()) { - try { - return require('./rtc-node.linux-arm64-musl.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-arm64-musl') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-arm64-musl/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./rtc-node.linux-arm64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-arm64-gnu') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-arm64-gnu/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'arm') { - if (isMusl()) { - try { - return require('./rtc-node.linux-arm-musleabihf.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-arm-musleabihf') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-arm-musleabihf/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./rtc-node.linux-arm-gnueabihf.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-arm-gnueabihf') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-arm-gnueabihf/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'loong64') { - if (isMusl()) { - try { - return require('./rtc-node.linux-loong64-musl.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-loong64-musl') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-loong64-musl/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./rtc-node.linux-loong64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-loong64-gnu') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-loong64-gnu/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'riscv64') { - if (isMusl()) { - try { - return require('./rtc-node.linux-riscv64-musl.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-riscv64-musl') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-riscv64-musl/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - try { - return require('./rtc-node.linux-riscv64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-riscv64-gnu') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-riscv64-gnu/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } - } else if (process.arch === 'ppc64') { - try { - return require('./rtc-node.linux-ppc64-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-ppc64-gnu') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-ppc64-gnu/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 's390x') { - try { - return require('./rtc-node.linux-s390x-gnu.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-linux-s390x-gnu') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-linux-s390x-gnu/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`)) - } - } else if (process.platform === 'openharmony') { - if (process.arch === 'arm64') { - try { - return require('./rtc-node.openharmony-arm64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-openharmony-arm64') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-openharmony-arm64/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'x64') { - try { - return require('./rtc-node.openharmony-x64.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-openharmony-x64') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-openharmony-x64/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else if (process.arch === 'arm') { - try { - return require('./rtc-node.openharmony-arm.node') - } catch (e) { - loadErrors.push(e) - } - try { - const binding = require('@livekit/rtc-ffi-bindings-openharmony-arm') - const bindingPackageVersion = require('@livekit/rtc-ffi-bindings-openharmony-arm/package.json').version - if (bindingPackageVersion !== '0.12.46-dev.8' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') { - throw new Error(`Native binding package version mismatch, expected 0.12.46-dev.8 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`) - } - return binding - } catch (e) { - loadErrors.push(e) - } - } else { - loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`)) - } - } else { - loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`)) - } -} - -nativeBinding = requireNative() - -if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { - let wasiBinding = null - let wasiBindingError = null - try { - wasiBinding = require('./rtc-node.wasi.cjs') - nativeBinding = wasiBinding - } catch (err) { - if (process.env.NAPI_RS_FORCE_WASI) { - wasiBindingError = err - } - } - if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) { - try { - wasiBinding = require('@livekit/rtc-ffi-bindings-wasm32-wasi') - nativeBinding = wasiBinding - } catch (err) { - if (process.env.NAPI_RS_FORCE_WASI) { - if (!wasiBindingError) { - wasiBindingError = err - } else { - wasiBindingError.cause = err - } - loadErrors.push(err) - } - } - } - if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) { - const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error') - error.cause = wasiBindingError - throw error - } -} - -if (!nativeBinding) { - if (loadErrors.length > 0) { - throw new Error( - `Cannot find native binding. ` + - `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` + - 'Please try `npm i` again after removing both package-lock.json and node_modules directory.', - { - cause: loadErrors.reduce((err, cur) => { - cur.cause = err - return cur - }), - }, - ) - } - throw new Error(`Failed to load native binding`) -} - -module.exports = nativeBinding -module.exports.FfiHandle = nativeBinding.FfiHandle -module.exports.livekitCopyBuffer = nativeBinding.livekitCopyBuffer -module.exports.livekitDispose = nativeBinding.livekitDispose -module.exports.livekitFfiRequest = nativeBinding.livekitFfiRequest -module.exports.livekitInitialize = nativeBinding.livekitInitialize -module.exports.livekitRetrievePtr = nativeBinding.livekitRetrievePtr