Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support node v18 #349

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/flat-jeans-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-server-sdk': patch
---

support for node v18
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ jobs:

test:
name: Test
strategy:
matrix:
node-version: [18, 20, 22, latest]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Install dependencies
run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion packages/livekit-server-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
"vitest": "^2.0.0"
},
"engines": {
"node": ">=19"
"node": ">=18"
}
}
4 changes: 2 additions & 2 deletions packages/livekit-server-sdk/src/WebhookReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import type { BinaryReadOptions, JsonReadOptions, JsonValue } from '@bufbuild/protobuf';
import { WebhookEvent as ProtoWebhookEvent } from '@livekit/protocol';
import { TokenVerifier } from './AccessToken.js';
import digest from './digest.js';

export const authorizeHeader = 'Authorize';

Expand Down Expand Up @@ -66,8 +67,7 @@ export class WebhookReceiver {
}
const claims = await this.verifier.verify(authHeader);
// confirm sha
const encoder = new TextEncoder();
const hash = await crypto.subtle.digest('SHA-256', encoder.encode(body));
const hash = await digest(body);
const hashDecoded = btoa(
Array.from(new Uint8Array(hash))
.map((v) => String.fromCharCode(v))
Expand Down
14 changes: 14 additions & 0 deletions packages/livekit-server-sdk/src/digest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
//
// SPDX-License-Identifier: Apache-2.0

// Use the Web Crypto API if available, otherwise fallback to Node.js crypto
export default async function digest(data: string): Promise<ArrayBuffer> {
if (globalThis.crypto?.subtle) {
const encoder = new TextEncoder();
return crypto.subtle.digest('SHA-256', encoder.encode(data));
} else {
const nodeCrypto = await import('node:crypto');
return nodeCrypto.createHash('sha256').update(data).digest();
}
}
Loading