Skip to content

Commit

Permalink
Remove sessionId and media type
Browse files Browse the repository at this point in the history
Fix media order for local sdp
  • Loading branch information
evgeny-nadymov committed Apr 3, 2021
1 parent 06c7f50 commit c7f2ab9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 8 additions & 4 deletions src/Calls/P2P/ChromeP2PSdpBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions src/Calls/P2P/FirefoxP2PSdpBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
31 changes: 5 additions & 26 deletions src/Calls/P2P/P2PSdpBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,20 @@ 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: []
};
}

const info = {
sessionId: lookup('o=').split(' ')[1],
// sessionId: lookup('o=').split(' ')[1],
ufrag: null,
pwd: null,
fingerprints: []
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -225,10 +207,7 @@ export function p2pParseSdp(sdp) {
}]
}

switch (media.type) {
case 'application': {
break;
}
switch (mediaType) {
case 'audio': {
info.audio = media;
break;
Expand Down
16 changes: 10 additions & 6 deletions src/Calls/P2P/SafariP2PSdpBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ 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
`;
}

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) {
Expand Down Expand Up @@ -98,20 +100,22 @@ 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
`;
}

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) {
Expand Down
5 changes: 4 additions & 1 deletion src/Stores/CallStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c7f2ab9

Please sign in to comment.