opentok / cordova-plugin-opentok

Cordova Plugin for OpenTok - add webrtc video to your iOS or Android App
MIT License
30 stars 80 forks source link

streamCreated not firing when publishing from iOS #138

Closed IvoPelayo closed 5 years ago

IvoPelayo commented 5 years ago

Bug Report

Current behavior I have a Ionic 3 app that uses cordova-opentok-plugin, and a webapp using opentok.js. I am able to see both videos on the ionic app, but on the webapp the 'streamCreated' event its never fired, so i´m only seeing the web publishers video

What is the current bug behavior? streamCreated event not firing

IvoPelayo commented 5 years ago

the solution is to remove all the callback functions on subscribe or publish methods. The only method that accepts callback properly is session.connect()

totiherms commented 5 years ago

I'm having the same issue, can you tell me how you solved this? It was working with ios11, but now on ios12 seems broked.

Using the provided samples from opentok also is working on android but not in ios.

msach22 commented 5 years ago

@totiherms Can you please share your code so we can see how you're setting the event listeners?

totiherms commented 5 years ago

@msach22 the code:

`this.session = OT.initSession(this.api, this.sessionId);

    this.session.connect(this.token, () => {
        this.showMessage("Conectado correctamente");
        this.connected = true;
        this.infoStr = "Espere al interlocutor";

        this.publisher = OT.initPublisher('publisher', (error) => {
          if (error) {
            let alert = this.alertCtrl.create({
              title: 'Error',
              subTitle: error,
              buttons: [{
                text: 'Ok',
                handler: data => {
                  this.navCtrl.pop();
                }
              }]
            });
            alert.present();
            console.log(error);
            return;
          }
        });
        this.session.publish(this.publisher, (error)=>{
            alert(error);
        });
    });

    this.session.on({
      streamCreated: (event) => {
        console.log("stream created");
        var subscriberOptions = { fitMode: "contain",insertMode: 'append',width: '100%',height: '100%' };
        this.session.subscribe(event.stream, 'subscriber',subscriberOptions);
        OT.updateViews();
      },
      streamDestroyed: (event) => {
        console.log("stream destroyed");
        console.log('Stream ${event.stream.name} ended because ${event.reason}');
        OT.updateViews();        
      },
      connectionCreated: (event) => {
        if (event.connection.connectionId != this.session.connection.connectionId) {
          this.showMessage("Se ha conectado un usuario");
          this.infoStr="";
            //console.log('Another client connected. ' + connectionCount + ' total.');
            //$('#currentConnections').html("Actualment hi han " + connectionCount + " usuaris connectats");
        }else{

        }
    },
    });`

the code from https://github.com/opentok/opentok-ionic-samples also has the same issue:

`this.session = OT.initSession(this.apiKey, this.sessionId);

this.session.on({
  streamCreated: (event) => {
    this.session.subscribe(event.stream, 'subscriber');
    OT.updateViews();
  },
  streamDestroyed: (event) => {
    console.log(`Stream ${event.stream.name} ended because ${event.reason}`);
    OT.updateViews();        
  }
});

this.session.connect(this.token, () => {
  this.publisher = OT.initPublisher('publisher');
  this.session.publish(this.publisher);
});`
totiherms commented 5 years ago

can also be related to: https://github.com/opentok/opentok-ionic-samples/issues/30

msach22 commented 5 years ago

@totiherms Thanks for sharing. I just ran some code and was able to publish without any issues. Here's what I recommend:

You can do it like so:

this.publisher = OT.initPublisher('publisher')
this.session.on({
  streamCreated: (event) => {
    this.session.subscribe(event.stream, 'subscriber');
  },
  streamDestroyed: (event) => {
    console.log(`Stream ${event.stream.name} ended because ${event.reason}`);
  },
 sessionConnected: event => {
    this.session.publish(publisher);
  },
});

this.session.connect(this.token, (error) => {
   if (error) {
      console.log('There was an error connecting');
   }
});

It looks like there's an issue that's been filed that's related to this: https://github.com/opentok/opentok-ionic-samples/issues/31

totiherms commented 5 years ago

@msach22 thanks! it's working now

juniordevs commented 5 years ago

You guy save my life. Thank you @msach22

msach22 commented 5 years ago

Happy to help @juniordevs! 😄