mirror of
https://github.com/MercuryWorkshop/adrift.git
synced 2025-05-13 06:10:01 -04:00
add firebase login and offering to the client
This commit is contained in:
parent
d1bef00d93
commit
7315350858
4 changed files with 41 additions and 70 deletions
|
@ -4,11 +4,15 @@
|
|||
import { DevWsTransport } from "../client/DevWsTransport";
|
||||
import { RTCTransport } from "../client/RTCTransport";
|
||||
import type Transport from "../client/Transport";
|
||||
// note: even though we import firebase, due to the tree shaking, it will only run if we use "auth" so if ADRIFT_DEV is set it won't import
|
||||
import { auth } from "../firebase-config";
|
||||
import {
|
||||
BareClient,
|
||||
registerRemoteListener,
|
||||
setBareClientImplementation,
|
||||
} from "bare-client-custom";
|
||||
import { signInWithEmailAndPassword } from "firebase/auth";
|
||||
import { getDatabase, onValue, ref, set } from "firebase/database";
|
||||
|
||||
let transport: Transport;
|
||||
|
||||
|
@ -50,6 +54,38 @@
|
|||
console.log("registering bare-client-custom");
|
||||
registerRemoteListener();
|
||||
}
|
||||
async function connectFirebase() {
|
||||
if (!rtctransport) return;
|
||||
|
||||
let creds = await signInWithEmailAndPassword(
|
||||
auth,
|
||||
"test@test.com",
|
||||
"123456"
|
||||
);
|
||||
|
||||
const db = getDatabase();
|
||||
let peer = ref(db, `/peers/${creds.user.uid}`);
|
||||
|
||||
let offer = await rtctransport.createOffer();
|
||||
|
||||
set(peer, JSON.stringify(offer));
|
||||
|
||||
onValue(peer, (snapshot) => {
|
||||
const data = snapshot.val();
|
||||
console.log(data);
|
||||
if (data && data.answer && data.candidates) {
|
||||
set(peer, null);
|
||||
const { answer, candidates } = JSON.parse(data);
|
||||
rtctransport?.answer(answer, candidates);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1>testa</h1>
|
||||
<h1>
|
||||
{#if !import.meta.env.VITE_ADRIFT_DEV}
|
||||
<button on:click={connectFirebase}>Connect with firebase </button>
|
||||
{:else}
|
||||
connected to dev server
|
||||
{/if}
|
||||
</h1>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue