WebsiteBeaver / CordovaCall

Cordova CallKit & ConnectionService plugin for iOS/Android that displays the native call UI for VOIP apps
MIT License
196 stars 91 forks source link

off('event') or unsubscribe #23

Closed HugoHeneault closed 6 years ago

HugoHeneault commented 6 years ago

I'm receiving different calls by push notification, with different params for each of them:

     pushObject.on('notification').subscribe((data: any) => {
          cordova.plugins.CordovaCall.receiveCall(data.additionalData.username);

          cordova.plugins.CordovaCall.on('answer', () => {
              this.handleDeeplink(data);
          });
      });

As I'm setting the CordovaCall.on('answer') at every push reception, I need to unbind it before setting it again. But I don't think there is a off() method.

Or maybe there is another way of handling it?

Thanks!

D-Marc1 commented 6 years ago

I'm confused why the event handler cordova.plugins.CordovaCall.on('answer') is inside of your push notification handler. Nesting event handlers is generally not a good idea.

dmarcs commented 6 years ago

@D-Marc1 is right. Your code should look like this:

pushObject.on('notification').subscribe((data: any) => {
   cordova.plugins.CordovaCall.receiveCall(data.additionalData.username);
});

cordova.plugins.CordovaCall.on('answer', () => {
     this.handleDeeplink();
});

That being said, I do think that we should implement an off method in a future release.