From 324334eb287dd8e3e82b2d5d64e8fb06b496a1f0 Mon Sep 17 00:00:00 2001 From: bsorrentino Date: Thu, 11 Jun 2020 18:08:35 +0200 Subject: [PATCH] feat(broadcaster): align plugin API to version 4.1.0 (#3432) --- .../plugins/broadcaster/index.ts | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/@ionic-native/plugins/broadcaster/index.ts b/src/@ionic-native/plugins/broadcaster/index.ts index affe3ef3d5..5f41935882 100644 --- a/src/@ionic-native/plugins/broadcaster/index.ts +++ b/src/@ionic-native/plugins/broadcaster/index.ts @@ -2,6 +2,20 @@ import { Injectable } from '@angular/core'; import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; import { Observable } from 'rxjs'; +/** + * Specific data for Android implementation + */ +export interface AndroidData { + extras: object; + flags: number; + category: string; +} + +/** + * Possibly Event Data types + */ +export type EventData = object | AndroidData | null; + /** * @name Broadcaster * @description @@ -35,6 +49,7 @@ export class Broadcaster extends IonicNativePlugin { /** * This function listen to an event sent from the native code * @param {string} eventName + * @param {boolean} isGlobal Valid only for Android. It allows to listen for global messages(i.e. intents) * @return {Observable} Returns an observable to watch when an event is received */ @Cordova({ @@ -42,18 +57,22 @@ export class Broadcaster extends IonicNativePlugin { clearFunction: 'removeEventListener', clearWithArgs: true, }) - addEventListener(eventName: string): Observable { + addEventListener(eventName: string, isGlobal = false): Observable { return; } /** * This function sends data to the native code * @param {string} eventName - * @param {any} eventData + * @param {boolean} isGlobalOrEventData means that message is global (valid only on Android) + * @param {AndroidData} isGlobalOrEventData allows to specify 'flags` and 'category' (valid only on Android) + * @param {object} isGlobalOrEventData allows to specify a generic object containing custom event data (all platform) + * @param {AndroidData} [data] if isGlobal is set, allows to specify 'flags` and 'category' if isGlobal is set (valid only on Android) + * @param {object} [data] if isGlobal is set, allows to specify a generic object containing custom event data (all platform) * @return {Promise} Returns a promise that resolves when an event is successfully fired */ @Cordova() - fireNativeEvent(eventName: string, eventData: any): Promise { + fireNativeEvent(eventName: string, isGlobalOrEventData: boolean | EventData, data?: EventData): Promise { return; } }