From 240feba76babb715dc08cb9c3f1fe3cea6447b9a Mon Sep 17 00:00:00 2001 From: Tim Brust Date: Fri, 3 Jan 2020 18:40:11 +0000 Subject: [PATCH] fix(in-app-browser): adds missing customscheme type (#3276) it also adds an overload to the `on` function to pass a generic string to support custom events. --- .../plugins/in-app-browser/index.ts | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/@ionic-native/plugins/in-app-browser/index.ts b/src/@ionic-native/plugins/in-app-browser/index.ts index f2f3549aec..50e2654d42 100644 --- a/src/@ionic-native/plugins/in-app-browser/index.ts +++ b/src/@ionic-native/plugins/in-app-browser/index.ts @@ -123,11 +123,11 @@ export interface InAppBrowserOptions { [key: string]: any; } -export type InAppBrowserEventType = 'loadstart' | 'loadstop' | 'loaderror' | 'exit' | 'beforeload' | 'message'; +export type InAppBrowserEventType = 'loadstart' | 'loadstop' | 'loaderror' | 'exit' | 'beforeload' | 'message' | 'customscheme'; export interface InAppBrowserEvent extends Event { /** the event name */ - type: InAppBrowserEventType; + type: string; /** the URL that was loaded. */ url: string; /** the error code, only in the case of loaderror. */ @@ -248,6 +248,28 @@ export class InAppBrowserObject { } ); } + + /** + * A method that allows you to listen to events happening in the browser. + * @param event {string} Name of the event + * @returns {Observable} Returns back an observable that will listen to the event on subscribe, and will stop listening to the event on unsubscribe. + */ + @InstanceCheck() + on(event: string): Observable { + return new Observable( + (observer: Observer) => { + this._objectInstance.addEventListener( + event, + observer.next.bind(observer) + ); + return () => + this._objectInstance.removeEventListener( + event, + observer.next.bind(observer) + ); + } + ); + } } /**