1
0
Fork 0
mirror of https://api.glitch.com/git/yaswvc synced 2026-01-12 05:28:10 +00:00

🐂🐏 Checkpoint

./public/main.js:5975361/899
./views/index.html:5975361/290
This commit is contained in:
Glitch (peerjs-video) 2020-09-07 20:57:52 +00:00
parent d76009cd32
commit 5f8e813b18
2 changed files with 32 additions and 18 deletions

View file

@ -50,16 +50,19 @@ peer.on('connection', (conn) => {
// Handle incoming voice/video connection // Handle incoming voice/video connection
peer.on('call', (call) => { peer.on('call', (call) => {
console.log('INCOMING CALL', call) console.log('INCOMING CALL', call);
navigator.mediaDevices.getUserMedia({video: true, audio: true}) call.answer(stream); // Answer the call with an A/V stream.
.then((stream) => { renderVideo(stream, '#localVideo');
call.answer(stream); // Answer the call with an A/V stream. call.on('stream', renderVideo);
renderVideo(stream, '#localVideo') // navigator.mediaDevices.getUserMedia({video: true, audio: true})
call.on('stream', renderVideo); // .then((stream) => {
}) // call.answer(stream); // Answer the call with an A/V stream.
.catch((err) => { // renderVideo(stream, '#localVideo');
console.error('Failed to get local stream', err); // call.on('stream', renderVideo);
}); // })
// .catch((err) => {
// console.error('Failed to get local stream', err);
// });
}); });
// Initiate outgoing connection // Initiate outgoing connection
@ -75,18 +78,34 @@ let connectToPeer = () => {
conn.send('hi!'); conn.send('hi!');
}); });
let call = peer.call(peerId, stream);
call.on('stream', renderVideo);
// navigator.mediaDevices.getUserMedia({video: true, audio: true})
// .then((stream) => {
// let call = peer.call(peerId, stream);
// call.on('stream', renderVideo);
// })
// .catch((err) => {
// logMessage('Failed to get local stream', err);
// });
};
let stream;
let startLocalStream = () => {
navigator.mediaDevices.getUserMedia({video: true, audio: true}) navigator.mediaDevices.getUserMedia({video: true, audio: true})
.then((stream) => { .then((stream) => {
let call = peer.call(peerId, stream); console.log('LOCAL STREAM')
call.on('stream', renderVideo); stream = stream;
}) })
.catch((err) => { .catch((err) => {
logMessage('Failed to get local stream', err); logMessage('Failed to get local stream', err);
}); });
}; }
startLocalStream();
let disconnectFromPeer = () => { let disconnectFromPeer = () => {
} }
window.disconnectFromPeer = disconnectFromPeer;
window.connectToPeer = connectToPeer; window.connectToPeer = connectToPeer;

View file

@ -42,10 +42,5 @@
</div> </div>
<footer>Made with <a href="https://glitch.com">Glitch</a>!</footer> <footer>Made with <a href="https://glitch.com">Glitch</a>!</footer>
<!-- include the Glitch button to show what the webpage is about and
to make it easier for folks to view source and remix -->
<div class="glitchButton" style="position:fixed;top:2em;right:20px;"></div>
<script src="https://button.glitch.me/button.js" defer></script>
</body> </body>
</html> </html>