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
require("dotenv").config(); | |
const axios = require("axios"); | |
const fs = require("fs"); | |
const { AsyncParser } = require("@json2csv/node"); | |
const token = Buffer.from( | |
process.env.NIMBLE_USERNAME + ":" + process.env.NIMBLE_PASSWORD | |
).toString("base64"); |
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 Call from '../components/Call'; | |
export default function Home() { | |
return ( | |
<div> | |
<Call /> | |
</div> | |
); | |
} |
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
return ( | |
<div className='p-10'> | |
<div className='flex justify-center mt-28'> | |
<> | |
{userId && ( | |
<> | |
<div className='flex flex-col items-center space-y-6'> | |
<h1 className='font-bold text-xl'>Authenticated as {userId}</h1> | |
{authenticated && ringing && ( |
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
const makeCall = ({ userId, isVideoCall }) => { | |
const dialParams = { ...defaultCallParams, ...{ userId, isVideoCall } }; | |
let call = SendBirdCall.dial(dialParams, (call, error) => { | |
if (error) { | |
setCall(null); | |
} | |
}); | |
call = setDefaultCallHandlers(call); | |
setConnecting(true); |
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
useEffect(() => { | |
if (userId) { | |
initiateSendbirdCalls(); | |
setDefaultCallParams({ | |
callOption: { | |
localMediaView: document.getElementById('local_video_element_id'), | |
remoteMediaView: document.getElementById('remote_video_element_id'), | |
audioEnabled: true, | |
videoEnabled: true, | |
}, |
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
const setDefaultCallHandlers = (call) => { | |
call.onEstablished = () => { | |
setRinging(false); | |
setConnecting(false); | |
console.log('Call established'); | |
}; | |
call.onConnected = () => { | |
setRinging(false); | |
setConnected(true); | |
setConnecting(false); |
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
const initiateSendbirdCalls = async () => { | |
const APP_ID = process.env.NEXT_PUBLIC_APP_ID; | |
SendBirdCall.init(APP_ID); | |
try { | |
setLoading(true); | |
await authenticate(); | |
await SendBirdCall.connectWebSocket(); | |
addEventHandler(); | |
setAuthenticated(true); |
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
const addEventHandler = () => { | |
SendBirdCall.addListener(`CALLS_HANDLER_${userId}`, { | |
onRinging: (call) => { | |
console.log('Receiving call'); | |
call = setDefaultCallHandlers(call); | |
setRinging(true); | |
setCall(call); | |
}, | |
}); | |
}; |
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
const authenticate = async () => { | |
try { | |
const result = await new Promise((resolve, reject) => { | |
SendBirdCall.authenticate({ userId }, (res, error) => { | |
if (error) { | |
reject(error); | |
} else { | |
resolve(res); | |
} | |
}); |
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
const Call = () => { | |
const [userId, setUserId] = useState(''); | |
const [call, setCall] = useState(null); | |
const [authenticated, setAuthenticated] = useState(false); | |
const [ringing, setRinging] = useState(false); | |
const [connected, setConnected] = useState(false); | |
const [connecting, setConnecting] = useState(false); | |
const [loading, setLoading] = useState(false); | |
const [muted, setMuted] = useState(false); | |
const [mutedVideo, setMutedAudio] = useState(false); |
NewerOlder