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

initPublisher creates a publisher object but does not intialize camera #160

Open ehassaan opened 5 years ago

ehassaan commented 5 years ago

Bug Report

initPublisher creates a publisher object but does not intialize camera

screenshot_1550508150

Calling the initPublisher('publisherId') function does create a publisher object but it does not initialize the camera and neither asks camera or sound permission. The publisher div shows either black screen or a placeholder image. Surprisingly when using cordova debugger in ionic sample, stepping over the code causes the initPublisher to work perfectly.

Steps to reproduce

Download opentok-ionic-sample (or opentok-cordova-sample) Edit the code to add apiKey, sessionId and token run npm install ionic cordova platform add android ionic cordova run android

cordova-android: "^7.1.4" cordova-plugin-opentok: ^3.4.3 Android Device: Xiamo A1, Android 9 Node LTS v10.15.1 Also tested on emulator Android 7.0

msach22 commented 5 years ago

Thanks for filing the issue @HassaanAkbar! I've also answered the question here: https://stackoverflow.com/questions/54751291/initpublisher-creates-a-publisher-object-but-does-not-initialize-camera/54755174#54755174

I'll update you as we make progress 😄

ehassaan commented 5 years ago

Thanks @msach22 But i think the issue is not just related to permissions. I just created two buttons. One for initializing publisher and one for connecting session and start publishing. I gave all the permissions from the phone settings. Still the publisher isn't able to initializing. It just shows a placeholder image like before.

screenshot_20190219-031223 I

InitTB is called in constructor.


  initTB() {

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

    OT.addEventListener('exception', function (e) {
      console.log("----EXCEPTION: ", e.message);
      this.error = e.message;
    });

    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();
      }
    });
  }
 initPublisher() {
    this.publisher = OT.initPublisher('publisherDiv');
  }
  startPublish() {

    this.session.connect(this.token, (error) => {
      console.log("connect error:", error);
      console.log("publisher:", this.publisher);
      this.session.publish(this.publisher);
    });
  }
msach22 commented 5 years ago

@HassaanAkbar If you check the Android code - you will see that the native publisher is initialized, but the view is not super-imposed on the DOM element until the publish method is called: https://github.com/opentok/cordova-plugin-opentok/blob/master/src/android/OpenTokAndroidPlugin.java#L243

alaghusun60 commented 5 years ago

@msach22 any solution for this issue

msach22 commented 5 years ago

@alaghusun60 I have a fix locally for this where the permissions are requested when the initPublisher is called and not when publish is called.

gutierre69 commented 5 years ago

Hi, I found a simple solution change this: for this:

msach22 commented 5 years ago

@gutierre69 using the CDN link would mean that you're using the OpenTok JS SDK and not the Cordova plugin.

kerloom commented 5 years ago

@alaghusun60 I have a fix locally for this where the permissions are requested when the initPublisher is called and not when publish is called.

@msach22 Could you please share the local fix code? I managed to make it work the first time. But when I repaeat a call, the camara seems to not initialize.

kerloom commented 5 years ago

@msach22 Do you have any update?

Thanks!

msach22 commented 5 years ago

Sorry folks, I'm not longer maintaining this project at this time so I'm unable to help here.