-
Notifications
You must be signed in to change notification settings - Fork 4
Add docs for screen recording conversion #266
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
Open
hilsonshrestha
wants to merge
1
commit into
3.0
Choose a base branch
from
firebase-function-screen-recording-conversion
base: 3.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
docs/data-and-deployment/firebase/converting-screen-recording.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # Screen Recording Conversion | ||
|
|
||
| ReVISit can capture screen recordings during a study and upload them to Firebase Storage. However, the format a browser records in isn't guaranteed to play back in every other browser. For example, a recording made in Chrome may not play in Safari, and vice versa. | ||
|
|
||
| To handle this, reVISit ships an optional Firebase Cloud Function, `convertScreenRecording`, that automatically converts uploaded screen recordings to a `.webm` file with browser-compatible codecs. This page walks through deploying that function to your own Firebase project. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - The [Firebase CLI](https://firebase.google.com/docs/cli) installed and authenticated (`firebase login`) | ||
| - The [gcloud CLI](https://cloud.google.com/sdk/docs/install) installed and authenticated (`gcloud auth login`) | ||
| - Access to the Firebase project you want to deploy the function to | ||
| - A reVISit deployment already configured with [Firebase Storage](./setup) | ||
|
|
||
| ## 1. Configure Environment Variables | ||
|
|
||
| The function reads your Firebase config from an `.env` file inside the `functions/` directory so it knows which Storage bucket to listen on. | ||
|
|
||
| Update `functions/.env`: | ||
|
|
||
| ``` | ||
| VITE_FIREBASE_CONFIG=' | ||
| { | ||
| apiKey: "YOUR_API_KEY", | ||
| authDomain: "YOUR_PROJECT_ID.firebaseapp.com", | ||
| projectId: "YOUR_PROJECT_ID", | ||
| storageBucket: "YOUR_PROJECT_ID.appspot.com", | ||
| messagingSenderId: "YOUR_MESSAGING_SENDER_ID", | ||
| appId: "YOUR_APP_ID" | ||
| } | ||
| ' | ||
| ``` | ||
|
|
||
| You can find these values in the Firebase console under **Project Settings > Your apps**. They should match the `VITE_FIREBASE_CONFIG` values used in the `.env` file at the root of your reVISit deployment. | ||
|
|
||
| :::tip | ||
| This value is parsed with [HJSON](https://hjson.github.io/), so you can paste the config object directly from the Firebase console without converting it to strict JSON. | ||
| ::: | ||
|
|
||
| ## 2. Grant IAM Permissions | ||
|
|
||
| Cloud Storage trigger functions rely on a Google-managed service account to deliver storage events. That service account needs permission to read from your bucket before it can invoke the function. | ||
|
|
||
| First, get your project number: | ||
|
|
||
| ```bash | ||
| gcloud projects describe YOUR_PROJECT_ID --format="value(projectNumber)" | ||
| ``` | ||
|
|
||
| Replace `YOUR_PROJECT_ID` with your Firebase project ID, and save the resulting number as `PROJECT_NUMBER` for the next command. | ||
|
|
||
| Then grant the Storage Admin role to that service account: | ||
|
|
||
| ```bash | ||
| gcloud projects add-iam-policy-binding YOUR_PROJECT_ID \ | ||
| --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-eventarc.iam.gserviceaccount.com" \ | ||
| --role="roles/storage.admin" | ||
| ``` | ||
|
|
||
| :::caution | ||
| This step is easy to miss but required. Without it, the function deploys successfully but never actually triggers when files are uploaded. | ||
| ::: | ||
|
|
||
| ## 3. Deploy the Function | ||
|
|
||
| From the `functions/` directory, install dependencies and deploy: | ||
|
|
||
| ```bash | ||
| yarn | ||
| yarn deploy | ||
| ``` | ||
|
|
||
| `yarn deploy` deploys the function `convertScreenRecording` to your Firebase project. | ||
|
|
||
| ## 4. Verify It's Working | ||
|
|
||
| Upload a screen recording to your bucket under a `<studyId>/screenRecording/` path (or run a study that records the screen), then check the function logs by navigating to Functions Page -> View Logs. | ||
|
|
||
|  | ||
|
|
||
| ``` | ||
| Downloading <studyId>/screenRecording/<file> | ||
| Converting to webm | ||
| Uploading <studyId>/screenRecording/<file> | ||
| Done: <studyId>/screenRecording/<file> | ||
| ``` | ||
|
|
||
| ## Limitations | ||
|
|
||
| - Recordings whose codecs aren't already WebM-compatible (`vp8`, `vp9`, `av1`, `opus`, `vorbis`) are skipped rather than re-encoded. | ||
| - The function overwrites the original file at the same Storage path — once conversion succeeds, there's no separate copy of the original left behind. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Storage -> storage |
||
|
|
||
| import StructuredLinks from '@site/src/components/StructuredLinks/StructuredLinks.tsx'; | ||
|
|
||
| <StructuredLinks | ||
| referenceLinks={[ | ||
| {name: "Cloud Storage Triggers", url: "https://firebase.google.com/docs/functions/gcp-storage-events"}, | ||
| {name: "Firebase CLI", url: "https://firebase.google.com/docs/cli"}, | ||
| {name: "gcloud CLI", url: "https://cloud.google.com/sdk/docs/install"}, | ||
| {name: "HJSON", url: "https://hjson.github.io/"} | ||
| ]} | ||
| /> | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
add something like:
:::Note
You can work around this issue by using the same browser that a participant used when they conducted a study. You'll see a warning when that is the case.
:::