|
|
|
@ -1,9 +1,8 @@
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
import _ from 'underscore';
|
|
|
|
import _ from 'underscore';
|
|
|
|
import { ConversationModel } from '../../../models/conversation';
|
|
|
|
|
|
|
|
// tslint:disable-next-line: no-submodule-imports
|
|
|
|
|
|
|
|
import { getConversationController } from '../../../session/conversations/ConversationController';
|
|
|
|
import { getConversationController } from '../../../session/conversations/ConversationController';
|
|
|
|
|
|
|
|
import { CallManager } from '../../../session/utils';
|
|
|
|
import { SessionButton, SessionButtonColor } from '../SessionButton';
|
|
|
|
import { SessionButton, SessionButtonColor } from '../SessionButton';
|
|
|
|
import { SessionWrapperModal } from '../SessionWrapperModal';
|
|
|
|
import { SessionWrapperModal } from '../SessionWrapperModal';
|
|
|
|
|
|
|
|
|
|
|
|
@ -35,7 +34,7 @@ const CallWindowHeader = styled.div`
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Add proper styling for this
|
|
|
|
// TODO: Add proper styling for this
|
|
|
|
const VideoContainer = styled.div`
|
|
|
|
const VideoContainer = styled.video`
|
|
|
|
width: 200px;
|
|
|
|
width: 200px;
|
|
|
|
height: 200px;
|
|
|
|
height: 200px;
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
@ -65,7 +64,9 @@ const CallWindowControls = styled.div`
|
|
|
|
// left: string;
|
|
|
|
// left: string;
|
|
|
|
// } | null;
|
|
|
|
// } | null;
|
|
|
|
|
|
|
|
|
|
|
|
type CallStateType = 'connecting' | 'ongoing' | 'incoming' | null
|
|
|
|
type CallStateType = 'connecting' | 'ongoing' | 'incoming' | null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fakeCaller = '054774a456f15c7aca42fe8d245983549000311aaebcf58ce246250c41fe227676';
|
|
|
|
|
|
|
|
|
|
|
|
export const CallContainer = () => {
|
|
|
|
export const CallContainer = () => {
|
|
|
|
const conversations = getConversationController().getConversations();
|
|
|
|
const conversations = getConversationController().getConversations();
|
|
|
|
@ -80,76 +81,75 @@ export const CallContainer = () => {
|
|
|
|
// const [callWindowPosition, setCallWindowPosition] = useState<WindowPositionType>(null)
|
|
|
|
// const [callWindowPosition, setCallWindowPosition] = useState<WindowPositionType>(null)
|
|
|
|
|
|
|
|
|
|
|
|
// picking a conversation at random to test with
|
|
|
|
// picking a conversation at random to test with
|
|
|
|
let randConvo = _.sample(conversations) as ConversationModel;
|
|
|
|
const foundConvo = conversations.find(convo => convo.id === fakeCaller);
|
|
|
|
randConvo.callState = 'incoming';
|
|
|
|
|
|
|
|
console.warn({ randConvo });
|
|
|
|
if (!foundConvo) {
|
|
|
|
|
|
|
|
throw new Error('fakeconvo not found');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foundConvo.callState = 'incoming';
|
|
|
|
|
|
|
|
console.warn('foundConvo: ', foundConvo);
|
|
|
|
|
|
|
|
|
|
|
|
const firstCallingConvo = _.first(conversations.filter(convo => convo.callState !== undefined));
|
|
|
|
const firstCallingConvo = _.first(conversations.filter(convo => convo.callState !== undefined));
|
|
|
|
|
|
|
|
|
|
|
|
//#region input handlers
|
|
|
|
//#region input handlers
|
|
|
|
const handleAcceptIncomingCall = () => {
|
|
|
|
const handleAcceptIncomingCall = async () => {
|
|
|
|
console.warn('accept call');
|
|
|
|
console.warn('accept call');
|
|
|
|
|
|
|
|
|
|
|
|
if (firstCallingConvo) {
|
|
|
|
if (firstCallingConvo) {
|
|
|
|
setConnectionState('connecting');
|
|
|
|
setConnectionState('connecting');
|
|
|
|
firstCallingConvo.callState = 'connecting';
|
|
|
|
firstCallingConvo.callState = 'connecting';
|
|
|
|
|
|
|
|
await CallManager.USER_acceptIncomingCallRequest(fakeCaller);
|
|
|
|
// some delay
|
|
|
|
// some delay
|
|
|
|
setConnectionState('ongoing');
|
|
|
|
setConnectionState('ongoing');
|
|
|
|
firstCallingConvo.callState = 'ongoing';
|
|
|
|
firstCallingConvo.callState = 'ongoing';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// set conversationState = setting up
|
|
|
|
// set conversationState = setting up
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleDeclineIncomingCall = () => {
|
|
|
|
const handleDeclineIncomingCall = async () => {
|
|
|
|
// set conversation.callState = null or undefined
|
|
|
|
// set conversation.callState = null or undefined
|
|
|
|
// close the modal
|
|
|
|
// close the modal
|
|
|
|
if (firstCallingConvo) {
|
|
|
|
if (firstCallingConvo) {
|
|
|
|
firstCallingConvo.callState = undefined;
|
|
|
|
firstCallingConvo.callState = undefined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.warn('declined call');
|
|
|
|
console.warn('declined call');
|
|
|
|
}
|
|
|
|
await CallManager.USER_rejectIncomingCallRequest(fakeCaller);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleEndCall = () => {
|
|
|
|
const handleEndCall = async () => {
|
|
|
|
// call method to end call connection
|
|
|
|
// call method to end call connection
|
|
|
|
console.warn("ending the call");
|
|
|
|
console.warn('ending the call');
|
|
|
|
}
|
|
|
|
await CallManager.USER_rejectIncomingCallRequest(fakeCaller);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleMouseDown = () => {
|
|
|
|
const handleMouseDown = () => {
|
|
|
|
// reposition call window
|
|
|
|
// reposition call window
|
|
|
|
}
|
|
|
|
};
|
|
|
|
//#endregion
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
{connectionState === 'connecting' ?
|
|
|
|
{connectionState === 'connecting' ? 'connecting...' : null}
|
|
|
|
'connecting...'
|
|
|
|
{connectionState === 'ongoing' ? (
|
|
|
|
: null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
{connectionState === 'ongoing' ?
|
|
|
|
|
|
|
|
<CallWindow onMouseDown={handleMouseDown}>
|
|
|
|
<CallWindow onMouseDown={handleMouseDown}>
|
|
|
|
<CallWindowInner>
|
|
|
|
<CallWindowInner>
|
|
|
|
<CallWindowHeader>
|
|
|
|
<CallWindowHeader>
|
|
|
|
{ firstCallingConvo ? firstCallingConvo.getName() : 'Group name not found'}
|
|
|
|
{firstCallingConvo ? firstCallingConvo.getName() : 'Group name not found'}
|
|
|
|
</CallWindowHeader>
|
|
|
|
</CallWindowHeader>
|
|
|
|
<VideoContainer></VideoContainer>
|
|
|
|
<VideoContainer />
|
|
|
|
<CallWindowControls>
|
|
|
|
<CallWindowControls>
|
|
|
|
<SessionButton text={'end call'} onClick={handleEndCall} />
|
|
|
|
<SessionButton text={'end call'} onClick={handleEndCall} />
|
|
|
|
<SessionButton text={'end call'} onClick={handleEndCall} />
|
|
|
|
<SessionButton text={'end call'} onClick={handleEndCall} />
|
|
|
|
</CallWindowControls>
|
|
|
|
</CallWindowControls>
|
|
|
|
</CallWindowInner>
|
|
|
|
</CallWindowInner>
|
|
|
|
</CallWindow>
|
|
|
|
</CallWindow>
|
|
|
|
: null
|
|
|
|
) : null}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{!connectionState ?
|
|
|
|
{!connectionState ? (
|
|
|
|
<SessionWrapperModal title={'incoming call'}>
|
|
|
|
<SessionWrapperModal title={'incoming call'}>'none'</SessionWrapperModal>
|
|
|
|
'none'
|
|
|
|
) : null}
|
|
|
|
</SessionWrapperModal>
|
|
|
|
|
|
|
|
: null
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{connectionState === 'incoming' ?
|
|
|
|
{connectionState === 'incoming' ? (
|
|
|
|
<SessionWrapperModal title={'incoming call'}>
|
|
|
|
<SessionWrapperModal title={'incoming call'}>
|
|
|
|
<div className="session-modal__button-group">
|
|
|
|
<div className="session-modal__button-group">
|
|
|
|
<SessionButton text={'decline'} onClick={handleDeclineIncomingCall} />
|
|
|
|
<SessionButton text={'decline'} onClick={handleDeclineIncomingCall} />
|
|
|
|
@ -160,9 +160,7 @@ export const CallContainer = () => {
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</SessionWrapperModal>
|
|
|
|
</SessionWrapperModal>
|
|
|
|
: null
|
|
|
|
) : null}
|
|
|
|
}
|
|
|
|
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|