Skip to content

Commit 5a4ec03

Browse files
committed
[Components] livekit - new components
1 parent 0ba5bc1 commit 5a4ec03

File tree

10 files changed

+542
-71
lines changed

10 files changed

+542
-71
lines changed

components/livekit/actions/create-ingress-from-url/create-ingress-from-url.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "livekit-create-ingress-from-url",
66
name: "Create Ingress From URL",
77
description: "Create a new ingress from url in LiveKit. [See the documentation](https://docs.livekit.io/home/ingress/overview/#url-input-example).",
8-
version: "0.0.1",
8+
version: "0.0.2",
99
type: "action",
1010
props: {
1111
app,

components/livekit/actions/create-room/create-room.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "livekit-create-room",
55
name: "Create Room",
66
description: "Create a new room in LiveKit. [See the documentation](https://docs.livekit.io/home/server/managing-rooms/#create-a-room).",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
app,

components/livekit/actions/delete-room/delete-room.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "livekit-delete-room",
55
name: "Delete Room",
66
description: "Delete a room in LiveKit. [See the documentation](https://docs.livekit.io/home/server/managing-rooms/#delete-a-room)",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
app,
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import app from "../../livekit.app.mjs";
2+
3+
export default {
4+
key: "livekit-generate-access-token",
5+
name: "Generate Access Token",
6+
description: "Generate an access token for a participant to join a LiveKit room. [See the documentation](https://github.com/livekit/node-sdks/tree/main/packages/livekit-server-sdk).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
room: {
12+
description: "The name of the room to join",
13+
optional: true,
14+
propDefinition: [
15+
app,
16+
"room",
17+
],
18+
},
19+
ttl: {
20+
type: "integer",
21+
label: "Token TTL (seconds)",
22+
description: "How long the access token should be valid for (in seconds)",
23+
optional: true,
24+
},
25+
name: {
26+
type: "string",
27+
label: "Participant Name",
28+
description: "Display name for the participant",
29+
optional: true,
30+
},
31+
identity: {
32+
type: "string",
33+
label: "Participant Identity",
34+
description: "Unique identity for the participant joining the call",
35+
},
36+
metadata: {
37+
type: "string",
38+
label: "Participant Metadata",
39+
description: "Optional metadata to attach to the participant",
40+
optional: true,
41+
},
42+
canPublish: {
43+
type: "boolean",
44+
label: "Can Publish",
45+
description: "Whether the participant can publish audio/video tracks",
46+
optional: true,
47+
},
48+
canSubscribe: {
49+
type: "boolean",
50+
label: "Can Subscribe",
51+
description: "Whether the participant can subscribe to other participants' tracks",
52+
optional: true,
53+
},
54+
canPublishData: {
55+
type: "boolean",
56+
label: "Can Publish Data",
57+
description: "Whether the participant can publish data messages",
58+
optional: true,
59+
},
60+
hidden: {
61+
type: "boolean",
62+
label: "Hidden Participant",
63+
description: "Whether the participant should be hidden from other participants",
64+
optional: true,
65+
},
66+
roomCreate: {
67+
type: "boolean",
68+
label: "Room Create Permission",
69+
description: "Permission to create rooms",
70+
optional: true,
71+
},
72+
roomList: {
73+
type: "boolean",
74+
label: "Room List Permission",
75+
description: "Permission to list rooms",
76+
optional: true,
77+
},
78+
roomRecord: {
79+
type: "boolean",
80+
label: "Room Record Permission",
81+
description: "Permission to start a recording",
82+
optional: true,
83+
},
84+
roomAdmin: {
85+
type: "boolean",
86+
label: "Room Admin Permission",
87+
description: "Permission to control the specific room",
88+
optional: true,
89+
},
90+
ingressAdmin: {
91+
type: "boolean",
92+
label: "Ingress Admin Permission",
93+
description: "Permission to control ingress, not specific to any room or ingress",
94+
optional: true,
95+
},
96+
canUpdateOwnMetadata: {
97+
type: "boolean",
98+
label: "Can Update Own Metadata",
99+
description: "Allow participant to update its own metadata",
100+
optional: true,
101+
},
102+
recorder: {
103+
type: "boolean",
104+
label: "Recorder",
105+
description: "Participant is recording the room, allows room to indicate it's being recorded",
106+
optional: true,
107+
},
108+
agent: {
109+
type: "boolean",
110+
label: "Agent",
111+
description: "Participant allowed to connect to LiveKit as Agent Framework worker",
112+
optional: true,
113+
},
114+
canSubscribeMetrics: {
115+
type: "boolean",
116+
label: "Can Subscribe Metrics",
117+
description: "Allow participant to subscribe to metrics",
118+
optional: true,
119+
},
120+
destinationRoom: {
121+
type: "string",
122+
label: "Destination Room",
123+
description: "Destination room which this participant can forward to",
124+
optional: true,
125+
},
126+
createRoomIfNotExists: {
127+
type: "boolean",
128+
label: "Create Room If Not Exists",
129+
description: "Whether to create the room if it doesn't exist",
130+
optional: true,
131+
},
132+
},
133+
async run({ $ }) {
134+
const {
135+
app,
136+
ttl,
137+
identity,
138+
name,
139+
metadata,
140+
room,
141+
createRoomIfNotExists,
142+
canPublish,
143+
canSubscribe,
144+
canPublishData,
145+
hidden,
146+
roomCreate,
147+
roomList,
148+
roomRecord,
149+
roomAdmin,
150+
ingressAdmin,
151+
canUpdateOwnMetadata,
152+
recorder,
153+
agent,
154+
canSubscribeMetrics,
155+
destinationRoom,
156+
} = this;
157+
158+
// Create room if it doesn't exist and option is enabled
159+
if (createRoomIfNotExists) {
160+
await app.createRoom({
161+
name: room,
162+
});
163+
}
164+
165+
// Create access token for the participant
166+
const response = await app.createAccessToken({
167+
identity,
168+
name,
169+
metadata,
170+
ttl,
171+
grant: {
172+
roomJoin: true,
173+
room,
174+
roomCreate,
175+
roomList,
176+
roomRecord,
177+
roomAdmin,
178+
ingressAdmin,
179+
canPublish,
180+
canSubscribe,
181+
canPublishData,
182+
canUpdateOwnMetadata,
183+
hidden,
184+
recorder,
185+
agent,
186+
canSubscribeMetrics,
187+
destinationRoom,
188+
},
189+
});
190+
191+
$.export("$summary", "Successfully generated access token for participant to join the call.");
192+
193+
return response;
194+
},
195+
};

