video stream displayed on mobile

pull/1939/head
Audric Ackermann 4 years ago
parent eb6d8727ba
commit 2e49c44536
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -4,7 +4,6 @@ import { CallMessage } from '../messages/outgoing/controlMessage/CallMessage';
import { ed25519Str } from '../onions/onionPath'; import { ed25519Str } from '../onions/onionPath';
import { getMessageQueue } from '../sending'; import { getMessageQueue } from '../sending';
import { PubKey } from '../types'; import { PubKey } from '../types';
import { sleepFor } from './Promise';
const incomingCall = ({ sender }: { sender: string }) => { const incomingCall = ({ sender }: { sender: string }) => {
return { type: 'incomingCall', payload: sender }; return { type: 'incomingCall', payload: sender };
@ -56,10 +55,10 @@ export async function USER_callRecipient(recipient: string) {
} }
peerConnection = new RTCPeerConnection(configuration); peerConnection = new RTCPeerConnection(configuration);
const mediadevices = await openMediaDevices(); const mediaDevices = await openMediaDevices();
mediadevices.getTracks().map(track => { mediaDevices.getTracks().map(track => {
window.log.info('USER_callRecipient adding track: ', track); window.log.info('USER_callRecipient adding track: ', track);
peerConnection?.addTrack(track); peerConnection?.addTrack(track, mediaDevices);
}); });
peerConnection.addEventListener('connectionstatechange', _event => { peerConnection.addEventListener('connectionstatechange', _event => {
window.log.info('peerConnection?.connectionState:', peerConnection?.connectionState); window.log.info('peerConnection?.connectionState:', peerConnection?.connectionState);
@ -76,6 +75,7 @@ export async function USER_callRecipient(recipient: string) {
void iceSenderDebouncer(recipient); void iceSenderDebouncer(recipient);
} }
}); });
const offerDescription = await peerConnection.createOffer({ const offerDescription = await peerConnection.createOffer({
offerToReceiveAudio: true, offerToReceiveAudio: true,
offerToReceiveVideo: ENABLE_VIDEO, offerToReceiveVideo: ENABLE_VIDEO,
@ -91,6 +91,7 @@ export async function USER_callRecipient(recipient: string) {
type: SignalService.CallMessage.Type.OFFER, type: SignalService.CallMessage.Type.OFFER,
sdps: [offerDescription.sdp], sdps: [offerDescription.sdp],
}); });
window.log.info('sending OFFER MESSAGE'); window.log.info('sending OFFER MESSAGE');
await getMessageQueue().sendToPubKeyNonDurably(PubKey.cast(recipient), callOfferMessage); await getMessageQueue().sendToPubKeyNonDurably(PubKey.cast(recipient), callOfferMessage);
// FIXME audric dispatch UI update to show the calling UI // FIXME audric dispatch UI update to show the calling UI
@ -132,30 +133,11 @@ const iceSenderDebouncer = _.debounce(async (recipient: string) => {
const openMediaDevices = async () => { const openMediaDevices = async () => {
return navigator.mediaDevices.getUserMedia({ return navigator.mediaDevices.getUserMedia({
// video: video: ENABLE_VIDEO,
video: ENABLE_VIDEO
? {
width: 320,
height: 240,
}
: false,
audio: true, audio: true,
}); });
}; };
const printStatsLoop = async () => {
// tslint:disable-next-line: no-constant-condition
while (true) {
if (peerConnection) {
const stats = await peerConnection?.getStats();
stats.forEach(st => {
console.warn('stat: ', st);
});
}
await sleepFor(5000);
}
};
// tslint:disable-next-line: function-name // tslint:disable-next-line: function-name
export async function USER_acceptIncomingCallRequest(fromSender: string) { export async function USER_acceptIncomingCallRequest(fromSender: string) {
const msgCacheFromSender = callCache.get(fromSender); const msgCacheFromSender = callCache.get(fromSender);
@ -183,16 +165,16 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
peerConnection = null; peerConnection = null;
} }
peerConnection = new RTCPeerConnection(configuration); peerConnection = new RTCPeerConnection(configuration);
const mediadevices = await openMediaDevices(); const mediaDevices = await openMediaDevices();
mediadevices.getTracks().map(track => { mediaDevices.getTracks().map(track => {
window.log.info('USER_acceptIncomingCallRequest adding track ', track); window.log.info('USER_acceptIncomingCallRequest adding track ', track);
peerConnection?.addTrack(track); peerConnection?.addTrack(track, mediaDevices);
}); });
peerConnection.addEventListener('icecandidateerror', event => { peerConnection.addEventListener('icecandidateerror', event => {
console.warn('icecandidateerror:', event); console.warn('icecandidateerror:', event);
}); });
peerConnection.addEventListener('negotiationneeded', event => { peerConnection.addEventListener('negotiationneeded', async event => {
console.warn('negotiationneeded:', event); console.warn('negotiationneeded:', event);
}); });
peerConnection.addEventListener('signalingstatechange', event => { peerConnection.addEventListener('signalingstatechange', event => {
@ -219,6 +201,7 @@ export async function USER_acceptIncomingCallRequest(fromSender: string) {
await peerConnection.setRemoteDescription( await peerConnection.setRemoteDescription(
new RTCSessionDescription({ sdp: sdps[0], type: 'offer' }) new RTCSessionDescription({ sdp: sdps[0], type: 'offer' })
); );
const answer = await peerConnection.createAnswer({ const answer = await peerConnection.createAnswer({
offerToReceiveAudio: true, offerToReceiveAudio: true,
offerToReceiveVideo: ENABLE_VIDEO, offerToReceiveVideo: ENABLE_VIDEO,
@ -332,4 +315,3 @@ export async function handleOtherCallMessage(
) { ) {
callCache.get(sender)?.push(callMessage); callCache.get(sender)?.push(callMessage);
} }
void printStatsLoop();

Loading…
Cancel
Save