Skip to content

Instantly share code, notes, and snippets.

View matt-mcalister's full-sized avatar

Matt McAlister matt-mcalister

  • Flatiron School
  • Brooklyn, NY
View GitHub Profile
import React from "react";
class VideoChat extends React.Component {
state = {
source: ""
}
componentDidMount(){
navigator.mediaDevices.getUserMedia({video: true, audio: true})
const videoPlayer = document.getElementById("video-player") // this is a <video> element
onSuccessWithSrcObject(stream) {
videoPlayer.srcObject = stream;
}
onSuccessWithSrc(stream) {
videoPlayer.src = window.URL.createObjectURL(stream);
}
/* request access to just the user's camera */
{ video: true }
/* request access to the user's microphone and camera, with a preferred resolution of 1280X720 */
{
audio: true,
video: { width: 1280, height: 720 }
}
/* request access to the user's microphone and camera, with a minimum resolution of 1280X720 */
navigator.mediaDevices.getUserMedia(mediaType)
.then(function(stream) {
/* on success, manipulate the stream */
})
.catch(function(err) {
/* on error, handle the error */
});
function resolveLater() {
return new Promise(resolve => {
setTimeout(() => {
resolve('finish');
}, 2000);
});
}
async function asyncCall() {
console.log('let');
async fetchFromBackEnd(){
this.notes = await fetch("http://localhost:3000/api/v1/notes").then(response => response.json())
// render sidebar notes
for (const note of this.notes) {
let newNote = new Note({title: note.title, body: note.body, id: note.id});
newNote.createSidebarDiv()
}
// sidebar eventlistener (show note)
fetchFromBackEnd(){
fetch("http://localhost:3000/api/v1/notes")
.then(response => response.json())
.then(notes => {
// render sidebar notes
for (const note of notes) {
let newNote = new Note({title: note.title, body: note.body, id: note.id});
newNote.createSidebarDiv()
}