Skip to content

Instantly share code, notes, and snippets.

@rodcisal
Created January 20, 2020 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodcisal/7b6bde9b01013e587d39d1864e6a5235 to your computer and use it in GitHub Desktop.
Save rodcisal/7b6bde9b01013e587d39d1864e6a5235 to your computer and use it in GitHub Desktop.
import React, { useRef, useLayoutEffect } from 'react'
import PropTypes from 'prop-types'
import './Videollamada.scss'
import DailyIframe from '@daily-co/daily-js'
function Videocall ({ toggleCall, conversationId, callActive }) {
const callRef = useRef()
if (callRef.current && !callActive) {
callRef.current.leave()
}
const startCall = async () => {
const callUrl = 'https://911total.daily.co/hello'
const callFrame = await DailyIframe.createFrame(
document.getElementById('videocall-wrapper'),
{ url: callUrl }
)
callRef.current = callFrame
callFrame.join()
}
useLayoutEffect(() => {
if (callActive) {
startCall()
}
}, [callActive])
if (!callActive) return null
return (
<div id='videocall-wrapper' />
)
}
Videocall.propTypes = {
toggleCall: PropTypes.func.isRequired,
conversationId: PropTypes.string.isRequired,
callActive: PropTypes.bool.isRequired
}
export default Videocall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment