@@ -1799,6 +1799,13 @@ class CallStore extends EventEmitter {
1799
1799
video : true ,
1800
1800
audio : true
1801
1801
} ) ;
1802
+
1803
+ if ( mediaState && mediaState . videoState === 'inactive' ) {
1804
+ inputStream . getVideoTracks ( ) . forEach ( x => {
1805
+ x . enabled = false ;
1806
+ } ) ;
1807
+ }
1808
+
1802
1809
this . currentCall . inputStream = inputStream ;
1803
1810
1804
1811
const inputVideo = document . getElementById ( 'call-input-video' ) ;
@@ -1807,14 +1814,6 @@ class CallStore extends EventEmitter {
1807
1814
}
1808
1815
if ( TG_CALLS_SDP ) {
1809
1816
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
- // }
1818
1817
} else {
1819
1818
if ( is_outgoing ) {
1820
1819
this . p2pAppendInputStream ( inputStream ) ;
@@ -2217,7 +2216,7 @@ class CallStore extends EventEmitter {
2217
2216
const { currentCall } = this ;
2218
2217
if ( ! currentCall ) return ;
2219
2218
2220
- const { connection } = currentCall ;
2219
+ const { callId , connection } = currentCall ;
2221
2220
if ( ! connection ) return ;
2222
2221
2223
2222
const options = {
@@ -2243,6 +2242,11 @@ class CallStore extends EventEmitter {
2243
2242
inputVideo . srcObject = screenStream ;
2244
2243
}
2245
2244
2245
+ const inputMediaState = this . p2pGetMediaState ( callId , 'input' ) ;
2246
+ if ( inputMediaState && inputMediaState . videoState !== 'active' ) {
2247
+ this . p2pVideoEnabled ( true ) ;
2248
+ }
2249
+
2246
2250
currentCall . screenStream = screenStream ;
2247
2251
}
2248
2252
@@ -2255,15 +2259,11 @@ class CallStore extends EventEmitter {
2255
2259
if ( ! screenStream ) return ;
2256
2260
2257
2261
const videoTracks = inputStream . getVideoTracks ( ) ;
2258
- if ( videoTracks . length > 0 )
2262
+ const videoTrack = videoTracks . length > 0 ? videoTracks [ 0 ] : null
2259
2263
2260
2264
connection . getSenders ( ) . forEach ( x => {
2261
2265
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 ) ;
2267
2267
}
2268
2268
} )
2269
2269
@@ -2277,6 +2277,10 @@ class CallStore extends EventEmitter {
2277
2277
}
2278
2278
2279
2279
currentCall . screenStream = null ;
2280
+
2281
+ if ( ! videoTrack || videoTrack . readyState !== 'live' ) {
2282
+ this . p2pVideoEnabled ( false ) ;
2283
+ }
2280
2284
}
2281
2285
2282
2286
p2pCloseConnectionAndStream ( connection , inputStream , outputStream , screenStream ) {
@@ -2352,7 +2356,7 @@ class CallStore extends EventEmitter {
2352
2356
}
2353
2357
}
2354
2358
2355
- p2pVideoEnabled ( enabled ) {
2359
+ async p2pVideoEnabled ( enabled ) {
2356
2360
const { currentCall } = this ;
2357
2361
if ( ! currentCall ) return ;
2358
2362
0 commit comments