Search code examples
ioscordovaionic4opentok

How to fix Publisher error in Opentok Cordova Plugin for iOS?


I am using cordova-plugin-opentok with Ionic 4, and I have a problem with iOS. The session connects correctly, but when I publish my video stream, It throws this error

"iOS Publish stream to session [ERROR] otk_session_private.cpp:3165 - Bad loop or already in a disconnecting/error state"

I have tried changing the Publisher parameters, but the error is still there.

let session;
let publisher;

session = OT.initSession(this.apiKEY, this.sessionID);

session.on('streamCreated', function(event) {
  session.subscribe(event.stream, 'subscriber', {
    insertMode: 'append',
    width: '100%',
    height: '100%'
  });
  OT.updateViews();
});

session.connect(this.token, function(error) {
  if (!error) {
    publisher = OT.initPublisher('publisher');
    session.publish(publisher, (error) => {
        if(error){
          console.log("Publisher error: " + error);
        }
        OT.updateViews();
    });
  } else {
    console.log("Error connecting: ", error.name, error.message);
  }
});

Solution

  • In case anyone finds this, since it is the only mention of this error on the internet, I was getting this error on C SDK. It turned out I was calling otc_init again by accident after creating the session and publisher. Silly mistake.