Skip to content

Commit b7d1c74

Browse files
author
evgeny-nadymov
committed
Stop video stream for audio only calls
Close video tag when video stream stopped
1 parent af281d9 commit b7d1c74

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

src/Components/Calls/CallPanel.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
.call-video-inactive {
9+
display: none;
10+
}
11+
812
.call-panel-microphone-hint {
913
display: flex;
1014
align-items: center;

src/Components/Calls/CallPanel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ class CallPanel extends React.Component {
330330
</Popover>
331331
</div>
332332
<div className='call-panel-content scrollbars-hidden' onDoubleClick={this.handleFullScreen}>
333-
<video id='call-output-video' autoPlay={true} muted={false}/>
334-
<video id='call-input-video' autoPlay={true} muted={true}/>
333+
<video id='call-output-video' className={outputMediaState && outputMediaState.videoState === 'active' ? 'call-video-active' : 'call-video-inactive'} autoPlay={true} muted={false}/>
334+
<video id='call-input-video' className={inputMediaState && inputMediaState.videoState === 'active' ? 'call-video-active' : 'call-video-inactive'} autoPlay={true} muted={true}/>
335335
</div>
336336
{ outputMediaState && outputMediaState.muted && (
337337
<div className='call-panel-microphone-hint'>

src/Stores/CallStore.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,13 @@ class CallStore extends EventEmitter {
17991799
video: true,
18001800
audio: true
18011801
});
1802+
1803+
if (mediaState && mediaState.videoState === 'inactive') {
1804+
inputStream.getVideoTracks().forEach(x => {
1805+
x.enabled = false;
1806+
});
1807+
}
1808+
18021809
this.currentCall.inputStream = inputStream;
18031810

18041811
const inputVideo = document.getElementById('call-input-video');
@@ -1807,14 +1814,6 @@ class CallStore extends EventEmitter {
18071814
}
18081815
if (TG_CALLS_SDP) {
18091816
this.p2pAppendInputStream(inputStream);
1810-
// if (is_outgoing) {
1811-
// this.p2pAppendInputStream(inputStream);
1812-
// } else {
1813-
// LOG_P2P_CALL('try invoke p2pAppendInputStream', connection.localDescription, connection.remoteDescription);
1814-
// if (connection.localDescription && connection.remoteDescription) {
1815-
// this.p2pAppendInputStream(inputStream);
1816-
// }
1817-
// }
18181817
} else {
18191818
if (is_outgoing) {
18201819
this.p2pAppendInputStream(inputStream);
@@ -2217,7 +2216,7 @@ class CallStore extends EventEmitter {
22172216
const { currentCall } = this;
22182217
if (!currentCall) return;
22192218

2220-
const { connection } = currentCall;
2219+
const { callId, connection } = currentCall;
22212220
if (!connection) return;
22222221

22232222
const options = {
@@ -2243,6 +2242,11 @@ class CallStore extends EventEmitter {
22432242
inputVideo.srcObject = screenStream;
22442243
}
22452244

2245+
const inputMediaState = this.p2pGetMediaState(callId, 'input');
2246+
if (inputMediaState && inputMediaState.videoState !== 'active') {
2247+
this.p2pVideoEnabled(true);
2248+
}
2249+
22462250
currentCall.screenStream = screenStream;
22472251
}
22482252

@@ -2255,15 +2259,11 @@ class CallStore extends EventEmitter {
22552259
if (!screenStream) return;
22562260

22572261
const videoTracks = inputStream.getVideoTracks();
2258-
if (videoTracks.length > 0)
2262+
const videoTrack = videoTracks.length > 0 ? videoTracks[0] : null
22592263

22602264
connection.getSenders().forEach(x => {
22612265
if (x.track.kind === 'video') {
2262-
if (videoTracks.length > 0) {
2263-
x.replaceTrack(videoTracks[0]);
2264-
} else {
2265-
x.replaceTrack(null);
2266-
}
2266+
x.replaceTrack(videoTrack);
22672267
}
22682268
})
22692269

@@ -2277,6 +2277,10 @@ class CallStore extends EventEmitter {
22772277
}
22782278

22792279
currentCall.screenStream = null;
2280+
2281+
if (!videoTrack || videoTrack.readyState !== 'live') {
2282+
this.p2pVideoEnabled(false);
2283+
}
22802284
}
22812285

22822286
p2pCloseConnectionAndStream(connection, inputStream, outputStream, screenStream) {
@@ -2352,7 +2356,7 @@ class CallStore extends EventEmitter {
23522356
}
23532357
}
23542358

2355-
p2pVideoEnabled(enabled) {
2359+
async p2pVideoEnabled(enabled) {
23562360
const { currentCall } = this;
23572361
if (!currentCall) return;
23582362

0 commit comments

Comments
 (0)