Skip to content

Commit

Permalink
Move and link migration guide (livekit#177)
Browse files Browse the repository at this point in the history
* move and link migration guide

* remove leading hyphen
  • Loading branch information
lukasIO authored May 6, 2024
1 parent bb2681e commit 219b0fa
Showing 1 changed file with 75 additions and 75 deletions.
150 changes: 75 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,81 +13,7 @@
> [!NOTE]
> This is v2 of the server-sdk-js which runs in NodeJS, Deno and Bun!
> (It theoretically now also runs in every major browser, but that's not recommended due to the security risks involved with exposing your API secrets)
> Read the section below for a detailed overview on what has changed.
## Migrate from v1.x to v2.x

### Token generation

Because the `jsonwebtoken` lib got replaced with `jose`, there are a couple of APIs that are now async, that weren't before:

```typescript
const at = new AccessToken('api-key', 'secret-key', {
identity: participantName,
});
at.addGrant({ roomJoin: true, room: roomName });

// v1
// const token = at.toJWT();

// v2
const token = await at.toJwt();

// v1
// const grants = v.verify(token);

// v2
const grants = await v.verify(token);

app.post('/webhook-endpoint', async (req, res) => {
// v1
// const event = receiver.receive(req.body, req.get('Authorization'));

// v2
const event = await receiver.receive(req.body, req.get('Authorization'));
});
```

### Egress API

Egress request types have been updated from interfaces to classes in the latest version. Additionally, `oneof` fields now require an explicit `case` field to specify the value type.

For example, to create a RoomComposite Egress:

```typescript
// v1
// const fileOutput = {
// fileType: EncodedFileType.MP4,
// filepath: 'livekit-demo/room-composite-test.mp4',
// s3: {
// accessKey: 'aws-access-key',
// secret: 'aws-access-secret',
// region: 'aws-region',
// bucket: 'my-bucket',
// },
// };

// const info = await egressClient.startRoomCompositeEgress('my-room', {
// file: fileOutput,
// });

// v2 - current
const fileOutput = new EncodedFileOutput({
filepath: 'dz/davids-room-test.mp4',
output: {
case: 's3',
value: new S3Upload({
accessKey: 'aws-access-key',
secret: 'aws-access-secret',
bucket: 'my-bucket',
}),
},
});

const info = await egressClient.startRoomCompositeEgress('my-room', {
file: fileOutput,
});
```
> Read the [migration section](#migrate-from-v1x-to-v2x) below for a detailed overview on what has changed.
## Installation

Expand Down Expand Up @@ -216,6 +142,80 @@ app.post('/webhook-endpoint', async (req, res) => {
});
```

## Migrate from v1.x to v2.x

### Token generation

Because the `jsonwebtoken` lib got replaced with `jose`, there are a couple of APIs that are now async, that weren't before:

```typescript
const at = new AccessToken('api-key', 'secret-key', {
identity: participantName,
});
at.addGrant({ roomJoin: true, room: roomName });

// v1
// const token = at.toJWT();

// v2
const token = await at.toJwt();

// v1
// const grants = v.verify(token);

// v2
const grants = await v.verify(token);

app.post('/webhook-endpoint', async (req, res) => {
// v1
// const event = receiver.receive(req.body, req.get('Authorization'));

// v2
const event = await receiver.receive(req.body, req.get('Authorization'));
});
```

### Egress API

Egress request types have been updated from interfaces to classes in the latest version. Additionally, `oneof` fields now require an explicit `case` field to specify the value type.

For example, to create a RoomComposite Egress:

```typescript
// v1
// const fileOutput = {
// fileType: EncodedFileType.MP4,
// filepath: 'livekit-demo/room-composite-test.mp4',
// s3: {
// accessKey: 'aws-access-key',
// secret: 'aws-access-secret',
// region: 'aws-region',
// bucket: 'my-bucket',
// },
// };

// const info = await egressClient.startRoomCompositeEgress('my-room', {
// file: fileOutput,
// });

// v2 - current
const fileOutput = new EncodedFileOutput({
filepath: 'dz/davids-room-test.mp4',
output: {
case: 's3',
value: new S3Upload({
accessKey: 'aws-access-key',
secret: 'aws-access-secret',
bucket: 'my-bucket',
}),
},
});

const info = await egressClient.startRoomCompositeEgress('my-room', {
file: fileOutput,
});
```

<!--BEGIN_REPO_NAV-->

<br/><table>
Expand Down

0 comments on commit 219b0fa

Please sign in to comment.