Skip to content

Commit

Permalink
Support both livekit-client 2.0.x and 1.5.x (#646)
Browse files Browse the repository at this point in the history
* Support both livekit-client 2.0.x and 1.5.x

* bump version

* remove autoEnd - lifecycle should be controlled by server
  • Loading branch information
davidzhao authored Apr 8, 2024
1 parent c909b3d commit 28ad293
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
6 changes: 3 additions & 3 deletions template-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@livekit/egress-sdk",
"version": "0.1.2",
"version": "0.2.0",
"description": "A lightweight SDK for developing RoomComposite templates",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -12,11 +12,11 @@
"build": "tsc"
},
"devDependencies": {
"livekit-client": "^1.7.0",
"livekit-client": "^1.15.13 || ^2.0.10",
"prettier": "^2.8.4",
"typescript": "^5.0.0"
},
"peerDependencies": {
"livekit-client": "^1.7.0"
"livekit-client": "^1.15.13 || ^2.0.10"
}
}
22 changes: 14 additions & 8 deletions template-sdk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 1 addition & 18 deletions template-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

import { ParticipantEvent, Room, RoomEvent } from 'livekit-client';

export interface EgressOptions {
// automatically finish recording when the last participant leaves
autoEnd?: boolean;
}

const EgressHelper = {
/**
* RoomComposite will pass URL to your livekit's server instance.
Expand Down Expand Up @@ -62,17 +57,13 @@ const EgressHelper = {
* Call when successfully connected to the room
* @param room
*/
setRoom(room: Room, opts?: EgressOptions) {
setRoom(room: Room) {
if (currentRoom) {
currentRoom.off(RoomEvent.ParticipantDisconnected, onParticipantDisconnected);
currentRoom.off(RoomEvent.Disconnected, EgressHelper.endRecording);
}

currentRoom = room;
currentRoom.localParticipant.on(ParticipantEvent.ParticipantMetadataChanged, onMetadataChanged);
if (opts?.autoEnd) {
currentRoom.on(RoomEvent.ParticipantDisconnected, onParticipantDisconnected);
}
currentRoom.on(RoomEvent.Disconnected, EgressHelper.endRecording);
onMetadataChanged();
},
Expand Down Expand Up @@ -124,14 +115,6 @@ function onMetadataChanged() {
}
}

function onParticipantDisconnected() {
if (currentRoom) {
if (currentRoom.participants.size === 0) {
EgressHelper.endRecording();
}
}
}

function getURLParam(name: string): string | null {
const query = new URLSearchParams(window.location.search);
return query.get(name);
Expand Down

0 comments on commit 28ad293

Please sign in to comment.