@@ -19,6 +19,7 @@ import AppStore from './ApplicationStore';
19
19
import LStore from './LocalizationStore' ;
20
20
import UserStore from './UserStore' ;
21
21
import TdLibController from '../Controllers/TdLibController' ;
22
+ import P2PEncryptor from '../Calls/P2P/P2PEncryptor' ;
22
23
23
24
const JOIN_TRACKS = true ;
24
25
const UNIFY_SDP = true ;
@@ -243,10 +244,18 @@ class CallStore extends EventEmitter {
243
244
const { call_id, data } = update ;
244
245
245
246
try {
246
- const signalingData = JSON . parse ( atob ( data ) ) ;
247
- LOG_P2P_CALL ( '[update] updateNewCallSignalingData' , update , signalingData ) ;
248
- if ( this . p2pCallsEnabled ) {
249
- this . p2pApplyCallSignalingData ( call_id , signalingData ) ;
247
+ const { currentCall } = this ;
248
+ if ( currentCall ) {
249
+ const { encryptor } = currentCall ;
250
+ if ( encryptor ) {
251
+ const decryptedData = encryptor . decryptFromBase64 ( data ) ;
252
+ const signalingData = JSON . parse ( decryptedData ) ;
253
+ // const signalingData = JSON.parse(atob(data));
254
+ LOG_P2P_CALL ( '[update] updateNewCallSignalingData' , update , signalingData ) ;
255
+ if ( this . p2pCallsEnabled ) {
256
+ this . p2pApplyCallSignalingData ( call_id , signalingData ) ;
257
+ }
258
+ }
250
259
}
251
260
} catch ( e ) {
252
261
ERROR_P2P_CALL ( '[update] updateNewSignalingData parse' , update ) ;
@@ -1643,13 +1652,21 @@ class CallStore extends EventEmitter {
1643
1652
} ) ;
1644
1653
}
1645
1654
1646
- p2pSendCallSignalingData ( callId , data ) {
1647
- LOG_P2P_CALL ( '[tdlib] sendCallSignalingData' , callId , data ) ;
1648
- TdLibController . send ( {
1649
- '@type' : 'sendCallSignalingData' ,
1650
- call_id : callId ,
1651
- data : btoa ( data )
1652
- } ) ;
1655
+ p2pSendCallSignalingData ( callId , str ) {
1656
+ LOG_P2P_CALL ( '[tdlib] sendCallSignalingData' , callId , str ) ;
1657
+ const { currentCall } = this ;
1658
+ if ( currentCall ) {
1659
+ const { encryptor } = currentCall ;
1660
+ if ( encryptor ) {
1661
+ const data = encryptor . encryptToBase64 ( str ) ;
1662
+
1663
+ TdLibController . send ( {
1664
+ '@type' : 'sendCallSignalingData' ,
1665
+ call_id : callId ,
1666
+ data
1667
+ } ) ;
1668
+ }
1669
+ }
1653
1670
}
1654
1671
1655
1672
p2pGetConfiguration ( state ) {
@@ -1741,6 +1758,8 @@ class CallStore extends EventEmitter {
1741
1758
if ( ! state ) return ;
1742
1759
if ( state [ '@type' ] !== 'callStateReady' ) return ;
1743
1760
1761
+ const { encryption_key } = state ;
1762
+
1744
1763
const outputStream = new MediaStream ( ) ;
1745
1764
1746
1765
const configuration = this . p2pGetConfiguration ( state ) ;
@@ -1783,7 +1802,8 @@ class CallStore extends EventEmitter {
1783
1802
callId : id ,
1784
1803
connection,
1785
1804
inputStream : null ,
1786
- outputStream
1805
+ outputStream,
1806
+ encryptor : new P2PEncryptor ( encryption_key )
1787
1807
} ;
1788
1808
LOG_P2P_CALL ( 'p2pJoinCall currentCall' , this . currentCall ) ;
1789
1809
0 commit comments