mirror of
https://api.glitch.com/git/yaswvc
synced 2026-01-12 06:48:11 +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);
|
messagesEl.appendChild(newMessage);
|
||||||
};
|
};
|
||||||
|
|
||||||
let renderVideo = (stream, selector = '.remote-video') => {
|
let renderVideo = (stream, selector = '#remoteVideo') => {
|
||||||
document.querySelector(selector).srcObject = stream;
|
document.querySelector(selector).srcObject = stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -32,16 +32,25 @@ peer.on('error', (error) => {
|
||||||
// Handle incoming data connection
|
// Handle incoming data connection
|
||||||
peer.on('connection', (conn) => {
|
peer.on('connection', (conn) => {
|
||||||
logMessage('incoming peer connection!');
|
logMessage('incoming peer connection!');
|
||||||
|
console.log('incoming peer connection!', conn);
|
||||||
conn.on('data', (data) => {
|
conn.on('data', (data) => {
|
||||||
logMessage(`received: ${data}`);
|
logMessage(`received: ${data}`);
|
||||||
});
|
});
|
||||||
conn.on('open', () => {
|
conn.on('open', () => {
|
||||||
conn.send('hello!');
|
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
|
// Handle incoming voice/video connection
|
||||||
peer.on('call', (call) => {
|
peer.on('call', (call) => {
|
||||||
|
console.log('INCOMING CALL', call)
|
||||||
navigator.mediaDevices.getUserMedia({video: true, audio: true})
|
navigator.mediaDevices.getUserMedia({video: true, audio: true})
|
||||||
.then((stream) => {
|
.then((stream) => {
|
||||||
call.answer(stream); // Answer the call with an A/V stream.
|
call.answer(stream); // Answer the call with an A/V stream.
|
||||||
|
|
@ -76,4 +85,8 @@ let connectToPeer = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let disconnectFromPeer = () => {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
window.connectToPeer = connectToPeer;
|
window.connectToPeer = connectToPeer;
|
||||||
|
|
@ -21,12 +21,21 @@
|
||||||
<script src="/main.js" type="module"></script>
|
<script src="/main.js" type="module"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<h6>
|
||||||
|
local
|
||||||
|
</h6>
|
||||||
<video id="localVideo" autoplay></video>
|
<video id="localVideo" autoplay></video>
|
||||||
|
<h6>
|
||||||
|
remote
|
||||||
|
</h6>
|
||||||
<video id="remoteVideo" autoplay></video>
|
<video id="remoteVideo" autoplay></video>
|
||||||
<input type="text" id="connect-to-peer" />
|
<input type="text" id="connect-to-peer" />
|
||||||
<button onclick="connectToPeer()">
|
<button onclick="connectToPeer()">
|
||||||
Connect
|
Connect
|
||||||
</button>
|
</button>
|
||||||
|
<button onclick="disconnectFromPeer()">
|
||||||
|
Disconnect
|
||||||
|
</button>
|
||||||
|
|
||||||
<div class="messages">
|
<div class="messages">
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue