Skip to content

Commit

Permalink
Upgrade libs
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbengtsson committed Aug 31, 2024
1 parent a1143f6 commit 45a5033
Show file tree
Hide file tree
Showing 6 changed files with 10,307 additions and 15,166 deletions.
21 changes: 11 additions & 10 deletions functions/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import admin from "firebase-admin";
import { initializeApp } from "firebase-admin/app";
import { getFirestore } from "firebase-admin/firestore";
import functions from "firebase-functions";
import fetch from "node-fetch";

admin.initializeApp();
initializeApp();

class ServerError extends Error {
constructor(type, statusCode, message = "Server error") {
Expand All @@ -22,7 +22,7 @@ export const playground = functions.https.onRequest(async (req, res) => {
iceServers: JSON.stringify(servers),
provider: `cloudflare`,
};
await admin.firestore().doc("appInfo/appInfo").update({ connectionConfig });
await getFirestore().doc("appInfo/appInfo").update({ connectionConfig });
functions.logger.log("Updated connection config", { connectionConfig });

res.send("Hello CF!");
Expand Down Expand Up @@ -53,8 +53,10 @@ async function getFreshCloudflareIceServers() {
}
const data = await response.json();
functions.logger.log("Cloudflare response", data);
const serverUrls = data.iceServers.urls;
return serverUrls;

// Cloudflare only returns one server
const iceServer = data.iceServers;
return [iceServer];
}

// async function getFreshTwilioIceServers() {
Expand Down Expand Up @@ -92,7 +94,7 @@ export const updateIceServers = functions
iceServers: JSON.stringify(iceServers),
provider: `cloudflare`,
};
await admin.firestore().doc("appInfo/appInfo").update({ connectionConfig });
await getFirestore().doc("appInfo/appInfo").update({ connectionConfig });
functions.logger.log("Updated connection config", { connectionConfig });
});

Expand Down Expand Up @@ -130,7 +132,7 @@ async function pairingFunction(body) {
devicePlatform: devicePlatform || null,
meta: meta || {},
};
await admin.firestore().collection("connections").add(localConnection);
await getFirestore().collection("connections").add(localConnection);
functions.logger.log("Added local connection", localConnection);

const remoteConnection = await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -163,8 +165,7 @@ async function pairingFunction(body) {
}
}

unsubscribe = admin
.firestore()
unsubscribe = getFirestore()
.collection("connections")
.where("remoteCode", "==", localCode)
.onSnapshot(
Expand Down
Loading

0 comments on commit 45a5033

Please sign in to comment.