components/livekit/actions/list-rooms/list-rooms.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "livekit-list-rooms",
55
name: "List Rooms",
66
description: "List all rooms with LiveKit. [See the documentation](https://docs.livekit.io/home/server/managing-rooms/#list-rooms).",
7-
version: "0.0.1",
7+
version: "0.0.2",
88
type: "action",
99
props: {
1010
app,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import app from "../../livekit.app.mjs";
2+
3+
export default {
4+
key: "livekit-remove-participants",
5+
name: "Remove Participants",
6+
description: "Remove specific participants from a LiveKit room. [See the documentation](https://github.com/livekit/node-sdks/tree/main/packages/livekit-server-sdk).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
room: {
12+
propDefinition: [
13+
app,
14+
"room",
15+
],
16+
},
17+
identities: {
18+
type: "string[]",
19+
label: "Participant Identities",
20+
description: "Identities of participants to remove from the room",
21+
propDefinition: [
22+
app,
23+
"identity",
24+
({ room }) => ({
25+
room,
26+
}),
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const {
32+
app,
33+
room,
34+
identities,
35+
} = this;
36+
37+
const results = await Promise.all(
38+
identities.map(async (identity) => {
39+
await app.removeParticipant(room, identity);
40+
return identity;
41+
}),
42+
);
43+
44+
$.export("$summary", `Successfully removed \`${identities.length}\` participant(s) from room: \`${room}\``);
45+
46+
return {
47+
room,
48+
removedParticipants: results,
49+
};
50+
},
51+
};

components/livekit/livekit.app.mjs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {
22
RoomServiceClient,
33
IngressClient,
4+
WebhookReceiver,
5+
AccessToken,
46
} from "livekit-server-sdk";
57
import constants from "./common/constants.mjs";
68

@@ -13,8 +15,27 @@ export default {
1315
label: "Room Name",
1416
description: "The name of the room",
1517
async options() {
16-
const rooms = await this.listRooms();
17-
return rooms.map(({ name }) => name);
18+
try {
19+
const rooms = await this.listRooms();
20+
return rooms.map(({ name }) => name);
21+
} catch (error) {
22+
console.log("Error fetching rooms:", error);
23+
return [];
24+
}
25+
},
26+
},
27+
identity: {
28+
type: "string",
29+
label: "Participant Identity",
30+
description: "The identity of the participant to remove from the room",
31+
async options({ room }) {
32+
try {
33+
const participants = await this.listParticipants(room);
34+
return participants.map(({ identity }) => identity);
35+
} catch (error) {
36+
console.log("Error fetching participants:", error);
37+
return [];
38+
}
1839
},
1940
},
2041
},
@@ -26,7 +47,7 @@ export default {
2647
? projectUrl
2748
: projectUrl.startsWith(constants.HTTP_PREFIX)
2849
? projectUrl.replace(constants.HTTP_PREFIX, constants.HTTPS_PREFIX)
29-
: `${constants.HTTPS_PREFIX}${projectUrl}`;
50+
: projectUrl;
3051
},
3152
getKeys() {
3253
const {
@@ -44,6 +65,9 @@ export default {
4465
getIngressClient() {
4566
return new IngressClient(this.getHost(), ...this.getKeys());
4667
},
68+
getWebhookReceiver() {
69+
return new WebhookReceiver(...this.getKeys());
70+
},
4771
createRoom(args) {
4872
return this.getRoomClient().createRoom(args);
4973
},
@@ -58,5 +82,30 @@ export default {
5882
} = {}) {
5983
return this.getIngressClient().createIngress(inputType, args);
6084
},
85+
verifyWebhook(body, authHeader) {
86+
const receiver = this.getWebhookReceiver();
87+
return receiver.receive(body, authHeader);
88+
},
89+
removeParticipant(room, identity) {
90+
return this.getRoomClient().removeParticipant(room, identity);
91+
},
92+
listParticipants(room) {
93+
return this.getRoomClient().listParticipants(room);
94+
},
95+
async createAccessToken({
96+
grant = {},
97+
...args
98+
} = {}) {
99+
const accessToken = new AccessToken(...this.getKeys(), args);
100+
101+
accessToken.addGrant(grant);
102+
103+
const token = await accessToken.toJwt();
104+
105+
return {
106+
token,
107+
host: this.getHost(),
108+
};
109+
},
61110
},
62111
};

components/livekit/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/livekit",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream LiveKit Components",
55
"main": "livekit.app.mjs",
66
"keywords": [
@@ -13,6 +13,6 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"livekit-server-sdk": "^2.8.1"
16+
"livekit-server-sdk": "^2.13.0"
1717
}
1818
}

0 commit comments

Comments
 (0)