|
| 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 | +}; |
0 commit comments