title: Unpublishing a publisher and trying to publish right after not working
body: <p>I am using the tokbox javascript sdk in the browser.
  I am having trouble recreating a publisher. My situation is like this:</p>
  
  <ol>
  <li>I create a publisher which broadcasts audio and video</li>
  <li>At a certain point, I want to switch the audio source, to a different MediaStream source.</li>
  <li>I unpublish the previous publisher on the session and destroy it in the callback</li>
  <li>I try to create a new publisher with this new configuration.</li>
  </ol>
  
  <p>Wheneven I do this I end up with the following error: </p>
  
  <p><code>Session.publish, could not publish in a reasonable amount of time.</code></p>
  
  <p>I've searched on SO and online for some answers. I have ran into people with similar problems like <a href="https://support.tokbox.com/hc/en-us/community/posts/206675776-Camera-switching-issue" rel="nofollow noreferrer">this</a> or <a href="https://stackoverflow.com/questions/38427760/publishing-fails-after-unpublishing/38455689#38455689?newreg=02f223622adf4e43a7a12b8deab5b695">this</a> but neither have answers to this issue.</p>
  
  <p>Basically, I either need to find out how I can alter an existing publisher that is already broadcasting (in terms of audio and video source config), or I am doing something wrong with the lifecycle of the publisher when I am trying to create a new one.</p>
  
  <p>Creating a second publisher while having the first seems to work okay, but first destroying one and then trying to create a new one seems to yield the issue described.</p>
  
  <p>Here is the sample code:</p>
  
  <pre><code>// returns existing publisher
  const existing = selectPublisher(getState()); 
  
  if (existing) {
    session.unpublish(existing);
    existing.destroy();
    console.log('destroyed.');
  }
  
  const publisher = OT.initPublisher(
    'publisher-container',
    finalOptions,
    error =&gt; {
      console.log(error);
    }
  );
  
  session.publish(publisher, error =&gt; {
    console.log(error);
  });
  </code></pre>
  
  <p>Initialisation of the publisher seems to work, it prints <code>undefined</code>.
  The print ends up with:</p>
  
  <pre><code>index.js:2177 OT.Publisher.onPublishingTimeout
  index.js:2177 OT.exception :: title: Unable to Publish (1500) msg: ICEWorkflow
  index.js:2177 1500 "Session.publish :: Could not publish in a reasonable amount of time"
  </code></pre>
  
  <p>I am using the opentok npm client package version 2.14.2</p>
  
  <p>EDIT: </p>
  
  <p>It seems that the problem is caused by the options I was passing into the publisher, the example above works fine if I just use the default options (not pass in any into the publisher).</p>
  
  <p>I am using two <code>MediaStreamTrack</code> objects, one for audio and video, gathered using <code>OT.getUserMedia(options)</code>. It looks like the first time it is working fine, but as soon as I unpublish and republish with the same two <code>MediaStreamTrack</code> objects I run into this issue.</p>
  
  <p>The object I'm passing it look like this (from chrome console):</p>
  
  <p><code>audioSource: MediaStreamTrack {kind: "audio", id: "9414787b-82b9-48c3-99bd-3208b46c2f9f", label: "Built-in Microphone", enabled: true, muted: false, …}
  </code></p>
  
  <p><code>videoSource: MediaStreamTrack {kind: "video", id: "3f20c926-7d0c-4537-8e8d-ef4b22393a58", label: "FaceTime HD Camera", enabled: true, muted: false, …}
  </code></p>