livekit-server-sdk 2.3.0 → 2.5.0

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 (66) hide show
  1. package/README.md +80 -95
  2. package/dist/AccessToken.d.ts +15 -3
  3. package/dist/AccessToken.d.ts.map +1 -0
  4. package/dist/AccessToken.js +32 -3
  5. package/dist/AccessToken.js.map +1 -1
  6. package/dist/EgressClient.d.ts +1 -0
  7. package/dist/EgressClient.d.ts.map +1 -0
  8. package/dist/EgressClient.js +5 -2
  9. package/dist/EgressClient.js.map +1 -1
  10. package/dist/IngressClient.d.ts +1 -0
  11. package/dist/IngressClient.d.ts.map +1 -0
  12. package/dist/IngressClient.js +3 -0
  13. package/dist/IngressClient.js.map +1 -1
  14. package/dist/RoomServiceClient.d.ts +4 -2
  15. package/dist/RoomServiceClient.d.ts.map +1 -0
  16. package/dist/RoomServiceClient.js.map +1 -1
  17. package/dist/ServiceBase.d.ts +3 -2
  18. package/dist/ServiceBase.d.ts.map +1 -0
  19. package/dist/ServiceBase.js +7 -1
  20. package/dist/ServiceBase.js.map +1 -1
  21. package/dist/SipClient.d.ts +43 -1
  22. package/dist/SipClient.d.ts.map +1 -0
  23. package/dist/SipClient.js +111 -11
  24. package/dist/SipClient.js.map +1 -1
  25. package/dist/TwirpRPC.d.ts +1 -0
  26. package/dist/TwirpRPC.d.ts.map +1 -0
  27. package/dist/TwirpRPC.js.map +1 -1
  28. package/dist/WebhookReceiver.d.ts +2 -1
  29. package/dist/WebhookReceiver.d.ts.map +1 -0
  30. package/dist/WebhookReceiver.js.map +1 -1
  31. package/dist/grants.d.ts +12 -2
  32. package/dist/grants.d.ts.map +1 -0
  33. package/dist/grants.js +3 -0
  34. package/dist/grants.js.map +1 -1
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +3 -0
  38. package/dist/index.js.map +1 -1
  39. package/package.json +7 -8
  40. package/src/AccessToken.test.ts +100 -0
  41. package/src/AccessToken.ts +184 -0
  42. package/src/EgressClient.ts +617 -0
  43. package/src/IngressClient.ts +257 -0
  44. package/src/RoomServiceClient.ts +359 -0
  45. package/src/ServiceBase.ts +38 -0
  46. package/src/SipClient.ts +427 -0
  47. package/src/TwirpRPC.ts +54 -0
  48. package/src/WebhookReceiver.test.ts +44 -0
  49. package/src/WebhookReceiver.ts +85 -0
  50. package/src/grants.test.ts +30 -0
  51. package/src/grants.ts +107 -0
  52. package/src/index.ts +53 -0
  53. package/.changeset/README.md +0 -8
  54. package/.changeset/config.json +0 -11
  55. package/.eslintrc.cjs +0 -17
  56. package/.github/banner_dark.png +0 -0
  57. package/.github/banner_light.png +0 -0
  58. package/.github/workflows/release.yaml +0 -46
  59. package/.github/workflows/test.yaml +0 -46
  60. package/.gitmodules +0 -3
  61. package/.prettierignore +0 -8
  62. package/CHANGELOG.md +0 -87
  63. package/NOTICE +0 -13
  64. package/renovate.json +0 -18
  65. package/tsconfig.eslint.json +0 -5
  66. package/vite.config.js +0 -8
