Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

streamCreated not firing when publishing from iOS #138

Closed
IvoPelayo opened this issue Dec 12, 2018 · 9 comments
Closed

streamCreated not firing when publishing from iOS #138

IvoPelayo opened this issue Dec 12, 2018 · 9 comments

Comments

@IvoPelayo
Copy link

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
Copy link
Author

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
Copy link

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
Copy link

msach22 commented Feb 21, 2019

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

@totiherms
Copy link

@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
Copy link

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

@msach22
Copy link

msach22 commented Feb 21, 2019

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

  • You publish when you receive the sessionConnected event

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
Copy link

@msach22 thanks! it's working now

@juniordevs
Copy link

You guy save my life.
Thank you @msach22

@msach22
Copy link

msach22 commented Mar 26, 2019

Happy to help @juniordevs! 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants