usar API de metered.ca
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

fixes #22
This commit is contained in:
Cat /dev/Nulo 2023-04-22 18:52:30 -03:00
parent cd505ab677
commit 866fbfd7ec
2 changed files with 22 additions and 21 deletions

View file

@ -5,6 +5,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="manifest" href="/manifest.webmanifest" />
<link rel="icon" href="/edit-2-outline.svg" />
<link
rel="preload"
href="https://nulo.metered.live/api/v1/turn/credentials?apiKey=205de2914a8564e2efa19a7d7f299a95e574"
as="fetch"
crossorigin="anonymous"
/>
<title>Schreiben</title>
</head>
<body>

View file

@ -24,6 +24,10 @@ export function generateNewWorld(): WorldIdentifier {
// cache the previous doc and return that instead
let worldYCache: { [key: string]: WorldY } = {};
const credsReq = fetch(
"https://nulo.metered.live/api/v1/turn/credentials?apiKey=205de2914a8564e2efa19a7d7f299a95e574"
).then((res) => res.json());
export function getWorldY(world: WorldIdentifier): WorldY {
if (worldYCache[world.room]) return worldYCache[world.room];
const ydoc = new Y.Doc();
@ -36,27 +40,18 @@ export function getWorldY(world: WorldIdentifier): WorldY {
// "wss://y-webrtc-signaling-eu.herokuapp.com",
// "wss://y-webrtc-signaling-us.herokuapp.com",
],
peerOpts: {
config: {
iceServers: [
// { urls: "stun:stun.l.google.com:19302" },
// { urls: "stun:global.stun.twilio.com:3478?transport=udp" },
{
urls: "stun:relay.metered.ca:80",
},
{
urls: "turn:relay.metered.ca:443",
username: "7aec233ea46fa835147308ae",
credential: "c0eTB5pqj9vOxhii",
},
{
urls: "turn:relay.metered.ca:443?transport=tcp",
username: "7aec233ea46fa835147308ae",
credential: "c0eTB5pqj9vOxhii",
},
],
},
},
});
credsReq.then((iceServers) => {
// change the default for future connections
provider.peerOpts.config = { iceServers };
if (!provider.room?.webrtcConns) return;
// change the configuration in current connections
for (const conn of provider.room?.webrtcConns?.values()) {
const pc: RTCPeerConnection = conn.peer._pc;
pc.setConfiguration({
iceServers,
});
}
});
const idbProvider = new IndexeddbPersistence(world.room, ydoc);
const worldY = { ydoc, webrtcProvider: provider };