2

I am using the tokbox javascript sdk in the browser. I am having trouble recreating a publisher. My situation is like this:

  1. I create a publisher which broadcasts audio and video
  2. At a certain point, I want to switch the audio source, to a different MediaStream source.
  3. I unpublish the previous publisher on the session and destroy it in the callback
  4. I try to create a new publisher with this new configuration.

Wheneven I do this I end up with the following error:

Session.publish, could not publish in a reasonable amount of time.

I've searched on SO and online for some answers. I have ran into people with similar problems like this or this but neither have answers to this issue.

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.

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.

Here is the sample 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 => {
    console.log(error);
  }
);

session.publish(publisher, error => {
  console.log(error);
});

Initialisation of the publisher seems to work, it prints undefined. The print ends up with:

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"

I am using the opentok npm client package version 2.14.2

EDIT:

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).

I am using two MediaStreamTrack objects, one for audio and video, gathered using OT.getUserMedia(options). It looks like the first time it is working fine, but as soon as I unpublish and republish with the same two MediaStreamTrack objects I run into this issue.

The object I'm passing it look like this (from chrome console):

audioSource: MediaStreamTrack {kind: "audio", id: "9414787b-82b9-48c3-99bd-3208b46c2f9f", label: "Built-in Microphone", enabled: true, muted: false, …}

videoSource: MediaStreamTrack {kind: "video", id: "3f20c926-7d0c-4537-8e8d-ef4b22393a58", label: "FaceTime HD Camera", enabled: true, muted: false, …}

Bob
  • 127
  • 1
  • 14
  • Bob, could you please provide the following: - Sample Code that you're using - The version of the OpenTok JS SDK - The browser that you're using – Manik May 14 '18 at 15:50
  • I updated the original post with the information you asked for. – Bob May 14 '18 at 17:13
  • Bob, can you please upgrade to the 2.14.2 SDK and see if you're still having the issue? Also, can you please tell me which browser you're using? Lastly, can you add the error handlers for when you create the publisher and call publish? This way we can see what the error handler comes back with. – Manik May 15 '18 at 16:40
  • I upgraded the package to 2.14.2 but it seems like I'm still having the issue. I tested in in chrome, version 66.0.3359.139. I also added the error handler, and it returns with the exact same error as I described above, I will add it to the original post. – Bob May 15 '18 at 19:32
  • Looks like I am having the same issue on firefox and even safari, I am using mac OSX by the way. – Bob May 15 '18 at 19:48
  • I tried something very similar and am not getting any issues. Can you try this codepen? https://codepen.io/anon/pen/erzxYr?editors=1000#0 Remember to add your credentials – Manik May 16 '18 at 16:58
  • Hey Manik, I tried these suggestions, and with a bit of work I found out that the problem is caused by the options I am passing. I will update the original post again. – Bob May 18 '18 at 17:27

1 Answers1

4

TokBox Developer Evangelist here.

When you destroy the publisher, we call the stop method on the MediaStreamTrack which is why you're unable to use the same MediaStreamTrack options again. To prevent this from happening, call the clone method on the MediaStreamTrack and pass in the clone as the options when you initialize the publisher.

Manik
  • 1,495
  • 11
  • 19