import SimplePeer from 'simple-peer' ; import createDesktopCapturerStream from './createDesktopCapturerStream' ; import handlePeerOnData from './handlePeerOnData' ; import Logger from '../../utils/LoggerWithFilePrefix' ; import NullSimplePeer from './NullSimplePeer' ; import simplePeerHandleSdpTransform from './simplePeerHandleSdpTransform' ; const log = new Logger ( __filename ) ; export default function handleCreatePeer ( peerConnection ) { return new Promise ( ( resolve , reject ) => { createDesktopCapturerStream ( peerConnection , peerConnection . desktopCapturerSourceID ) . then ( ( ) => { if ( peerConnection . peer === NullSimplePeer ) { peerConnection . peer = new SimplePeer ( { initiator : true , config : { iceServers : [ ] } , sdpTransform : simplePeerHandleSdpTransform , } ) ; } if ( peerConnection . localStream !== null ) { peerConnection . peer . addStream ( peerConnection . localStream ) ; } peerConnection . peer . on ( 'signal' , ( data ) => { peerConnection . signalsDataToCallUser . push ( data ) ; } ) ; peerConnection . peer . on ( 'data' , ( data ) => { handlePeerOnData ( peerConnection , data ) ; } ) ; resolve ( undefined ) ; } ) . catch ( ( e ) => { log . error ( e ) ; reject ( ) ; } ) ; } ) ; }