| 47 | |
| 48 | let Callback2; |
| 49 | function ensureCallback2() { |
| 50 | @NativeClass |
| 51 | @Interfaces([org.nativescript.firebase.messaging.FirebaseMessaging.Callback2]) |
| 52 | class Callback2Impl extends java.lang.Object implements org.nativescript.firebase.messaging.FirebaseMessaging.Callback2<string, com.google.firebase.messaging.RemoteMessage> { |
| 53 | _owner: WeakRef<MessagingCore>; |
| 54 | _propName: string; |
| 55 | constructor() { |
| 56 | super(); |
| 57 | return global.__native(this); |
| 58 | } |
| 59 | |
| 60 | public onError(error: any): void {} |
| 61 | |
| 62 | public onSuccess(message: string, remoteMessage: com.google.firebase.messaging.RemoteMessage): void { |
| 63 | const callback = this._owner?.get?.()?.[this._propName]; |
| 64 | if (typeof callback === 'function') { |
| 65 | if (this._propName === '_onToken') { |
| 66 | callback(message); |
| 67 | } else if (this._propName === '_onNotificationTap' || this._propName === '_onMessage') { |
| 68 | try { |
| 69 | setTimeout(() => { |
| 70 | callback(JSON.parse(message), remoteMessage); |
| 71 | }); |
| 72 | } catch (e) { |
| 73 | // ignore |
| 74 | } |
| 75 | } else { |
| 76 | try { |
| 77 | callback(JSON.parse(message), remoteMessage); |
| 78 | } catch (e) { |
| 79 | // ignore |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | Callback2 = Callback2Impl; |
| 87 | } |
| 88 | |
| 89 | const onMessageCallbacks: Set<(message: any, nativeMessage: any) => void> = new Set(); |
| 90 | const onTokenCallbacks: Set<(token: any) => void> = new Set(); |