You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			99 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			TypeScript
		
	
		
		
			
		
	
	
			99 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			TypeScript
		
	
| 
											4 years ago
										 | import React, { useEffect } from 'react'; | ||
| 
											4 years ago
										 | import { useSelector } from 'react-redux'; | ||
|  | 
 | ||
|  | import styled from 'styled-components'; | ||
| 
											4 years ago
										 | import { useConversationUsername } from '../../hooks/useParamSelector'; | ||
|  | import { ed25519Str } from '../../session/onions/onionPath'; | ||
|  | import { CallManager } from '../../session/utils'; | ||
|  | import { callTimeoutMs } from '../../session/utils/calling/CallManager'; | ||
|  | import { getHasIncomingCall, getHasIncomingCallFrom } from '../../state/selectors/call'; | ||
|  | import { Avatar, AvatarSize } from '../avatar/Avatar'; | ||
|  | import { SessionButton, SessionButtonColor } from '../basic/SessionButton'; | ||
| 
											4 years ago
										 | import { SessionWrapperModal } from '../SessionWrapperModal'; | ||
|  | 
 | ||
|  | export const CallWindow = styled.div`
 | ||
|  |   position: absolute; | ||
|  |   z-index: 9; | ||
|  |   padding: 1rem; | ||
|  |   top: 50vh; | ||
|  |   left: 50vw; | ||
|  |   transform: translate(-50%, -50%); | ||
|  |   display: flex; | ||
|  |   flex-direction: column; | ||
|  |   background-color: var(--color-modal-background); | ||
|  |   border: var(--session-border); | ||
|  | `;
 | ||
|  | 
 | ||
| 
											4 years ago
										 | const IncomingCallAvatarContainer = styled.div`
 | ||
| 
											4 years ago
										 |   padding: 0 0 2rem 0; | ||
|  | `;
 | ||
|  | 
 | ||
| 
											4 years ago
										 | export const IncomingCallDialog = () => { | ||
|  |   const hasIncomingCall = useSelector(getHasIncomingCall); | ||
| 
											4 years ago
										 |   const incomingCallFromPubkey = useSelector(getHasIncomingCallFrom); | ||
| 
											4 years ago
										 | 
 | ||
| 
											4 years ago
										 |   useEffect(() => { | ||
|  |     let timeout: NodeJS.Timeout; | ||
|  |     if (incomingCallFromPubkey) { | ||
|  |       timeout = global.setTimeout(async () => { | ||
|  |         if (incomingCallFromPubkey) { | ||
|  |           window.log.info( | ||
|  |             `call missed with ${ed25519Str( | ||
|  |               incomingCallFromPubkey | ||
| 
											4 years ago
										 |             )} as the dialog was not interacted with for ${callTimeoutMs} ms`
 | ||
| 
											4 years ago
										 |           ); | ||
|  |           await CallManager.USER_rejectIncomingCallRequest(incomingCallFromPubkey); | ||
|  |         } | ||
| 
											4 years ago
										 |       }, callTimeoutMs); | ||
| 
											4 years ago
										 |     } | ||
|  | 
 | ||
|  |     return () => { | ||
|  |       if (timeout) { | ||
|  |         global.clearTimeout(timeout); | ||
|  |       } | ||
|  |     }; | ||
|  |   }, [incomingCallFromPubkey]); | ||
|  | 
 | ||
| 
											4 years ago
										 |   //#region input handlers
 | ||
|  |   const handleAcceptIncomingCall = async () => { | ||
| 
											4 years ago
										 |     if (incomingCallFromPubkey) { | ||
|  |       await CallManager.USER_acceptIncomingCallRequest(incomingCallFromPubkey); | ||
| 
											4 years ago
										 |     } | ||
|  |   }; | ||
|  | 
 | ||
|  |   const handleDeclineIncomingCall = async () => { | ||
|  |     // close the modal
 | ||
| 
											4 years ago
										 |     if (incomingCallFromPubkey) { | ||
|  |       await CallManager.USER_rejectIncomingCallRequest(incomingCallFromPubkey); | ||
| 
											4 years ago
										 |     } | ||
|  |   }; | ||
| 
											4 years ago
										 |   const from = useConversationUsername(incomingCallFromPubkey); | ||
| 
											4 years ago
										 |   if (!hasIncomingCall || !incomingCallFromPubkey) { | ||
| 
											4 years ago
										 |     return null; | ||
|  |   } | ||
|  | 
 | ||
|  |   if (hasIncomingCall) { | ||
|  |     return ( | ||
| 
											4 years ago
										 |       <SessionWrapperModal title={window.i18n('incomingCallFrom', [from || 'unknown'])}> | ||
| 
											4 years ago
										 |         <IncomingCallAvatarContainer> | ||
| 
											4 years ago
										 |           <Avatar size={AvatarSize.XL} pubkey={incomingCallFromPubkey} /> | ||
| 
											4 years ago
										 |         </IncomingCallAvatarContainer> | ||
| 
											4 years ago
										 |         <div className="session-modal__button-group"> | ||
| 
											4 years ago
										 |           <SessionButton | ||
|  |             text={window.i18n('decline')} | ||
|  |             buttonColor={SessionButtonColor.Danger} | ||
|  |             onClick={handleDeclineIncomingCall} | ||
|  |           /> | ||
| 
											4 years ago
										 |           <SessionButton | ||
|  |             text={window.i18n('accept')} | ||
|  |             onClick={handleAcceptIncomingCall} | ||
|  |             buttonColor={SessionButtonColor.Green} | ||
|  |           /> | ||
|  |         </div> | ||
|  |       </SessionWrapperModal> | ||
|  |     ); | ||
|  |   } | ||
|  |   // display spinner while connecting
 | ||
|  |   return null; | ||
|  | }; |