@@ -27,6 +27,7 @@ const DATACHANNEL = true;
27
27
const TG_CALLS = true ;
28
28
const TG_CALLS_MEDIA_STATE = true ;
29
29
const TG_CALLS_SDP = true ;
30
+ export const TG_CALLS_SDP_STRING = true ;
30
31
31
32
export function LOG_CALL ( str , ...data ) {
32
33
// return;
@@ -1813,10 +1814,10 @@ class CallStore extends EventEmitter {
1813
1814
const call = this . p2pGet ( callId )
1814
1815
if ( ! call ) return ;
1815
1816
1816
- // const { is_outgoing } = call;
1817
+ const { is_outgoing } = call ;
1817
1818
// if (!is_outgoing) return;
1818
1819
1819
- const offer = await connection . createOffer ( {
1820
+ let offer = await connection . createOffer ( {
1820
1821
offerToReceiveAudio : true ,
1821
1822
offerToReceiveVideo : true
1822
1823
} ) ;
@@ -1826,14 +1827,16 @@ class CallStore extends EventEmitter {
1826
1827
if ( TG_CALLS_SDP ) {
1827
1828
const initialSetup = p2pParseSdp ( offer . sdp ) ;
1828
1829
initialSetup [ '@type' ] = 'InitialSetup' ;
1830
+
1829
1831
this . p2pSendInitialSetup ( callId , initialSetup ) ;
1830
1832
if ( currentCall . answer ) {
1831
1833
await connection . setRemoteDescription ( currentCall . answer ) ;
1832
1834
currentCall . answer = null ;
1833
1835
if ( currentCall . candidates ) {
1834
1836
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);
1837
1840
} ) ;
1838
1841
currentCall . candidates = [ ] ;
1839
1842
}
@@ -1843,6 +1846,17 @@ class CallStore extends EventEmitter {
1843
1846
}
1844
1847
} ;
1845
1848
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
+
1846
1860
p2pAppendInputStream ( inputStream ) {
1847
1861
LOG_P2P_CALL ( 'p2pAppendInputStream start' , inputStream ) ;
1848
1862
const { currentCall } = this ;
@@ -1957,8 +1971,9 @@ class CallStore extends EventEmitter {
1957
1971
await connection . setRemoteDescription ( description ) ;
1958
1972
if ( currentCall . candidates ) {
1959
1973
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);
1962
1977
} ) ;
1963
1978
currentCall . candidates = [ ] ;
1964
1979
}
@@ -1991,8 +2006,9 @@ class CallStore extends EventEmitter {
1991
2006
LOG_P2P_CALL ( '[candidate] postpone' , iceCandidate ) ;
1992
2007
currentCall . candidates . push ( iceCandidate ) ;
1993
2008
} 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);
1996
2012
}
1997
2013
}
1998
2014
break ;
@@ -2004,10 +2020,12 @@ class CallStore extends EventEmitter {
2004
2020
const { fingerprints } = description ;
2005
2021
if ( fingerprints ) {
2006
2022
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
+ }
2011
2029
}
2012
2030
} )
2013
2031
}
@@ -2022,8 +2040,9 @@ class CallStore extends EventEmitter {
2022
2040
await connection . setRemoteDescription ( description ) ;
2023
2041
if ( currentCall . candidates ) {
2024
2042
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);
2027
2046
} ) ;
2028
2047
currentCall . candidates = [ ] ;
2029
2048
}
@@ -2050,10 +2069,22 @@ class CallStore extends EventEmitter {
2050
2069
let candidate = data ;
2051
2070
if ( UNIFY_CANDIDATE ) {
2052
2071
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
+
2053
2082
candidate = P2PSdpBuilder . generateCandidate ( x ) ;
2054
2083
candidate . sdpMLineIndex = 0 ;
2055
2084
2056
- candidates . push ( candidate ) ;
2085
+ // if (x.type === 'relay') {
2086
+ candidates . push ( candidate ) ;
2087
+ // }
2057
2088
} ) ;
2058
2089
}
2059
2090
if ( candidates . length > 0 ) {
@@ -2064,8 +2095,9 @@ class CallStore extends EventEmitter {
2064
2095
LOG_P2P_CALL ( '[candidate] postpone' , iceCandidate ) ;
2065
2096
currentCall . candidates . push ( iceCandidate ) ;
2066
2097
} 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);
2069
2101
}
2070
2102
} ) ;
2071
2103
}
0 commit comments