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 both livekit-client 2.0.x and 1.5.x #646

Merged
merged 3 commits into from
Apr 8, 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
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
Loading