- const audioElement = document.createElement('audio');
- audioElement.setAttribute('class', 'junction-call-audio');
- audioElement.src = source;
- audioElement.autoplay = 'autoplay';
- audioElement.type = type;
- document.querySelector('body').appendChild(audioElement);
+ internals.peers[peerId] = peerConn;
+
+ peerConn.onicecandidate = (event) => {
+ if (event.candidate) {
+ internals.socket.emit('relayICECandidate', {
+ 'peer_id': peerId,
+ 'ice_candidate': {
+ 'sdpMLineIndex': event.candidate.sdpMLineIndex,
+ 'candidate': event.candidate.candidate
+ }
+ });
+ }
+ }
+
+ peerConn.onaddstream = (stream) => {
+ console.log(`Received stream for peer ${peerId}`);
+ console.log(stream);
+ }
+
+ peerConn.addStream(mediaStream);
+
+ if (data.should_create_offer) {
+ console.log("Creating RTC offer to ", peerId);
+ peerConn.createOffer((local_description) => {
+ console.log("Local offer description is: ", local_description);
+ peerConn.setLocalDescription(local_description, () => {
+ internals.socket.emit('relaySessionDescription', {
+ 'peer_id': peerId,
+ 'session_description': local_description
+ });
+
+ console.log("Offer setLocalDescription succeeded");
+ }, () => { console.log("Offer setLocalDescription failed!"); }
+ );
+ },
+ (error) => { console.log("Error sending offer: ", error) }
+ );
+ }
+ console.log(`There are now ${Peers.count()} participants`);
+ });
+
+ internals.socket.on('removePeer', function() {
+
+ Peers.remove('id-'+(Peers.count() - 1)); // This is only for testing, don't use count to remove ids.
+ console.log(`There are now ${Peers.count()} participants`);
+ });