From c3de8dfaba158c7f5726bcfd67481c7525375450 Mon Sep 17 00:00:00 2001 From: Eric Horodyski Date: Fri, 4 Jan 2019 16:06:52 -0500 Subject: [PATCH] feat(baidu-push): add plugin (#2838) * Initial push. * Revert tslint.json and switch imports around to be alphabetical. * Remove non-used plugins to decrease build time. * Finish the BaiduPush interface. * Add observables. * Restore other plugins. * Restore file formatting. * Update documentation. * Update index.ts --- src/@ionic-native/plugins/baidu-push/index.ts | 187 ++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 src/@ionic-native/plugins/baidu-push/index.ts diff --git a/src/@ionic-native/plugins/baidu-push/index.ts b/src/@ionic-native/plugins/baidu-push/index.ts new file mode 100644 index 000000000..eb0cbe32e --- /dev/null +++ b/src/@ionic-native/plugins/baidu-push/index.ts @@ -0,0 +1,187 @@ +import { Injectable } from '@angular/core'; +import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; +import { Observable } from 'rxjs/Observable'; + +declare const baiduPush: any; + +export interface BaiduResponse { + /** + * The corresponding Baidu SDK method called. + */ + type: string; + /** + * The error code corresponding to Baidu's request. + */ + errorCode?: string; + /** + * Registration data revelvant to subsequent actions. + */ + data: T; +} + +export interface RegistrationData { + /** + * The ID registered to Baidu for the app. + */ + appId: string; + /** + * The ID registered to Baidu for the device. + */ + userId: string; + /** + * The channel ID registered to Baidu for the app. + */ + channelId: string; +} + +export interface UnregistrationData { + /** + * The ID corresponding to the Baidu request. + */ + requestId: string; +} + +export interface TagData { + /** + * The ID corresponding to the Baidu request. + */ + requestId: string; + /** + * The channel ID registered to Baidu for the app. + */ + channelId: string; + /** + * The list of successfully set/deleted tags. + */ + sucessTags: string[]; + /** + * The list of unsuccessfully set/deleted tags. + */ + failTags: string[]; +} + +export interface NotificationData { + /** + * The title of the notification. + */ + title: string; + /** + * The description of the notification. + */ + description: string; + /** + * Custom content for the notification. + */ + customContentString?: string; +} + +/** + * @name Baidu Push + * @description + * This plugin faciliates the use of Baidu Push notifications. + * + * @usage + * ```typescript + * import { BaiduPush } from '@ionic-native/baidu-push'; + * + * + * constructor(private baiduPush: BaiduPush) { } + * + * ... + * + * this.baiduPush.startWork('xxxxxx') + * .then((res: any) => console.log(res)) + * .catch((error: any) => console.error(error)); + * + * ``` + * @interfaces + * BaiduResponse + * RegistrationData + * UnregistrationData + * TagData + * NotificationData + */ +@Plugin({ + pluginName: 'BaiduPush', + plugin: 'cordova-plugin-push-baidu', + pluginRef: 'baiduPush', + repo: 'https://github.com/Ti-webdev/cordova-plugin-push-baidu.git', + platforms: ['Android', 'iOS'] +}) +@Injectable() +export class BaiduPush extends IonicNativePlugin { + /** + * This method registers the device to Baidu Cloud Push services. + * @param {string} apiKey Baidu Cloud Push API key. + * @return {Promise>} Returns a Promise that resolves with a BaiduResponse. + */ + @Cordova() + startWork(apiKey: string): Promise> { + return; + } + + /** + * This method unregisters the device to Baidu Cloud Push services. + * @return {Promise>} Returns a Promise that resolves with a BaiduResponse. + */ + @Cordova() + stopWork(): Promise> { + return; + } + + /** + * This method re-binds the device to Baidu Cloud Push services. + * @return {Promise>} Returns a Promise that resolves with a BaiduResponse. + */ + @Cordova() + resumeWork(): Promise> { + return; + } + + /** + * This sets tags in the Baidu Cloud Push services. + * @param tags {any} tags The tags to set. + * @return {Promise>} Returns a Promise that resolves with a BaiduResponse. + */ + @Cordova() + setTags(tags: any): Promise> { + return; + } + + /** + * This sets tags in the Baidu Cloud Push services. + * @param tags {any} tags The tags to set. + * @return {Promise>} Returns a Promise that resolves with a BaiduResponse. + */ + @Cordova() + delTags(tags: any): Promise> { + return; + } + + /** + * This method is called when a notification is recieved on the foreground. + * @return {Promise>} Returns a Promise that resolves with a BaiduResponse. + */ + @Cordova({ observable: true }) + onMessage(): Observable> { + return; + } + + /** + * This method is called when the user taps a notification. + * @return {Promise>} Returns a Promise that resolves with a BaiduResponse. + */ + @Cordova({ observable: true }) + onNotificationClicked(): Observable> { + return; + } + + /** + * This method is called when a notification is recieved. + * @return {Promise>} Returns a Promise that resolves with a BaiduResponse. + */ + @Cordova({ observable: true }) + onNotificationArrived(): Observable> { + return; + } +}