Skip to content

Commit

Permalink
Add support for node v18 (#349)
Browse files Browse the repository at this point in the history
* support v18

* add license

* test node v18 in ci

* changeset

* test node v22 in ci

* test latest node version in ci
  • Loading branch information
lalitkapoor authored Dec 5, 2024
1 parent a77a256 commit e06bd48
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
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();
}
}

0 comments on commit e06bd48

Please sign in to comment.