title: Record mic and audio from SIP call using sip.js
body: <p>Good evening Stack Overflow!
  I really need help for a project of mine where I'm using sip.js and a VoIP to make real calls to a phone number.</p>
  
  <p><strong>The Goal</strong></p>
  
  <p>I want to allow the user to record the audio and microphone and save the data on a server (in base64 encoding or as a file). So I after the conversation can hear the conversation again and use it for what ever my purpose (employee training) was. </p>
  
  <p><strong>The Problem</strong></p>
  
  <p>I can't get the sound of the person speaking, which comes through and -HTML tag (working with the sip.js plugin). As of now I haven't found any way to successfully save the sound streaming through this audio tag.</p>
  
  <p><strong>What I've done so far</strong></p>
  
  <p>I've successfully figured out how to record the audio of the microphone using a plugin called <a href="https://github.com/cwilso/AudioRecorder" rel="noreferrer">AudioRecorder</a> which allows me to record the audio through the microphone and saving it. I slightly changed the code so it got saved encoded as base64. This all work as expected, though I only get the audio of my own voice, and not the person I'm talking with.</p>
  
  <p>Because I succeed to record the audio of my own voice I looked into the AudioRecorder plugin and tried to reverse the plugin to record from a audio tag. I found the "createMediaStreamSource" function inside AudioRecorder which I wanted to work with the -tag which did not work (as I suspected, because the -tag in it self isn't a stream (of which i understand).</p>
  
  <p><strong>The Code</strong></p>
  
  <p>I'm basically using the sip.js plugin to establish a call to a phone number by using below code (just using an example, matching my code, because my raw code contains some added values which doesn't need to be showed here):</p>
  
  <pre><code>// Create a user agent called bob, connect, and register to receive invitations.
  var userAgent = new SIP.UA({
    uri: 'bob@example.com',
    wsServers: ['wss://sip-ws.example.com'],
    register: true
  });
  var options = { media: { constraints: { audio: true, video: false }, render: { remote: document.getElementById("audio") } } };
  </code></pre>
  
  <p>Then i use the build in invite function to call a phonenumber, which does the rest. Audio and microphone is now up and running.</p>
  
  <pre><code>userAgent.invite("+4512345678", options);
  </code></pre>
  
  <p>I can now talk with my new best friend Bob. But I can't record other than my own sound as of now.</p>
  
  <p><strong>Whats Next?</strong></p>
  
  <p>I would really like some help to understand how I can record the sound of "Bob" and store it, preferred in the same file as my own voice. If I have to record two separately files and play them synced, I won't mind, but else if preferred.</p>
  
  <p>I know this might just be a call for help without showing anything real code of what I've tried to do it myself, but I have to admit I just fiddled with the code for hours without any good results and now I'm screaming for help.</p>
  
  <p>Thank your all in advance and sorry for the bad grammar and (mis)use of language. </p>