js-calls-part-1-index-js-make-call

Home   »   js-calls-part-1-index-js-make-call

/**
* Make a call to other user
*/
function makeCall() {
   /**
    * Ask user_id to call to
    */
   const userId = prompt("ENTER USER TO CALL");
   if (!userId) {
       return;
   }
   /**
    * Set dialing parameters
    */
   const dialParams = {
       userId,
       isVideoCall: true,
       callOption: {
           localMediaView: document.getElementById(
               'local_video_element_id'),
           remoteMediaView: document.getElementById(
               'remote_video_element_id'),
           videoEnabled: true,
           audioEnabled: true
       }
   };
   /**
    * Make the call
    */
   const call = SendBirdCall.dial(dialParams, (call, error) => {
       if (error) {
           console.dir(error);
           alert('Dial Failed!');
       } else {
           console.log('Dial Success');
       }   
   });   
   /**
    * Once the call is established,
    * run this logic
    */
   call.onEstablished = (call) => {
       console.log('onEstablished');
       currentCall = call; 
       // Hide / Show some buttons
       document.getElementById('butMakeCall').style.display = 'none';
       document.getElementById('butEndCall').style.display = 'inline-block';
   };
   /**
    * Once the call is connected,
    * run this logic
    */
   call.onConnected = (call) => {
       console.log('onConnected');
   };
   /**
    * Once the call ended,
    * run this logic
    */
   call.onEnded = (call) => {
       console.log('onEnded');
       currentCall = null;
       // Hide / Show some buttons
       document.getElementById('butMakeCall').style.display = 'inline-block';
       document.getElementById('butEndCall').style.display = 'none';
   };   
   /**
    * Remote user changed audio settings
    * (analysys not covered in this tutorial)
    */
   call.onRemoteAudioSettingsChanged = (call) => {
       console.log('Remote user changed audio settings');
   };   
   /**
    * Remote user changed audio settings
    * (analysys not covered in this tutorial)
    */
    call.onRemoteVideoSettingsChanged = (call) => {
       console.log('Remote user changed video settings');
   };
}

Leave a Reply

Your email address will not be published. Required fields are marked *