mirror of
https://api.glitch.com/git/yaswvc
synced 2026-01-12 03:18:10 +00:00
🌇🍩 Checkpoint
./public/main.js:5975361/376 ./views/index.html:5975361/318
This commit is contained in:
parent
f9efbf070a
commit
d76009cd32
2 changed files with 23 additions and 1 deletions
|
|
@ -13,7 +13,7 @@ let logMessage = (message) => {
|
|||
messagesEl.appendChild(newMessage);
|
||||
};
|
||||
|
||||
let renderVideo = (stream, selector = '.remote-video') => {
|
||||
let renderVideo = (stream, selector = '#remoteVideo') => {
|
||||
document.querySelector(selector).srcObject = stream;
|
||||
};
|
||||
|
||||
|
|
@ -32,16 +32,25 @@ peer.on('error', (error) => {
|
|||
// Handle incoming data connection
|
||||
peer.on('connection', (conn) => {
|
||||
logMessage('incoming peer connection!');
|
||||
console.log('incoming peer connection!', conn);
|
||||
conn.on('data', (data) => {
|
||||
logMessage(`received: ${data}`);
|
||||
});
|
||||
conn.on('open', () => {
|
||||
conn.send('hello!');
|
||||
});
|
||||
conn.on('close', () => {
|
||||
logMessage('Connection closed.');
|
||||
});
|
||||
conn.on('error', (error) => {
|
||||
console.error('Error:', error);
|
||||
logMessage('Error'+error);
|
||||
})
|
||||
});
|
||||
|
||||
// Handle incoming voice/video connection
|
||||
peer.on('call', (call) => {
|
||||
console.log('INCOMING CALL', call)
|
||||
navigator.mediaDevices.getUserMedia({video: true, audio: true})
|
||||
.then((stream) => {
|
||||
call.answer(stream); // Answer the call with an A/V stream.
|
||||
|
|
@ -76,4 +85,8 @@ let connectToPeer = () => {
|
|||
});
|
||||
};
|
||||
|
||||
let disconnectFromPeer = () => {
|
||||
|
||||
}
|
||||
|
||||
window.connectToPeer = connectToPeer;
|
||||
|
|
@ -21,12 +21,21 @@
|
|||
<script src="/main.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h6>
|
||||
local
|
||||
</h6>
|
||||
<video id="localVideo" autoplay></video>
|
||||
<h6>
|
||||
remote
|
||||
</h6>
|
||||
<video id="remoteVideo" autoplay></video>
|
||||
<input type="text" id="connect-to-peer" />
|
||||
<button onclick="connectToPeer()">
|
||||
Connect
|
||||
</button>
|
||||
<button onclick="disconnectFromPeer()">
|
||||
Disconnect
|
||||
</button>
|
||||
|
||||
<div class="messages">
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue