calls fix cross platforms issue with uuid
This commit is contained in:
parent
8c9832f118
commit
6625b7c7b6
|
@ -23,6 +23,8 @@ import {
|
|||
import { useModuloWithTripleDots } from '../../../hooks/useModuloWithTripleDots';
|
||||
import { CallWindowControls } from './CallButtons';
|
||||
import { SessionSpinner } from '../SessionSpinner';
|
||||
import { DEVICE_DISABLED_DEVICE_ID } from '../../../session/utils/CallManager';
|
||||
// import { useCallAudioLevel } from '../../../hooks/useCallAudioLevel';
|
||||
|
||||
const VideoContainer = styled.div`
|
||||
height: 100%;
|
||||
|
@ -135,6 +137,7 @@ export const InConversationCallContainer = () => {
|
|||
currentConnectedAudioInputs,
|
||||
currentConnectedCameras,
|
||||
currentConnectedAudioOutputs,
|
||||
currentSelectedAudioOutput,
|
||||
localStream,
|
||||
localStreamVideoIsMuted,
|
||||
remoteStream,
|
||||
|
@ -143,13 +146,25 @@ export const InConversationCallContainer = () => {
|
|||
isAudioOutputMuted,
|
||||
} = useVideoCallEventsListener('InConversationCallContainer', true);
|
||||
|
||||
// const isSpeaking = useCallAudioLevel();
|
||||
|
||||
if (videoRefRemote?.current && videoRefLocal?.current) {
|
||||
if (videoRefRemote.current.srcObject !== remoteStream) {
|
||||
videoRefRemote.current.srcObject = remoteStream;
|
||||
}
|
||||
|
||||
if (videoRefLocal.current.srcObject !== localStream) {
|
||||
videoRefLocal.current.srcObject = localStream;
|
||||
}
|
||||
|
||||
if (videoRefRemote.current) {
|
||||
if (currentSelectedAudioOutput === DEVICE_DISABLED_DEVICE_ID) {
|
||||
videoRefLocal.current.muted = true;
|
||||
} else {
|
||||
void videoRefLocal.current.setSinkId(currentSelectedAudioOutput);
|
||||
videoRefLocal.current.muted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ongoingCallWithFocused) {
|
||||
|
|
|
@ -3,7 +3,11 @@ import { useSelector } from 'react-redux';
|
|||
// tslint:disable-next-line: no-submodule-imports
|
||||
import useMountedState from 'react-use/lib/useMountedState';
|
||||
import { CallManager } from '../session/utils';
|
||||
import { CallManagerOptionsType, InputItem } from '../session/utils/CallManager';
|
||||
import {
|
||||
CallManagerOptionsType,
|
||||
DEVICE_DISABLED_DEVICE_ID,
|
||||
InputItem,
|
||||
} from '../session/utils/CallManager';
|
||||
import {
|
||||
getCallIsInFullScreen,
|
||||
getHasOngoingCallWithPubkey,
|
||||
|
@ -19,7 +23,9 @@ export function useVideoCallEventsListener(uniqueId: string, onSame: boolean) {
|
|||
const [remoteStream, setRemoteStream] = useState<MediaStream | null>(null);
|
||||
const [localStreamVideoIsMuted, setLocalStreamVideoIsMuted] = useState(true);
|
||||
const [ourAudioIsMuted, setOurAudioIsMuted] = useState(false);
|
||||
const [ourAudioOutputIsMuted, setOurAudioOutputIsMuted] = useState(false);
|
||||
const [currentSelectedAudioOutput, setCurrentSelectedAudioOutput] = useState(
|
||||
DEVICE_DISABLED_DEVICE_ID
|
||||
);
|
||||
const [remoteStreamVideoIsMuted, setRemoteStreamVideoIsMuted] = useState(true);
|
||||
const mountedState = useMountedState();
|
||||
|
||||
|
@ -47,7 +53,7 @@ export function useVideoCallEventsListener(uniqueId: string, onSame: boolean) {
|
|||
localStream: lLocalStream,
|
||||
remoteStream: lRemoteStream,
|
||||
isAudioMuted,
|
||||
isAudioOutputMuted,
|
||||
currentSelectedAudioOutput,
|
||||
} = options;
|
||||
if (mountedState()) {
|
||||
setLocalStream(lLocalStream);
|
||||
|
@ -55,7 +61,7 @@ export function useVideoCallEventsListener(uniqueId: string, onSame: boolean) {
|
|||
setRemoteStreamVideoIsMuted(isRemoteVideoStreamMuted);
|
||||
setLocalStreamVideoIsMuted(isLocalVideoStreamMuted);
|
||||
setOurAudioIsMuted(isAudioMuted);
|
||||
setOurAudioOutputIsMuted(isAudioOutputMuted);
|
||||
setCurrentSelectedAudioOutput(currentSelectedAudioOutput);
|
||||
|
||||
setCurrentConnectedCameras(camerasList);
|
||||
setCurrentConnectedAudioInputs(audioInputsList);
|
||||
|
@ -72,12 +78,13 @@ export function useVideoCallEventsListener(uniqueId: string, onSame: boolean) {
|
|||
return {
|
||||
currentConnectedAudioInputs,
|
||||
currentConnectedAudioOutputs,
|
||||
currentSelectedAudioOutput,
|
||||
currentConnectedCameras,
|
||||
localStreamVideoIsMuted,
|
||||
remoteStreamVideoIsMuted,
|
||||
localStream,
|
||||
remoteStream,
|
||||
isAudioMuted: ourAudioIsMuted,
|
||||
isAudioOutputMuted: ourAudioOutputIsMuted,
|
||||
isAudioOutputMuted: currentSelectedAudioOutput === DEVICE_DISABLED_DEVICE_ID,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ export type CallManagerOptionsType = {
|
|||
isLocalVideoStreamMuted: boolean;
|
||||
isRemoteVideoStreamMuted: boolean;
|
||||
isAudioMuted: boolean;
|
||||
isAudioOutputMuted: boolean;
|
||||
currentSelectedAudioOutput: string;
|
||||
};
|
||||
|
||||
export type CallManagerListener = ((options: CallManagerOptionsType) => void) | null;
|
||||
|
@ -59,7 +59,7 @@ function callVideoListeners() {
|
|||
isRemoteVideoStreamMuted: remoteVideoStreamIsMuted,
|
||||
isLocalVideoStreamMuted: selectedCameraId === DEVICE_DISABLED_DEVICE_ID,
|
||||
isAudioMuted: selectedAudioInputId === DEVICE_DISABLED_DEVICE_ID,
|
||||
isAudioOutputMuted: selectedAudioOutputId === DEVICE_DISABLED_DEVICE_ID,
|
||||
currentSelectedAudioOutput: selectedAudioOutputId,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -102,11 +102,13 @@ let isSettingRemoteAnswerPending = false;
|
|||
let lastOutgoingOfferTimestamp = -Infinity;
|
||||
|
||||
const configuration: RTCConfiguration = {
|
||||
bundlePolicy: 'max-bundle',
|
||||
rtcpMuxPolicy: 'require',
|
||||
iceServers: [
|
||||
{
|
||||
urls: 'turn:freyr.getsession.org',
|
||||
username: 'webrtc',
|
||||
credential: 'webrtc',
|
||||
username: 'session',
|
||||
credential: 'session',
|
||||
},
|
||||
],
|
||||
// iceTransportPolicy: 'relay', // for now, this cause the connection to break after 30-40 sec if we enable this
|
||||
|
@ -408,7 +410,7 @@ export async function USER_callRecipient(recipient: string) {
|
|||
throw new Error('USER_callRecipient peerConnection is already initialized ');
|
||||
}
|
||||
currentCallUUID = uuidv4();
|
||||
peerConnection = createOrGetPeerConnection(recipient, true);
|
||||
peerConnection = createOrGetPeerConnection(recipient);
|
||||
// send a pre offer just to wake up the device on the remote side
|
||||
const preOfferMsg = new CallMessage({
|
||||
timestamp: Date.now(),
|
||||
|
@ -575,25 +577,20 @@ function onDataChannelOnOpen() {
|
|||
sendVideoStatusViaDataChannel();
|
||||
}
|
||||
|
||||
function createOrGetPeerConnection(
|
||||
withPubkey: string,
|
||||
createDataChannel: boolean,
|
||||
isAcceptingCall = false
|
||||
) {
|
||||
function createOrGetPeerConnection(withPubkey: string, isAcceptingCall = false) {
|
||||
if (peerConnection) {
|
||||
return peerConnection;
|
||||
}
|
||||
remoteStream = new MediaStream();
|
||||
peerConnection = new RTCPeerConnection(configuration);
|
||||
if (createDataChannel) {
|
||||
dataChannel = peerConnection.createDataChannel('session-datachannel', {
|
||||
negotiated: true,
|
||||
id: 548, // SESSION dec ascii code 83*3+69+73+79+78
|
||||
});
|
||||
dataChannel = peerConnection.createDataChannel('session-datachannel', {
|
||||
ordered: true,
|
||||
negotiated: true,
|
||||
id: 548, // S E S S I O N in ascii code 83*3+69+73+79+78
|
||||
});
|
||||
|
||||
dataChannel.onmessage = onDataChannelReceivedMessage;
|
||||
dataChannel.onopen = onDataChannelOnOpen;
|
||||
}
|
||||
dataChannel.onmessage = onDataChannelReceivedMessage;
|
||||
dataChannel.onopen = onDataChannelOnOpen;
|
||||
|
||||
if (!isAcceptingCall) {
|
||||
peerConnection.onnegotiationneeded = async (event: Event) => {
|
||||
|
@ -601,17 +598,6 @@ function createOrGetPeerConnection(
|
|||
};
|
||||
}
|
||||
|
||||
// peerConnection.ondatachannel = e => {
|
||||
// if (!createDataChannel) {
|
||||
// dataChannel = e.channel;
|
||||
// window.log.info('Got our datachannel setup');
|
||||
|
||||
// onDataChannelOnOpen();
|
||||
|
||||
// dataChannel.onmessage = onDataChannelReceivedMessage;
|
||||
// }
|
||||
// };
|
||||
|
||||
peerConnection.onsignalingstatechange = handleSignalingStateChangeEvent;
|
||||
|
||||
peerConnection.ontrack = event => {
|
||||
|
@ -658,14 +644,18 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
|
|||
);
|
||||
return;
|
||||
}
|
||||
if (!lastOfferMessage.uuid) {
|
||||
window?.log?.info('incoming call request cannot be accepted as uuid is invalid');
|
||||
return;
|
||||
}
|
||||
window.inboxStore?.dispatch(answerCall({ pubkey: fromSender }));
|
||||
await openConversationWithMessages({ conversationKey: fromSender });
|
||||
if (peerConnection) {
|
||||
throw new Error('USER_acceptIncomingCallRequest: peerConnection is already set.');
|
||||
}
|
||||
currentCallUUID = uuidv4();
|
||||
currentCallUUID = lastOfferMessage.uuid;
|
||||
|
||||
peerConnection = createOrGetPeerConnection(fromSender, true, true);
|
||||
peerConnection = createOrGetPeerConnection(fromSender, true);
|
||||
|
||||
await openMediaDevicesAndAddTracks();
|
||||
|
||||
|
|
Loading…
Reference in New Issue