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 from 'react'; | |
const Login = ({ setUserId }) => { | |
const connect = (e) => { | |
e.preventDefault(); | |
setUserId(e.target.userId.value); | |
}; | |
return ( | |
<form onSubmit={connect}> |
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, { useState } from 'react'; | |
const Dialer = ({ makeCall }) => { | |
const [userIdError, setUserIdError] = useState(null); | |
const [userId, setUserId] = useState(''); | |
const initiateCall = (isVideoCall) => { | |
setUserIdError(null); | |
if (!userId) { | |
return setUserIdError('Please input a User ID'); |
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 SendBirdCall from "sendbird-calls"; | |
import React, { useState, useEffect } from "react"; | |
import LoginForm from "./LoginForm"; | |
import DialForm from "./DialForm"; | |
import IncomingCallModal from "./IncomingCallModal"; | |
const Call = () => { | |
const [userId, setUserId] = useState(""); | |
const [call, setCall] = useState(null); | |
const [authenticated, setAuthenticated] = useState(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
import SendBirdCall from 'sendbird-calls'; | |
import React, { useState, useEffect } from 'react'; | |
import Login from './Login'; | |
import Dialer from './Dialer'; |
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); |
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 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 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 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
useEffect(() => { | |
if (userId) { | |
initiateSendbirdCalls(); | |
setDefaultCallParams({ | |
callOption: { | |
localMediaView: document.getElementById('local_video_element_id'), | |
remoteMediaView: document.getElementById('remote_video_element_id'), | |
audioEnabled: true, | |
videoEnabled: true, | |
}, |
OlderNewer