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

🍰👲 Checkpoint

./public/main.js:3115263/295
./server.js:3115263/96
This commit is contained in:
Glitch (hello-express) 2020-05-26 02:56:09 +00:00
parent 4c208382bb
commit 4a61a39c24
2 changed files with 11 additions and 1 deletions

View file

@ -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}...`);

View file

@ -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