mirror of
https://api.glitch.com/git/yaswvc
synced 2026-01-12 03:18:10 +00:00
🍰👲 Checkpoint
./public/main.js:3115263/295 ./server.js:3115263/96
This commit is contained in:
parent
4c208382bb
commit
4a61a39c24
2 changed files with 11 additions and 1 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
// client-side js, loaded by index.html
|
// client-side js, loaded by index.html
|
||||||
// run by the browser each time the page is loaded
|
// run by the browser each time the page is loaded
|
||||||
|
|
||||||
|
let Peer = window.Peer;
|
||||||
|
|
||||||
let messagesEl = document.querySelector('.messages');
|
let messagesEl = document.querySelector('.messages');
|
||||||
let peerIdEl = document.querySelector('#connect-to-peer');
|
let peerIdEl = document.querySelector('#connect-to-peer');
|
||||||
let videoEl = document.querySelector('.remote-video');
|
let videoEl = document.querySelector('.remote-video');
|
||||||
|
|
@ -15,6 +17,7 @@ let renderVideo = (stream) => {
|
||||||
videoEl.srcObject = stream;
|
videoEl.srcObject = stream;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Register with the peer server
|
||||||
let peer = new Peer({
|
let peer = new Peer({
|
||||||
host: '/',
|
host: '/',
|
||||||
path: '/peerjs/myapp'
|
path: '/peerjs/myapp'
|
||||||
|
|
@ -25,6 +28,8 @@ peer.on('open', (id) => {
|
||||||
peer.on('error', (error) => {
|
peer.on('error', (error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle incoming data connection
|
||||||
peer.on('connection', (conn) => {
|
peer.on('connection', (conn) => {
|
||||||
logMessage('incoming peer connection!');
|
logMessage('incoming peer connection!');
|
||||||
conn.on('data', (data) => {
|
conn.on('data', (data) => {
|
||||||
|
|
@ -34,6 +39,8 @@ peer.on('connection', (conn) => {
|
||||||
conn.send('hello!');
|
conn.send('hello!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle incoming voice/video connection
|
||||||
peer.on('call', (call) => {
|
peer.on('call', (call) => {
|
||||||
navigator.mediaDevices.getUserMedia({video: true, audio: true})
|
navigator.mediaDevices.getUserMedia({video: true, audio: true})
|
||||||
.then((stream) => {
|
.then((stream) => {
|
||||||
|
|
@ -45,6 +52,7 @@ peer.on('call', (call) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Initiate outgoing connection
|
||||||
let connectToPeer = () => {
|
let connectToPeer = () => {
|
||||||
let peerId = peerIdEl.value;
|
let peerId = peerIdEl.value;
|
||||||
logMessage(`Connecting to ${peerId}...`);
|
logMessage(`Connecting to ${peerId}...`);
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
// we've started you off with Express (https://expressjs.com/)
|
// we've started you off with Express (https://expressjs.com/)
|
||||||
// but feel free to use whatever libraries or frameworks you'd like through `package.json`.
|
// but feel free to use whatever libraries or frameworks you'd like through `package.json`.
|
||||||
const { ExpressPeerServer } = require("peer");
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
|
|
||||||
|
const { ExpressPeerServer } = require("peer");
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
// make all the files in 'public' available
|
// make all the files in 'public' available
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue