Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(broadcaster): align plugin API to version 4.1.0 #3432

Merged
merged 2 commits into from
Jun 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/@ionic-native/plugins/broadcaster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,25 +49,30 @@ 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<any>} Returns an observable to watch when an event is received
*/
@Cordova({
observable: true,
clearFunction: 'removeEventListener',
clearWithArgs: true,
})
addEventListener(eventName: string): Observable<any> {
addEventListener(eventName: string, isGlobal = false): Observable<any> {
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<any>} Returns a promise that resolves when an event is successfully fired
*/
@Cordova()
fireNativeEvent(eventName: string, eventData: any): Promise<any> {
fireNativeEvent(eventName: string, isGlobalOrEventData: boolean | EventData, data?: EventData): Promise<any> {
return;
}
}