-
Notifications
You must be signed in to change notification settings - Fork 31
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
Save tracking info for rooms #1699
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov Report
@@ Coverage Diff @@
## master #1699 +/- ##
===================================================
- Coverage 53.02876% 52.77050% -0.25826%
===================================================
Files 74 75 +1
Lines 4903 4963 +60
Branches 976 987 +11
===================================================
+ Hits 2600 2619 +19
- Misses 1970 2007 +37
- Partials 333 337 +4
Continue to review full report in Codecov by Sentry.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
packages/api/src/controllers/room.ts
Outdated
const room = await svc.createRoom(opts); | ||
emptyTimeout: 15 * 60, | ||
maxParticipants: 10, | ||
metadata: `{"userId": "${req.user.id}"}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to have the metadata! As a nit, you could write a syntax-safe JSON here as well:
metadata: `{"userId": "${req.user.id}"}`, | |
metadata: JSON.stringify({userId: req.user.id}), |
packages/api/src/controllers/room.ts
Outdated
app.use("/webhook", express.raw({ type: "*/*" })); | ||
app.post("/webhook", async (req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this would have the same effect (unless you want the middleware on other methods not only POST)
app.use("/webhook", express.raw({ type: "*/*" })); | |
app.post("/webhook", async (req, res) => { | |
app.post("/webhook", express.raw({ type: "*/*" }), async (req, res) => { |
packages/api/src/controllers/room.ts
Outdated
req.config.livekitApiKey, | ||
req.config.livekitSecret | ||
); | ||
console.log("livekit webhook auth", req.get("Authorization")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably remove/comment this log before deploy
packages/api/src/controllers/room.ts
Outdated
); | ||
const participants = await svc.listParticipants(roomId); | ||
|
||
room = await db.room.get(roomId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe double check this room exists and return a 4xx error if it doesn't (or anything that LiveKit won't retry)
packages/api/src/schema/schema.yaml
Outdated
description: Success | ||
content: | ||
application/json: | ||
$ref: "#/components/schemas/create-room-response" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's only for $refing it here, I'd say we can just inline it (and remove the top-level component)
$ref: "#/components/schemas/create-room-response" | |
additionalProperties: false | |
properties: | |
id: | |
type: string |
packages/api/src/schema/schema.yaml
Outdated
unique: true | ||
index: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the id
field is the only exception! We don't need any index here.
unique: true | |
index: true |
In the database, we have a separate column for the ID which is also the table primary key, and when querying by it we always check that table instead of the id
in the JSON column. The index here would be redundant/unused.
type: string | ||
readOnly: true | ||
example: 66E2161C-7670-4D05-B71D-DA2D6979556F | ||
index: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add room
to this list here: https://github.com/livepeer/livepeer-com/blob/a326c2f31bfd7638390ba703bcf7f1ca6a7cad1e/packages/api/src/store/table.ts#L352
Otherwise the indexes won't really be created. This is a tech debt we've been carrying since the time we had some issues with indexes on the stream
table which is huge and gets a lot of updates.
id: | ||
type: string | ||
|
||
room: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding documentation (description
) to the user-facing fields in this object?
for (const key in room.participants) { | ||
room.participants[key].tracksPublished = undefined; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe consider hiding the entire participants
field. Do users really need access to all that information? Might be easier to start by using it only internally for tracking/billing and consider exposing only parts of it that users may need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be helpful to give them at least the IDs and names of the participants so that they would easily be able to see who has joined and remove people if needed (api coming in next PR). I will tidy up the remaining fields too in the next PR.
packages/api/src/controllers/room.ts
Outdated
break; | ||
case "room_started": | ||
case "room_finished": | ||
room = await db.room.get(event.room.name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for checking if the room exists. Maybe we want this step outside the switch
?
* Save tracking info for rooms * add response schemas * review comments
What does this pull request do? Explain your changes. (required)
I've created a database table to be able to keep track of rooms. I've implemented a webhook receiver so that we can store information like which participants have joined and what tracks they have published.
Specific updates (required)
How did you test each of these updates (required)
Does this pull request close any open issues?
Screenshots (optional)
Checklist