package/src/grants.ts ADDED
@@ -0,0 +1,107 @@
1
+ // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ import { TrackSource } from '@livekit/protocol';
5
+ import type { JWTPayload } from 'jose';
6
+
7
+ export function trackSourceToString(source: TrackSource) {
8
+ switch (source) {
9
+ case TrackSource.CAMERA:
10
+ return 'camera';
11
+ case TrackSource.MICROPHONE:
12
+ return 'microphone';
13
+ case TrackSource.SCREEN_SHARE:
14
+ return 'screen_share';
15
+ case TrackSource.SCREEN_SHARE_AUDIO:
16
+ return 'screen_share_audio';
17
+ default:
18
+ throw new TypeError(`Cannot convert TrackSource ${source} to string`);
19
+ }
20
+ }
21
+
22
+ export function claimsToJwtPayload(
23
+ grant: ClaimGrants,
24
+ ): JWTPayload & { video?: Record<string, unknown> } {
25
+ const claim: Record<string, any> = { ...grant };
26
+ // eslint-disable-next-line no-restricted-syntax
27
+ if (Array.isArray(claim.video?.canPublishSources)) {
28
+ claim.video.canPublishSources = claim.video.canPublishSources.map(trackSourceToString);
29
+ }
30
+ return claim;
31
+ }
32
+
33
+ export interface VideoGrant {
34
+ /** permission to create a room */
35
+ roomCreate?: boolean;
36
+
37
+ /** permission to join a room as a participant, room must be set */
38
+ roomJoin?: boolean;
39
+
40
+ /** permission to list rooms */
41
+ roomList?: boolean;
42
+
43
+ /** permission to start a recording */
44
+ roomRecord?: boolean;
45
+
46
+ /** permission to control a specific room, room must be set */
47
+ roomAdmin?: boolean;
48
+
49
+ /** name of the room, must be set for admin or join permissions */
50
+ room?: string;
51
+
52
+ /** permissions to control ingress, not specific to any room or ingress */
53
+ ingressAdmin?: boolean;
54
+
55
+ /**
56
+ * allow participant to publish. If neither canPublish or canSubscribe is set,
57
+ * both publish and subscribe are enabled
58
+ */
59
+ canPublish?: boolean;
60
+
61
+ /**
62
+ * TrackSource types that the participant is allowed to publish
63
+ * When set, it supersedes CanPublish. Only sources explicitly set here can be published
64
+ */
65
+ canPublishSources?: TrackSource[];
66
+
67
+ /** allow participant to subscribe to other tracks */
68
+ canSubscribe?: boolean;
69
+
70
+ /**
71
+ * allow participants to publish data, defaults to true if not set
72
+ */
73
+ canPublishData?: boolean;
74
+
75
+ /**
76
+ * by default, a participant is not allowed to update its own metadata
77
+ */
78
+ canUpdateOwnMetadata?: boolean;
79
+
80
+ /** participant isn't visible to others */
81
+ hidden?: boolean;
82
+
83
+ /** participant is recording the room, when set, allows room to indicate it's being recorded */
84
+ recorder?: boolean;
85
+
86
+ /** participant allowed to connect to LiveKit as Agent Framework worker */
87
+ agent?: boolean;
88
+ }
89
+
90
+ export interface SIPGrant {
91
+ /** manage sip resources */
92
+ admin?: boolean;
93
+
94
+ /** make outbound calls */
95
+ call?: boolean;
96
+ }
97
+
98
+ /** @internal */
99
+ export interface ClaimGrants extends JWTPayload {
100
+ name?: string;
101
+ video?: VideoGrant;
102
+ sip?: SIPGrant;
103
+ kind?: string;
104
+ metadata?: string;
105
+ attributes?: Record<string, string>;
106
+ sha256?: string;
107
+ }
package/src/index.ts ADDED
@@ -0,0 +1,53 @@
1
+ // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ export * from './AccessToken.js';
6
+ export * from './EgressClient.js';
7
+ export * from './IngressClient.js';
8
+ export * from './SipClient.js';
9
+ export * from './RoomServiceClient.js';
10
+ export * from './WebhookReceiver.js';
11
+ export * from './grants.js';
12
+ export {
13
+ AliOSSUpload,
14
+ AzureBlobUpload,
15
+ DirectFileOutput,
16
+ EgressInfo,
17
+ EncodedFileOutput,
18
+ EncodedFileType,
19
+ EncodingOptions,
20
+ EncodingOptionsPreset,
21
+ GCPUpload,
22
+ ImageOutput,
23
+ ParticipantEgressRequest,
24
+ RoomCompositeEgressRequest,
25
+ S3Upload,
26
+ SegmentedFileOutput,
27
+ SegmentedFileProtocol,
28
+ StreamOutput,
29
+ StreamProtocol,
30
+ TrackCompositeEgressRequest,
31
+ TrackEgressRequest,
32
+ WebEgressRequest,
33
+ IngressAudioEncodingOptions,
34
+ IngressAudioEncodingPreset,
35
+ IngressAudioOptions,
36
+ IngressInfo,
37
+ IngressInput,
38
+ IngressState,
39
+ IngressVideoEncodingOptions,
40
+ IngressVideoEncodingPreset,
41
+ IngressVideoOptions,
42
+ DataPacket_Kind,
43
+ ParticipantInfo,
44
+ ParticipantInfo_State,
45
+ ParticipantPermission,
46
+ Room,
47
+ TrackInfo,
48
+ TrackType,
49
+ TrackSource,
50
+ SIPTrunkInfo,
51
+ SIPDispatchRuleInfo,
52
+ SIPParticipantInfo,
53
+ } from '@livekit/protocol';
@@ -1,8 +0,0 @@
1
- # Changesets
2
-
3
- Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4
- with multi-package repos, or single-package repos to help you version and publish your code. You can
5
- find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6
-
7
- We have a quick list of common questions to get you started engaging with this project in
8
- [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://unpkg.com/@changesets/config@2.0.0/schema.json",
3
- "changelog": ["@livekit/changesets-changelog-github", { "repo": "livekit/server-sdk-js" }],
4
- "commit": false,
5
- "fixed": [],
6
- "linked": [],
7
- "access": "public",
8
- "baseBranch": "main",
9
- "updateInternalDependencies": "patch",
10
- "ignore": []
11
- }
package/.eslintrc.cjs DELETED
@@ -1,17 +0,0 @@
1
- module.exports = {
2
- extends: ['plugin:import/recommended', 'airbnb-typescript/base', 'prettier'],
3
- parserOptions: {
4
- project: './tsconfig.eslint.json',
5
- },
6
- ignorePatterns: ['src/proto', 'docs/', 'dist/', 'examples'],
7
- rules: {
8
- 'import/export': 'off',
9
- 'max-classes-per-file': 'off',
10
- 'no-param-reassign': 'off',
11
- 'no-await-in-loop': 'off',
12
- 'consistent-return': 'off',
13
- 'class-methods-use-this': 'off',
14
- '@typescript-eslint/no-use-before-define': 'off',
15
- 'no-restricted-syntax': ['error', 'WithStatement', "BinaryExpression[operator='in']"],
16
- },
17
- };
Binary file
Binary file
@@ -1,46 +0,0 @@
1
- name: Release
2
-
3
- on:
4
- push:
5
- branches:
6
- - main
7
-
8
- concurrency: ${{ github.workflow }}-${{ github.ref }}
9
-
10
- jobs:
11
- release:
12
- name: Release
13
- runs-on: ubuntu-latest
14
- steps:
15
- - name: Checkout Repo
16
- uses: actions/checkout@v4
17
- - uses: pnpm/action-setup@v2
18
- with:
19
- version: 8
20
- - name: Use Node.js 20
21
- uses: actions/setup-node@v4
22
- with:
23
- node-version: 20
24
- cache: 'pnpm'
25
- - name: Install dependencies
26
- run: pnpm install
27
- - name: Create Release Pull Request or Publish to npm
28
- id: changesets
29
- uses: changesets/action@v1
30
- with:
31
- publish: pnpm ci:publish
32
- env:
33
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
35
- - name: Build Docs
36
- if: steps.changesets.outputs.published == 'true'
37
- run: pnpm build-docs
38
-
39
-
40
- - name: S3 Upload
41
- if: steps.changesets.outputs.published == 'true'
42
- run: aws s3 cp docs/ s3://livekit-docs/server-sdk-js --recursive
43
- env:
44
- AWS_ACCESS_KEY_ID: ${{ secrets.DOCS_DEPLOY_AWS_ACCESS_KEY }}
45
- AWS_SECRET_ACCESS_KEY: ${{ secrets.DOCS_DEPLOY_AWS_API_SECRET }}
46
- AWS_DEFAULT_REGION: "us-east-1"
@@ -1,46 +0,0 @@
1
- name: Test
2
-
3
- # Controls when the action will run.
4
- on:
5
- # Triggers the workflow on push or pull request events but only for the main branch
6
- workflow_dispatch:
7
- push:
8
- branches: [ main ]
9
- pull_request:
10
- branches: [ main ]
11
-
12
- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
13
- jobs:
14
- test-node:
15
- # The type of runner that the job will run on
16
- runs-on: ubuntu-latest
17
- # Steps represent a sequence of tasks that will be executed as part of the job
18
- steps:
19
- # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
20
- - uses: actions/checkout@v4
21
- - uses: pnpm/action-setup@v2
22
- with:
23
- version: 8
24
- - name: Use Node.js 20
25
- uses: actions/setup-node@v4
26
- with:
27
- node-version: 20
28
- cache: 'pnpm'
29
- - name: Install dependencies
30
- run: pnpm install
31
-
32
- - name: Lint
33
- run: pnpm lint
34
-
35
- - name: Prettier
36
- run: pnpm format:check
37
-
38
- - name: Test Node
39
- run: pnpm test
40
-
41
- - name: Test browser
42
- run: pnpm test:browser
43
-
44
- - name: Test edge runtime
45
- run: pnpm test:edge
46
-
package/.gitmodules DELETED
@@ -1,3 +0,0 @@
1
- [submodule "protocol"]
2
- path = protocol
3
- url = https://github.com/livekit/protocol
package/.prettierignore DELETED
@@ -1,8 +0,0 @@
1
- .github/
2
- dist/
3
- docs/
4
- node_modules/
5
- protocol/
6
- src/proto/
7
- yarn.lock
8
- pnpm-lock.json
package/CHANGELOG.md DELETED
@@ -1,87 +0,0 @@
1
- # livekit-server-sdk
2
-
3
- ## 2.3.0
4
-
5
- ### Minor Changes
6
-
7
- - Add SIP service. - [#173](https://github.com/livekit/server-sdk-js/pull/173) ([@dennwc](https://github.com/dennwc))
8
-
9
- ## 2.2.0
10
-
11
- ### Minor Changes
12
-
13
- - Bump minimum engine requirement to node 19 - [#155](https://github.com/livekit/server-sdk-js/pull/155) ([@lukasIO](https://github.com/lukasIO))
14
-
15
- - Add support for enableTranscoding - [#171](https://github.com/livekit/server-sdk-js/pull/171) ([@biglittlebigben](https://github.com/biglittlebigben))
16
-
17
- ### Patch Changes
18
-
19
- - Allow user to set participant metadata when creating Ingress - [#152](https://github.com/livekit/server-sdk-js/pull/152) ([@davidzhao](https://github.com/davidzhao))
20
-
21
- ## 2.1.2
22
-
23
- ### Patch Changes
24
-
25
- - Support for departure timeout in CreateRoom - [#150](https://github.com/livekit/server-sdk-js/pull/150) ([@davidzhao](https://github.com/davidzhao))
26
-
27
- ## 2.1.1
28
-
29
- ### Patch Changes
30
-
31
- - Make use of @livekit/protocol package - [#147](https://github.com/livekit/server-sdk-js/pull/147) ([@lukasIO](https://github.com/lukasIO))
32
-
33
- ## 2.1.0
34
-
35
- ### Minor Changes
36
-
37
- - Expose protobuf TrackSource and map TrackSource claims to string - [#145](https://github.com/livekit/server-sdk-js/pull/145) ([@lukasIO](https://github.com/lukasIO))
38
-
39
- ### Patch Changes
40
-
41
- - Add support for Egress Image Output - [#143](https://github.com/livekit/server-sdk-js/pull/143) ([@biglittlebigben](https://github.com/biglittlebigben))
42
-
43
- ## 2.0.4
44
-
45
- ### Patch Changes
46
-
47
- - Add agent field to VideoGrant - [#141](https://github.com/livekit/server-sdk-js/pull/141) ([@lukasIO](https://github.com/lukasIO))
48
-
49
- ## 2.0.3
50
-
51
- ### Patch Changes
52
-
53
- - Export types needed for Egress - [#137](https://github.com/livekit/server-sdk-js/pull/137) ([@davidzhao](https://github.com/davidzhao))
54
-
55
- ## 2.0.2
56
-
57
- ### Patch Changes
58
-
59
- - Fix issue decoding unknown fields in webhook receiver - [#135](https://github.com/livekit/server-sdk-js/pull/135) ([@davidzhao](https://github.com/davidzhao))
60
-
61
- ## 2.0.1
62
-
63
- ### Patch Changes
64
-
65
- - Ignore unknown fields in protobuf parsing - [#132](https://github.com/livekit/server-sdk-js/pull/132) ([@lukasIO](https://github.com/lukasIO))
66
-
67
- ## 2.0.0
68
-
69
- ### Major Changes
70
-
71
- - Change module type to ESM - [#118](https://github.com/livekit/server-sdk-js/pull/118) ([@lukasIO](https://github.com/lukasIO))
72
-
73
- - Require node 18 as minimum version - [#118](https://github.com/livekit/server-sdk-js/pull/118) ([@lukasIO](https://github.com/lukasIO))
74
-
75
- - Make `WebhookEvent` names type safe - [#125](https://github.com/livekit/server-sdk-js/pull/125) ([@lukasIO](https://github.com/lukasIO))
76
-
77
- - Token generation is now async (replaced jsonwebtoken with jose for better JS runtime support) - [#118](https://github.com/livekit/server-sdk-js/pull/118) ([@lukasIO](https://github.com/lukasIO))
78
-
79
- - Replace protobufjs with protobuf-es - [#118](https://github.com/livekit/server-sdk-js/pull/118) ([@lukasIO](https://github.com/lukasIO))
80
-
81
- ### Minor Changes
82
-
83
- - Use globally available web crypto API instead of nodeJS crypto module - [#122](https://github.com/livekit/server-sdk-js/pull/122) ([@lukasIO](https://github.com/lukasIO))
84
-
85
- ### Patch Changes
86
-
87
- - Throw error on bad Twirp response status and use async/await instead of promise chaining for improved error catching - [#124](https://github.com/livekit/server-sdk-js/pull/124) ([@lukasIO](https://github.com/lukasIO))
package/NOTICE DELETED
@@ -1,13 +0,0 @@
1
- Copyright 2023 LiveKit, Inc.
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
package/renovate.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
- "extends": ["config:base"],
4
- "rangeStrategy": "auto",
5
- "packageRules": [
6
- {
7
- "schedule": "on the first day of the month",
8
- "matchDepTypes": ["devDependencies"],
9
- "matchUpdateTypes": ["patch", "minor"],
10
- "groupName": "devDependencies (non-major)"
11
- },
12
- {
13
- "matchPackagePrefixes": ["@livekit", "livekit-"],
14
- "matchUpdateTypes": ["patch", "minor"],
15
- "groupName": "Update LiveKit dependencies (non-major)"
16
- }
17
- ]
18
- }
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": ["src/**.ts", "vite.config.js"],
4
- "exclude": []
5
- }
package/vite.config.js DELETED
@@ -1,8 +0,0 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import { defineConfig } from 'vite';
3
-
4
- export default defineConfig({
5
- test: {
6
- environment: 'node',
7
- },
8
- });