Created
January 20, 2020 22:29
-
-
Save rodcisal/7b6bde9b01013e587d39d1864e6a5235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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