Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Commit

Permalink
Add missing comment from codelab instructions
Browse files Browse the repository at this point in the history
The comment mentioned in the codelab was missing.

See #3 for details
  • Loading branch information
ErikHellman authored Feb 21, 2020
1 parent cac8668 commit c8d9431
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ async function createRoom() {

registerPeerConnectionListeners();

// Add code for creating a room here

This comment has been minimized.

Copy link
@Huy12qwa

Huy12qwa Mar 6, 2022

const offer = roomSnapshot.data().offer;
await peerConnection.setRemoteDescription(offer);
const answer = await peerConnection.createAnswer();
await peerConnection.setLocalDescription(answer);

const roomWithAnswer = {
answer: {
type: answer.type,
sdp: answer.sdp
}
}
await roomRef.update(roomWithAnswer);

This comment has been minimized.

Copy link
@Huy12qwa

Huy12qwa Mar 6, 2022

roomRef.onSnapshot(async snapshot -> {
console.log('Got updated room:', snapshot.data());
const data = snapshot.data();
if (!peerConnection.currentRemoteDescription && data.answer) {
console.log('Set remote description: ', data.answer);
const answer = new RTCSessionDescription(data.answer)
await peerConnection.setRemoteDescription(answer);
}
});]


This comment has been minimized.

Copy link
@r3think

r3think Jan 12, 2021

const offer = await peerConnection.createOffer();
await peerConnection.setLocalDescription(offer);

const roomWithOffer = {
offer: {
type: offer.type,
sdp: offer.sdp
}
}
const roomRef = await db.collection('rooms').add(roomWithOffer);
const roomId = roomRef.id;
document.querySelector('#currentRoom').innerText = Current room is ${roomId} - You are the caller!

This comment has been minimized.

Copy link
@Huy12qwa

Huy12qwa Mar 6, 2022

const offer = roomSnapshot.data().offer;
await peerConnection.setRemoteDescription(offer);
const answer = await peerConnection.createAnswer();
await peerConnection.setLocalDescription(answer);

const roomWithAnswer = {
answer: {
type: answer.type,
sdp: answer.sdp
}
}
await roomRef.update(roomWithAnswer);

// Code for creating room above

This comment has been minimized.

Copy link
@Huy12qwa

Huy12qwa Mar 6, 2022

async function collectIceCandidates(roomRef, peerConnection,
localName, remoteName) {
const candidatesCollection = roomRef.collection(localName);

peerConnection.addEventListener('icecandidate', event -> {
    if (event.candidate) {
        const json = event.candidate.toJSON();
        candidatesCollection.add(json);
    }
});

roomRef.collection(remoteName).onSnapshot(snapshot -> {
    snapshot.docChanges().forEach(change -> {
        if (change.type === "added") {
            const candidate = new RTCIceCandidate(change.doc.data());
            peerConneciton.addIceCandidate(candidate);
        }
    });
})

}


localStream.getTracks().forEach(track => {
peerConnection.addTrack(track, localStream);
});
Expand Down

2 comments on commit c8d9431

@Huy12qwa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const offer = roomSnapshot.data().offer;
await peerConnection.setRemoteDescription(offer);
const answer = await peerConnection.createAnswer();
await peerConnection.setLocalDescription(answer);

const roomWithAnswer = {
answer: {
type: answer.type,
sdp: answer.sdp
}
}
await roomRef.update(roomWithAnswer);

@euije
Copy link

@euije euije commented on c8d9431 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Huy12qwa!!!

Please sign in to comment.