@@ -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