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

Commit beb2f9f

Browse files
authored
Merge pull request #5 from gorisanson/solution
Fix solution
2 parents 86d853d + 77ae0b1 commit beb2f9f

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

public/app.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async function createRoom() {
3030
document.querySelector('#createBtn').disabled = true;
3131
document.querySelector('#joinBtn').disabled = true;
3232
const db = firebase.firestore();
33+
const roomRef = await db.collection('rooms').doc();
3334

3435
console.log('Create PeerConnection with configuration: ', configuration);
3536
peerConnection = new RTCPeerConnection(configuration);
@@ -40,6 +41,19 @@ async function createRoom() {
4041
peerConnection.addTrack(track, localStream);
4142
});
4243

44+
// Code for collecting ICE candidates below
45+
const callerCandidatesCollection = roomRef.collection('callerCandidates');
46+
47+
peerConnection.addEventListener('icecandidate', event => {
48+
if (!event.candidate) {
49+
console.log('Got final candidate!');
50+
return;
51+
}
52+
console.log('Got candidate: ', event.candidate);
53+
callerCandidatesCollection.add(event.candidate.toJSON());
54+
});
55+
// Code for collecting ICE candidates above
56+
4357
// Code for creating a room below
4458
const offer = await peerConnection.createOffer();
4559
await peerConnection.setLocalDescription(offer);
@@ -51,26 +65,13 @@ async function createRoom() {
5165
sdp: offer.sdp,
5266
},
5367
};
54-
const roomRef = await db.collection('rooms').add(roomWithOffer);
68+
await roomRef.set(roomWithOffer);
5569
roomId = roomRef.id;
5670
console.log(`New room created with SDP offer. Room ID: ${roomRef.id}`);
5771
document.querySelector(
5872
'#currentRoom').innerText = `Current room is ${roomRef.id} - You are the caller!`;
5973
// Code for creating a room above
6074

61-
// Code for collecting ICE candidates below
62-
const callerCandidatesCollection = roomRef.collection('callerCandidates');
63-
64-
peerConnection.addEventListener('icecandidate', event => {
65-
if (!event.candidate) {
66-
console.log('Got final candidate!');
67-
return;
68-
}
69-
console.log('Got candidate: ', event.candidate);
70-
callerCandidatesCollection.add(event.candidate.toJSON());
71-
});
72-
// Code for collecting ICE candidates above
73-
7475
peerConnection.addEventListener('track', event => {
7576
console.log('Got remote track:', event.streams[0]);
7677
event.streams[0].getTracks().forEach(track => {

0 commit comments

Comments
 (0)