Skip to content

Commit cd7b175

Browse files
author
evgeny-nadymov
committed
Mute self mic
1 parent ea0cd0c commit cd7b175

File tree

4 files changed

+79
-33
lines changed

4 files changed

+79
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"homepage": "https://evgeny-nadymov.github.io/telegram-react",
33
"name": "telegram_react",
4-
"version": "0.0.979",
4+
"version": "0.0.983",
55
"private": true,
66
"dependencies": {
77
"tdweb": "^1.7.2",

src/Calls/P2P/P2PSdpBuilder.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { ChromeP2PSdpBuilder } from './ChromeP2PSdpBuilder';
99
import { FirefoxP2PSdpBuilder } from './FirefoxP2PSdpBuilder';
1010
import { SafariP2PSdpBuilder } from './SafariP2PSdpBuilder';
11+
import { TG_CALLS_SDP_STRING } from '../../Stores/CallStore';
1112

1213
export function p2pParseCandidate(candidate) {
1314
if (!candidate) {
@@ -17,10 +18,12 @@ export function p2pParseCandidate(candidate) {
1718
return null;
1819
}
1920

21+
const sdpString = candidate;
2022
candidate = candidate.substr('candidate:'.length);
2123

2224
const [ foundation, component, protocol, priority, ip, port, ...other ] = candidate.split(' ');
2325
const c = {
26+
sdpString,
2427
foundation,
2528
component,
2629
protocol,
@@ -169,11 +172,13 @@ export function p2pParseSdp(sdp) {
169172
extmap.push({ id: parseInt(id), uri });
170173
} else if (line.startsWith('a=fmtp:')) {
171174
const [ id, str ] = line.substr('a=fmtp:'.length).split(' ');
175+
const obj = { };
172176
const arr = str.split(';').map(x => {
173177
const [ key, value ] = x.split('=');
178+
obj[key] = value;
174179
return { [key]: value };
175180
});
176-
fmtp.set(parseInt(id), arr);
181+
fmtp.set(parseInt(id), obj);
177182
} else if (line.startsWith('a=rtcp-fb:')) {
178183
const [ id, type = '', subtype = '' ] = line.substr('a=rtcp-fb:'.length).split(' ');
179184
if (rtcpFb.has(parseInt(id))) {
@@ -202,15 +207,15 @@ export function p2pParseSdp(sdp) {
202207

203208
const ssrc = lookup('a=ssrc:', false, mediaIndex, nextMediaIndex);
204209
if (ssrc) {
205-
media.ssrc = parseInt(ssrc.split(' ')[0]);
210+
media.ssrc = ssrc.split(' ')[0];
206211
}
207212

208213
const ssrcGroup = lookup('a=ssrc-group:', false, mediaIndex, nextMediaIndex);
209214
if (ssrcGroup) {
210215
const [ semantics, ...ssrcs ] = ssrcGroup.split(' ');
211216
media.ssrcGroups = [{
212217
semantics,
213-
ssrcs: ssrcs.map(x => parseInt(x))
218+
ssrcs
214219
}]
215220
}
216221

@@ -256,7 +261,7 @@ a=extmap:${id} ${uri}`;
256261

257262
export function addPayloadTypes(types) {
258263
let sdp = '';
259-
264+
console.log('[SDP] addPayloadTypes', types);
260265
for (let i = 0; i < types.length; i++) {
261266
const type = types[i];
262267
const { id, name, clockrate, channels, feedbackTypes, parameters } = type;
@@ -270,12 +275,10 @@ a=rtcp-fb:${id} ${[type, subtype].join(' ')}`;
270275
});
271276
}
272277
if (parameters) {
273-
const fmtp = parameters.reduce((arr, x) => {
274-
Object.getOwnPropertyNames(x).forEach(pName => {
275-
arr.push(`${pName}=${x[pName]}`);
276-
});
277-
return arr;
278-
}, []);
278+
const fmtp = [];
279+
Object.getOwnPropertyNames(parameters).forEach(pName => {
280+
fmtp.push(`${pName}=${parameters[pName]}`);
281+
});
279282

280283
sdp += `
281284
a=fmtp:${id} ${fmtp.join(';')}`;
@@ -327,7 +330,18 @@ export class P2PSdpBuilder {
327330
static generateCandidate(info) {
328331
if (!info) return null;
329332

330-
const { sdpMLineIndex, sdpMid, foundation, component, protocol, priority, address, type, relAddress, generation, tcpType, networkId, networkCost, username } = info;
333+
const { sdpString, sdpMLineIndex, sdpMid, foundation, component, protocol, priority, address, type, relAddress, generation, tcpType, networkId, networkCost, username } = info;
334+
if (TG_CALLS_SDP_STRING) {
335+
if (sdpString) {
336+
return {
337+
candidate: sdpString,
338+
sdpMLineIndex,
339+
sdpMid
340+
};
341+
}
342+
}
343+
throw 'no sdpString';
344+
331345
let candidate = `candidate:${foundation} ${component} ${protocol} ${priority} ${address.ip} ${address.port}`;
332346
const attrs = []
333347
if (type) {
@@ -337,12 +351,12 @@ export class P2PSdpBuilder {
337351
attrs.push(`raddr ${relAddress.ip}`);
338352
attrs.push(`rport ${relAddress.port}`);
339353
}
340-
if (generation) {
341-
attrs.push(`generation ${generation}`);
342-
}
343354
if (tcpType) {
344355
attrs.push(`tcptype ${tcpType}`);
345356
}
357+
if (generation) {
358+
attrs.push(`generation ${generation}`);
359+
}
346360
if (username) {
347361
attrs.push(`ufrag ${username}`);
348362
}

src/Components/Calls/CallPanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class CallPanel extends React.Component {
358358
</div>
359359
<div className='call-panel-content scrollbars-hidden' onDoubleClick={this.handleFullScreen}>
360360
<video id='call-output-video' autoPlay={true} muted={false}/>
361-
<video id='call-input-video' autoPlay={true} muted={false}/>
361+
<video id='call-input-video' autoPlay={true} muted={true}/>
362362
</div>
363363
{ !otherAudioEnabled && (
364364
<div className='call-panel-microphone-hint'>

src/Stores/CallStore.js

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const DATACHANNEL = true;
2727
const TG_CALLS = true;
2828
const TG_CALLS_MEDIA_STATE = true;
2929
const TG_CALLS_SDP = true;
30+
export const TG_CALLS_SDP_STRING = true;
3031

3132
export function LOG_CALL(str, ...data) {
3233
// return;
@@ -1813,10 +1814,10 @@ class CallStore extends EventEmitter {
18131814
const call = this.p2pGet(callId)
18141815
if (!call) return;
18151816

1816-
// const { is_outgoing } = call;
1817+
const { is_outgoing } = call;
18171818
// if (!is_outgoing) return;
18181819

1819-
const offer = await connection.createOffer({
1820+
let offer = await connection.createOffer({
18201821
offerToReceiveAudio: true,
18211822
offerToReceiveVideo: true
18221823
});
@@ -1826,14 +1827,16 @@ class CallStore extends EventEmitter {
18261827
if (TG_CALLS_SDP) {
18271828
const initialSetup = p2pParseSdp(offer.sdp);
18281829
initialSetup['@type'] = 'InitialSetup';
1830+
18291831
this.p2pSendInitialSetup(callId, initialSetup);
18301832
if (currentCall.answer) {
18311833
await connection.setRemoteDescription(currentCall.answer);
18321834
currentCall.answer = null;
18331835
if (currentCall.candidates) {
18341836
currentCall.candidates.forEach(x => {
1835-
LOG_P2P_CALL('[candidate] add postpone', x);
1836-
connection.addIceCandidate(x);
1837+
this.p2pAddIceCandidate(connection, x);
1838+
// LOG_P2P_CALL('[candidate] add postpone', x);
1839+
// connection.addIceCandidate(x);
18371840
});
18381841
currentCall.candidates = [];
18391842
}
@@ -1843,6 +1846,17 @@ class CallStore extends EventEmitter {
18431846
}
18441847
};
18451848

1849+
async p2pAddIceCandidate(connection, candidate) {
1850+
LOG_P2P_CALL('[candidate] start', candidate);
1851+
try {
1852+
// if (!candidate.address) return;
1853+
await connection.addIceCandidate(candidate);
1854+
LOG_P2P_CALL('[candidate] add', candidate);
1855+
} catch (e) {
1856+
LOG_P2P_CALL('[candidate] error', candidate, e);
1857+
}
1858+
}
1859+
18461860
p2pAppendInputStream(inputStream) {
18471861
LOG_P2P_CALL('p2pAppendInputStream start', inputStream);
18481862
const { currentCall } = this;
@@ -1957,8 +1971,9 @@ class CallStore extends EventEmitter {
19571971
await connection.setRemoteDescription(description);
19581972
if (currentCall.candidates) {
19591973
currentCall.candidates.forEach(x => {
1960-
LOG_P2P_CALL('[candidate] add postpone', x);
1961-
connection.addIceCandidate(x);
1974+
this.p2pAddIceCandidate(connection, x);
1975+
// LOG_P2P_CALL('[candidate] add postpone', x);
1976+
// connection.addIceCandidate(x);
19621977
});
19631978
currentCall.candidates = [];
19641979
}
@@ -1991,8 +2006,9 @@ class CallStore extends EventEmitter {
19912006
LOG_P2P_CALL('[candidate] postpone', iceCandidate);
19922007
currentCall.candidates.push(iceCandidate);
19932008
} else {
1994-
LOG_P2P_CALL('[candidate] add', iceCandidate);
1995-
await connection.addIceCandidate(iceCandidate);
2009+
await this.p2pAddIceCandidate(connection, iceCandidate);
2010+
// LOG_P2P_CALL('[candidate] add', iceCandidate);
2011+
// await connection.addIceCandidate(iceCandidate);
19962012
}
19972013
}
19982014
break;
@@ -2004,10 +2020,12 @@ class CallStore extends EventEmitter {
20042020
const { fingerprints } = description;
20052021
if (fingerprints) {
20062022
fingerprints.forEach(x => {
2007-
if (is_outgoing) {
2008-
x.setup = 'active';
2009-
} else {
2010-
x.setup = 'passive';
2023+
if (x.setup === 'actpass') {
2024+
if (is_outgoing) {
2025+
x.setup = 'active';
2026+
} else {
2027+
x.setup = 'passive';
2028+
}
20112029
}
20122030
})
20132031
}
@@ -2022,8 +2040,9 @@ class CallStore extends EventEmitter {
20222040
await connection.setRemoteDescription(description);
20232041
if (currentCall.candidates) {
20242042
currentCall.candidates.forEach(x => {
2025-
LOG_P2P_CALL('[candidate] add postpone', x);
2026-
connection.addIceCandidate(x);
2043+
this.p2pAddIceCandidate(connection, x);
2044+
// LOG_P2P_CALL('[candidate] add postpone', x);
2045+
// connection.addIceCandidate(x);
20272046
});
20282047
currentCall.candidates = [];
20292048
}
@@ -2050,10 +2069,22 @@ class CallStore extends EventEmitter {
20502069
let candidate = data;
20512070
if (UNIFY_CANDIDATE) {
20522071
data.candidates.forEach(x => {
2072+
// if (x.type === 'local') {
2073+
// x.type = 'host';
2074+
// } else if (x.type === 'relay') {
2075+
// x.component = 1;
2076+
// x.relAddress = {
2077+
// ip: '0.0.0.0',
2078+
// port: 0
2079+
// }
2080+
// }
2081+
20532082
candidate = P2PSdpBuilder.generateCandidate(x);
20542083
candidate.sdpMLineIndex = 0;
20552084

2056-
candidates.push(candidate);
2085+
// if (x.type === 'relay') {
2086+
candidates.push(candidate);
2087+
// }
20572088
});
20582089
}
20592090
if (candidates.length > 0) {
@@ -2064,8 +2095,9 @@ class CallStore extends EventEmitter {
20642095
LOG_P2P_CALL('[candidate] postpone', iceCandidate);
20652096
currentCall.candidates.push(iceCandidate);
20662097
} else {
2067-
LOG_P2P_CALL('[candidate] add', iceCandidate);
2068-
await connection.addIceCandidate(iceCandidate);
2098+
await this.p2pAddIceCandidate(connection, iceCandidate);
2099+
// LOG_P2P_CALL('[candidate] add', iceCandidate);
2100+
// await connection.addIceCandidate(iceCandidate);
20692101
}
20702102
});
20712103
}

0 commit comments

Comments
 (0)