Guest User

Untitled

a guest
Jun 17th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.      
  2.       //...
  3.       //Payload is received from the websockets server
  4.       const {data} = payload;
  5.  
  6.       if (data.sdp) {
  7.         await peerConnection.setRemoteDescription(data.sdp);
  8.  
  9.         if (data.sdp.type === 'offer') {
  10.           const answer = await peerConnection.createAnswer();
  11.           await peerConnection.setLocalDescription(answer);
  12.  
  13.           const answerPayload = {
  14.             sdp: answer,
  15.             chat: chatId,
  16.           };
  17.  
  18.           chat.signaling(answerPayload, chatId);
  19.         }
  20.       } else if (data.ice) {
  21.         await peerConnection.addIceCandidate(data.ice);
  22.       }
  23.       //...
  24.  
  25.  
  26.  
  27.  
  28.       //When the user presses on the call button
  29.       if (isCaller) {
  30.         const offer = await peerConnection.createOffer();
  31.         await peerConnection.setLocalDescription(offer);
  32.  
  33.         const payload = {
  34.           sdp: offer,
  35.           chat: chatId,
  36.         };
  37.         //Send the payload to the server
  38.       }
Advertisement
Add Comment
Please, Sign In to add comment