Skip to content

Commit 7165b48

Browse files
committed
[Components] livekit - new action components
1 parent 7b3ce7c commit 7165b48

File tree

8 files changed

+337
-8
lines changed

8 files changed

+337
-8
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { IngressInput } from "livekit-server-sdk";
2+
import app from "../../livekit.app.mjs";
3+
4+
export default {
5+
key: "livekit-create-ingress-from-url",
6+
name: "Create Ingress From URL",
7+
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",
9+
type: "action",
10+
props: {
11+
app,
12+
name: {
13+
type: "string",
14+
label: "Ingress Name",
15+
description: "The name of the ingress",
16+
optional: true,
17+
},
18+
roomName: {
19+
description: "The name of the room to send media to",
20+
propDefinition: [
21+
app,
22+
"room",
23+
],
24+
},
25+
participantIdentity: {
26+
type: "string",
27+
label: "Participant Identity",
28+
description: "Unique identity of the participant",
29+
},
30+
participantName: {
31+
type: "string",
32+
label: "Participant Name",
33+
description: "Participant display name",
34+
optional: true,
35+
},
36+
participantMetadata: {
37+
type: "string",
38+
label: "Participant Metadata",
39+
description: "Metadata to attach to the participant",
40+
optional: true,
41+
},
42+
bypassTranscoding: {
43+
type: "boolean",
44+
label: "Bypass Transcoding",
45+
description: "Whether to skip transcoding and forward the input media directly. Only supported by WHIP",
46+
optional: true,
47+
},
48+
enableTranscoding: {
49+
type: "boolean",
50+
label: "Enable Transcoding",
51+
description: "Whether to enable transcoding or forward the input media directly. Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.",
52+
optional: true,
53+
},
54+
url: {
55+
type: "string",
56+
label: "URL",
57+
description: "URL of the media to pull for ingresses of type URL",
58+
},
59+
},
60+
async run({ $ }) {
61+
const {
62+
app,
63+
name,
64+
roomName,
65+
participantIdentity,
66+
participantName,
67+
participantMetadata,
68+
bypassTranscoding,
69+
enableTranscoding,
70+
url,
71+
} = this;
72+
73+
const response = await app.createIngress({
74+
inputType: IngressInput.URL_INPUT,
75+
name,
76+
roomName,
77+
participantIdentity,
78+
participantName,
79+
participantMetadata,
80+
bypassTranscoding,
81+
enableTranscoding,
82+
url,
83+
});
84+
$.export("$summary", `Seccessfully created room with SID \`${response.sid}\`.`);
85+
return response;
86+
},
87+
};
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import app from "../../livekit.app.mjs";
2+
3+
export default {
4+
key: "livekit-create-room",
5+
name: "Create Room",
6+
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",
8+
type: "action",
9+
props: {
10+
app,
11+
name: {
12+
type: "string",
13+
label: "Room Name",
14+
description: "The name of the room",
15+
},
16+
emptyTimeout: {
17+
type: "integer",
18+
label: "Empty Timeout",
19+
description: "Number of seconds to keep the room open before any participant joins",
20+
optional: true,
21+
},
22+
departureTimeout: {
23+
type: "integer",
24+
label: "Departure Timeout",
25+
description: "Number of seconds to keep the room open after the last participant leaves",
26+
optional: true,
27+
},
28+
maxParticipants: {
29+
type: "integer",
30+
label: "Max Participants",
31+
description: "Limit to the number of participants in a room at a time",
32+
optional: true,
33+
},
34+
metadata: {
35+
type: "string",
36+
label: "Metadata",
37+
description: "Initial room metadata",
38+
optional: true,
39+
},
40+
minPlayoutDelay: {
41+
type: "integer",
42+
label: "Min Playout Delay",
43+
description: "Minimum playout delay in milliseconds",
44+
optional: true,
45+
},
46+
maxPlayoutDelay: {
47+
type: "integer",
48+
label: "Max Playout Delay",
49+
description: "Maximum playout delay in milliseconds",
50+
optional: true,
51+
},
52+
syncStreams: {
53+
type: "boolean",
54+
label: "Sync Streams",
55+
description: "Improves A/V sync when min_playout_delay set to a value larger than 200ms. It will disables transceiver re-use -- this option is not recommended for rooms with frequent subscription changes",
56+
optional: true,
57+
},
58+
},
59+
async run({ $ }) {
60+
const {
61+
app,
62+
name,
63+
emptyTimeout,
64+
departureTimeout,
65+
maxParticipants,
66+
metadata,
67+
minPlayoutDelay,
68+
maxPlayoutDelay,
69+
syncStreams,
70+
} = this;
71+
72+
const response = await app.createRoom({
73+
name,
74+
emptyTimeout,
75+
departureTimeout,
76+
maxParticipants,
77+
metadata,
78+
minPlayoutDelay,
79+
maxPlayoutDelay,
80+
syncStreams,
81+
});
82+
$.export("$summary", `Seccessfully created room with SID \`${response.sid}\`.`);
83+
return response;
84+
},
85+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import app from "../../livekit.app.mjs";
2+
3+
export default {
4+
key: "livekit-delete-room",
5+
name: "Delete Room",
6+
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",
8+
type: "action",
9+
props: {
10+
app,
11+
room: {
12+
propDefinition: [
13+
app,
14+
"room",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const {
20+
app,
21+
room,
22+
} = this;
23+
24+
await app.deleteRoom(room);
25+
26+
$.export("$summary", "Successfully deleted room.");
27+
28+
return {
29+
success: true,
30+
};
31+
},
32+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import app from "../../livekit.app.mjs";
2+
3+
export default {
4+
key: "livekit-list-rooms",
5+
name: "List Rooms",
6+
description: "List all rooms with LiveKit. [See the documentation](https://docs.livekit.io/home/server/managing-rooms/#list-rooms).",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
},
12+
async run({ $ }) {
13+
const rooms = await this.app.listRooms();
14+
$.export("$summary", `Successfully listed \`${rooms.length}\` room(s).`);
15+
return rooms;
16+
},
17+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const HTTPS_PREFIX = "https://";
2+
const HTTP_PREFIX = "http://";
3+
4+
export default {
5+
HTTPS_PREFIX,
6+
HTTP_PREFIX,
7+
};

components/livekit/livekit.app.mjs

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
1+
import {
2+
RoomServiceClient,
3+
IngressClient,
4+
} from "livekit-server-sdk";
5+
import constants from "./common/constants.mjs";
6+
17
export default {
28
type: "app",
39
app: "livekit",
4-
propDefinitions: {},
10+
propDefinitions: {
11+
room: {
12+
type: "string",
13+
label: "Room Name",
14+
description: "The name of the room",
15+
async options() {
16+
const rooms = await this.listRooms();
17+
return rooms.map(({ name }) => name);
18+
},
19+
},
20+
},
521
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
22+
getHost() {
23+
const { project_url: projectUrl } = this.$auth;
24+
25+
return projectUrl.startsWith(constants.HTTPS_PREFIX)
26+
? projectUrl
27+
: projectUrl.startsWith(constants.HTTP_PREFIX)
28+
? projectUrl.replace(constants.HTTP_PREFIX, constants.HTTPS_PREFIX)
29+
: `${constants.HTTPS_PREFIX}${projectUrl}`;
30+
},
31+
getKeys() {
32+
const {
33+
api_key: apiKey,
34+
secret_key: secretKey,
35+
} = this.$auth;
36+
return [
37+
apiKey,
38+
secretKey,
39+
];
40+
},
41+
getRoomClient() {
42+
return new RoomServiceClient(this.getHost(), ...this.getKeys());
43+
},
44+
getIngressClient() {
45+
return new IngressClient(this.getHost(), ...this.getKeys());
46+
},
47+
createRoom(args) {
48+
return this.getRoomClient().createRoom(args);
49+
},
50+
listRooms(names) {
51+
return this.getRoomClient().listRooms(names);
52+
},
53+
deleteRoom(room) {
54+
return this.getRoomClient().deleteRoom(room);
55+
},
56+
createIngress({
57+
inputType, ...args
58+
} = {}) {
59+
return this.getIngressClient().createIngress(inputType, args);
960
},
1061
},
11-
};
62+
};

components/livekit/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/livekit",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream LiveKit Components",
55
"main": "livekit.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"livekit-server-sdk": "^2.8.1"
1417
}
15-
}
18+
}

0 commit comments

Comments
 (0)