-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NEW] P2P WebRTC Connection Establishment (#22847)
* [NEW] WebRTC P2P Connection with Basic Call UI * [FIX] Set Stream on a stable connection * [FIX] userId typecheck error * [REFACTOR] - Restore type of userId to string by removing `| undefined` - Add translation for visitor does not exist toastr - Set visitorId from room object fetched instead of fetching from livechat widget as query param - Type Checking * [FIX] Running startCall 2 times for agent * [FIX] Call declined Page
- Loading branch information
1 parent
202bf73
commit 8fe45ae
Showing
10 changed files
with
301 additions
and
33 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { Box, Flex } from '@rocket.chat/fuselage'; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import { Notifications } from '../../../app/notifications/client'; | ||
import { WebRTC } from '../../../app/webrtc/client'; | ||
import { WEB_RTC_EVENTS } from '../../../app/webrtc/index'; | ||
import { useTranslation } from '../../contexts/TranslationContext'; | ||
|
||
function CallPage({ roomId, visitorToken, visitorId, status, setStatus }) { | ||
const [isAgentActive, setIsAgentActive] = useState(false); | ||
const t = useTranslation(); | ||
useEffect(() => { | ||
if (visitorToken) { | ||
const webrtcInstance = WebRTC.getInstanceByRoomId(roomId, visitorId); | ||
Notifications.onUser( | ||
WEB_RTC_EVENTS.WEB_RTC, | ||
(type, data) => { | ||
if (data.room == null) { | ||
return; | ||
} | ||
webrtcInstance.onUserStream(type, data); | ||
}, | ||
visitorId, | ||
); | ||
Notifications.onRoom(roomId, 'webrtc', (type, data) => { | ||
if (type === 'callStatus' && data.callStatus === 'ended') { | ||
webrtcInstance.stop(); | ||
setStatus(data.callStatus); | ||
} | ||
}); | ||
Notifications.notifyRoom(roomId, 'webrtc', 'callStatus', { callStatus: 'inProgress' }); | ||
} else if (!isAgentActive) { | ||
const webrtcInstance = WebRTC.getInstanceByRoomId(roomId); | ||
if (status === 'inProgress') { | ||
webrtcInstance.startCall({ | ||
audio: true, | ||
video: { | ||
width: { ideal: 1920 }, | ||
height: { ideal: 1080 }, | ||
}, | ||
}); | ||
} | ||
Notifications.onRoom(roomId, 'webrtc', (type, data) => { | ||
if (type === 'callStatus') { | ||
switch (data.callStatus) { | ||
case 'ended': | ||
webrtcInstance.stop(); | ||
break; | ||
case 'inProgress': | ||
webrtcInstance.startCall({ | ||
audio: true, | ||
video: { | ||
width: { ideal: 1920 }, | ||
height: { ideal: 1080 }, | ||
}, | ||
}); | ||
} | ||
setStatus(data.callStatus); | ||
} | ||
}); | ||
setIsAgentActive(true); | ||
} | ||
}, [isAgentActive, status, setStatus, visitorId, roomId, visitorToken]); | ||
|
||
switch (status) { | ||
case 'ringing': | ||
// Todo Deepak | ||
return ( | ||
<h1 style={{ color: 'white', textAlign: 'center', marginTop: 250 }}> | ||
Waiting for the visitor to join ... | ||
</h1> | ||
); | ||
case 'declined': | ||
return ( | ||
<Box | ||
minHeight='90%' | ||
display='flex' | ||
justifyContent='center' | ||
alignItems='center' | ||
color='white' | ||
fontSize='s1' | ||
> | ||
{t('Call_declined')} | ||
</Box> | ||
); | ||
case 'inProgress': | ||
return ( | ||
<Flex.Container direction='column' justifyContent='center'> | ||
<Box | ||
width='full' | ||
minHeight='sh' | ||
textAlign='center' | ||
backgroundColor='neutral-900' | ||
overflow='hidden' | ||
position='relative' | ||
> | ||
<Box | ||
position='absolute' | ||
zIndex='1' | ||
style={{ | ||
top: '5%', | ||
right: '2%', | ||
}} | ||
w='x200' | ||
> | ||
<video | ||
id='localVideo' | ||
autoPlay | ||
playsInline | ||
muted | ||
style={{ | ||
width: '100%', | ||
transform: 'scaleX(-1)', | ||
}} | ||
></video> | ||
</Box> | ||
<video | ||
id='remoteVideo' | ||
autoPlay | ||
playsInline | ||
muted | ||
style={{ | ||
width: '100%', | ||
transform: 'scaleX(-1)', | ||
}} | ||
></video> | ||
</Box> | ||
</Flex.Container> | ||
); | ||
} | ||
} | ||
|
||
export default CallPage; |
Oops, something went wrong.