From c7f2ab91cad2feb3ee2a283bd941de5c9d140d83 Mon Sep 17 00:00:00 2001 From: evgeny-nadymov Date: Sat, 3 Apr 2021 04:41:00 +0300 Subject: [PATCH] Remove sessionId and media type Fix media order for local sdp --- package.json | 2 +- src/Calls/P2P/ChromeP2PSdpBuilder.js | 12 +++++++---- src/Calls/P2P/FirefoxP2PSdpBuilder.js | 12 +++++++---- src/Calls/P2P/P2PSdpBuilder.js | 31 +++++---------------------- src/Calls/P2P/SafariP2PSdpBuilder.js | 16 ++++++++------ src/Stores/CallStore.js | 5 ++++- 6 files changed, 36 insertions(+), 42 deletions(-) diff --git a/package.json b/package.json index 99930ae9f..6f11a21d0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "homepage": "https://evgeny-nadymov.github.io/telegram-react", "name": "telegram_react", - "version": "0.0.977", + "version": "0.0.978", "private": true, "dependencies": { "tdweb": "^1.7.2", diff --git a/src/Calls/P2P/ChromeP2PSdpBuilder.js b/src/Calls/P2P/ChromeP2PSdpBuilder.js index 557ae4812..b77348cf2 100644 --- a/src/Calls/P2P/ChromeP2PSdpBuilder.js +++ b/src/Calls/P2P/ChromeP2PSdpBuilder.js @@ -9,11 +9,13 @@ import { addDataChannel, addExtmap, addPayloadTypes, addSsrc } from './P2PSdpBui export class ChromeP2PSdpBuilder { static generateOffer(info) { - const { sessionId, fingerprints, ufrag, pwd, audio, video } = info; + const { fingerprints, ufrag, pwd, audio, video } = info; + audio.type = 'audio'; + video.type = 'video'; const media = [audio, video]; let sdp = `v=0 -o=- ${sessionId} 2 IN IP4 127.0.0.1 +o=- 1 2 IN IP4 127.0.0.1 s=- t=0 0`; if (fingerprints) { @@ -88,11 +90,13 @@ a=rtcp-rsize`; } static generateAnswer(info) { - const { sessionId, fingerprints, ufrag, pwd, audio, video } = info; + const { fingerprints, ufrag, pwd, audio, video } = info; + audio.type = 'audio'; + video.type = 'video'; const media = [audio, video]; let sdp = `v=0 -o=- ${sessionId} 2 IN IP4 127.0.0.1 +o=- 1 2 IN IP4 127.0.0.1 s=- t=0 0`; if (fingerprints) { diff --git a/src/Calls/P2P/FirefoxP2PSdpBuilder.js b/src/Calls/P2P/FirefoxP2PSdpBuilder.js index a3c77ad82..f97c07f40 100644 --- a/src/Calls/P2P/FirefoxP2PSdpBuilder.js +++ b/src/Calls/P2P/FirefoxP2PSdpBuilder.js @@ -9,11 +9,13 @@ import { addDataChannel, addExtmap, addPayloadTypes, addSsrc } from './P2PSdpBui export class FirefoxP2PSdpBuilder { static generateOffer(info) { - const { sessionId, fingerprints, ufrag, pwd, audio, video } = info; + const { fingerprints, ufrag, pwd, audio, video } = info; + audio.type = 'audio'; + video.type = 'video'; const media = [audio, video]; let sdp = `v=0 -o=- ${sessionId} 0 IN IP4 0.0.0.0 +o=- 1 0 IN IP4 0.0.0.0 s=- t=0 0`; if (fingerprints) { @@ -78,11 +80,13 @@ a=rtcp-rsize`; } static generateAnswer(info) { - const { sessionId, fingerprints, ufrag, pwd, audio, video } = info; + const { fingerprints, ufrag, pwd, audio, video } = info; + audio.type = 'audio'; + video.type = 'video'; const media = [audio, video]; let sdp = `v=0 -o=- ${sessionId} 0 IN IP4 0.0.0.0 +o=- 1 0 IN IP4 0.0.0.0 s=- t=0 0`; if (fingerprints) { diff --git a/src/Calls/P2P/P2PSdpBuilder.js b/src/Calls/P2P/P2PSdpBuilder.js index cc7f0e1ea..019b7c0d4 100644 --- a/src/Calls/P2P/P2PSdpBuilder.js +++ b/src/Calls/P2P/P2PSdpBuilder.js @@ -101,31 +101,12 @@ export function p2pParseSdp(sdp) { return -1; }; - const findDirection = (lineFrom = 0, lineTo = Number.MAX_VALUE) => { - if (lineTo === -1) { - lineTo = Number.MAX_VALUE; - } - for (let i = lineFrom; i < lines.length && i < lineTo; i++) { - const line = lines[i]; - if (line.startsWith('a=sendonly')) { - return 'sendonly'; - } else if (line.startsWith('a=recvonly')) { - return 'recvonly'; - } else if (line.startsWith('a=sendrecv')) { - return 'sendrecv'; - } else if (line.startsWith('a=inactive')) { - return 'inactive'; - } - } - - return ''; - } const pwdIndex = findIndex('a=ice-pwd:'); const ufragIndex = findIndex('a=ice-ufrag:'); if (pwdIndex === -1 && ufragIndex === -1) { return { - sessionId: lookup('o=').split(' ')[1], + // sessionId: lookup('o=').split(' ')[1], ufrag: null, pwd: null, fingerprints: [] @@ -133,7 +114,7 @@ export function p2pParseSdp(sdp) { } const info = { - sessionId: lookup('o=').split(' ')[1], + // sessionId: lookup('o=').split(' ')[1], ufrag: null, pwd: null, fingerprints: [] @@ -162,8 +143,9 @@ export function p2pParseSdp(sdp) { const extmap = []; const types = []; + const mediaType = lookup('m=', true, mediaIndex, nextMediaIndex).split(' ')[0]; const media = { - type: lookup('m=', true, mediaIndex, nextMediaIndex).split(' ')[0], + // type: lookup('m=', true, mediaIndex, nextMediaIndex).split(' ')[0], // mid: lookup('a=mid:', true, mediaIndex, nextMediaIndex), // dir: findDirection(mediaIndex, nextMediaIndex), rtpExtensions: extmap, @@ -225,10 +207,7 @@ export function p2pParseSdp(sdp) { }] } - switch (media.type) { - case 'application': { - break; - } + switch (mediaType) { case 'audio': { info.audio = media; break; diff --git a/src/Calls/P2P/SafariP2PSdpBuilder.js b/src/Calls/P2P/SafariP2PSdpBuilder.js index cbae232ac..e5d99ae9a 100644 --- a/src/Calls/P2P/SafariP2PSdpBuilder.js +++ b/src/Calls/P2P/SafariP2PSdpBuilder.js @@ -9,12 +9,14 @@ import { addDataChannel, addExtmap, addPayloadTypes, addSsrc } from './P2PSdpBui export class SafariP2PSdpBuilder { static generateOffer(info) { - const { sessionId, fingerprints, ufrag, pwd, audio, video } = info; + const { fingerprints, ufrag, pwd, audio, video } = info; + audio.type = 'audio'; + video.type = 'video'; const media = [audio, video]; if (!media.length) { return `v=0 -o=- ${sessionId} 2 IN IP4 127.0.0.1 +o=- 1 2 IN IP4 127.0.0.1 s=- t=0 0 a=msid-semantic: WMS @@ -22,7 +24,7 @@ a=msid-semantic: WMS } let sdp = `v=0 -o=- ${sessionId} 2 IN IP4 127.0.0.1 +o=- 1 2 IN IP4 127.0.0.1 s=- t=0 0`; if (fingerprints) { @@ -98,12 +100,14 @@ a=rtcp-rsize`; } static generateAnswer(info) { - const { sessionId, fingerprints, ufrag, pwd, audio, video } = info; + const { fingerprints, ufrag, pwd, audio, video } = info; + audio.type = 'audio'; + video.type = 'video'; const media = [audio, video]; if (!media.length) { return `v=0 -o=- ${sessionId} 2 IN IP4 127.0.0.1 +o=- 1 2 IN IP4 127.0.0.1 s=- t=0 0 a=msid-semantic: WMS @@ -111,7 +115,7 @@ a=msid-semantic: WMS } let sdp = `v=0 -o=- ${sessionId} 2 IN IP4 127.0.0.1 +o=- 1 2 IN IP4 127.0.0.1 s=- t=0 0`; if (fingerprints) { diff --git a/src/Stores/CallStore.js b/src/Stores/CallStore.js index 0eac856b0..e02791f1f 100644 --- a/src/Stores/CallStore.js +++ b/src/Stores/CallStore.js @@ -1858,7 +1858,10 @@ class CallStore extends EventEmitter { const senders = connection.getSenders(); if (senders.some(x => x.track)) return; - inputStream && inputStream.getTracks().forEach(x => { + inputStream && inputStream.getAudioTracks().forEach(x => { + connection.addTrack(x, inputStream); + }); + inputStream && inputStream.getVideoTracks().forEach(x => { connection.addTrack(x, inputStream); }); LOG_P2P_CALL('p2pAppendInputStream stop', inputStream);