-
Notifications
You must be signed in to change notification settings - Fork 38
/
socketListeners.js
33 lines (28 loc) · 996 Bytes
/
socketListeners.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//on connection get all available offers and call createOfferEls
socket.on('availableOffers',offers=>{
console.log(offers)
createOfferEls(offers)
})
//someone just made a new offer and we're already here - call createOfferEls
socket.on('newOfferAwaiting',offers=>{
createOfferEls(offers)
})
socket.on('answerResponse',offerObj=>{
console.log(offerObj)
addAnswer(offerObj)
})
socket.on('receivedIceCandidateFromServer',iceCandidate=>{
addNewIceCandidate(iceCandidate)
console.log(iceCandidate)
})
function createOfferEls(offers){
//make green answer button for this new offer
const answerEl = document.querySelector('#answer');
offers.forEach(o=>{
console.log(o);
const newOfferEl = document.createElement('div');
newOfferEl.innerHTML = `<button class="btn btn-success col-1">Answer ${o.offererUserName}</button>`
newOfferEl.addEventListener('click',()=>answerOffer(o))
answerEl.appendChild(newOfferEl);
})
}