@onekeyfe/react-native-jpush 0.0.0-stage → 6.7.0-alpha.435
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +23 -2
- package/ReactNativeJpush.podspec +66 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +143 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +143 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/cn/android/service/JTransitActivity.java +19 -0
- package/android/src/main/java/cn/jiguang/android/BuildConfig.java +10 -0
- package/android/src/main/java/cn/jiguang/android/IDataShare.java +190 -0
- package/android/src/main/java/cn/jiguang/api/BaseLogger.java +82 -0
- package/android/src/main/java/cn/jiguang/api/JAction.java +22 -0
- package/android/src/main/java/cn/jiguang/api/JActionExtra.java +21 -0
- package/android/src/main/java/cn/jiguang/api/JAnalyticsAction.java +11 -0
- package/android/src/main/java/cn/jiguang/api/JCoreInterface.java +228 -0
- package/android/src/main/java/cn/jiguang/api/JCoreManager.java +156 -0
- package/android/src/main/java/cn/jiguang/api/JDispatchAction.java +66 -0
- package/android/src/main/java/cn/jiguang/api/MultiSpHelper.java +114 -0
- package/android/src/main/java/cn/jiguang/api/ReportCallBack.java +9 -0
- package/android/src/main/java/cn/jiguang/api/SdkType.java +13 -0
- package/android/src/main/java/cn/jiguang/api/utils/JCollectionAuth.java +23 -0
- package/android/src/main/java/cn/jiguang/core/JCoreCrypto.java +545 -0
- package/android/src/main/java/cn/jiguang/core/JCoreStorage.java +737 -0
- package/android/src/main/java/cn/jiguang/core/JCoreTcpEngine.java +1394 -0
- package/android/src/main/java/cn/jiguang/core/JCoreWireCodec.java +1716 -0
- package/android/src/main/java/cn/jiguang/internal/ActionManager.java +63 -0
- package/android/src/main/java/cn/jiguang/internal/JConstants.java +61 -0
- package/android/src/main/java/cn/jiguang/internal/JCoreHelperAction.java +12 -0
- package/android/src/main/java/cn/jiguang/internal/JCoreInternalHelper.java +102 -0
- package/android/src/main/java/cn/jiguang/net/DefaultHostVerifier.java +40 -0
- package/android/src/main/java/cn/jiguang/net/HttpRequest.java +78 -0
- package/android/src/main/java/cn/jiguang/net/HttpResponse.java +48 -0
- package/android/src/main/java/cn/jiguang/net/HttpUtils.java +106 -0
- package/android/src/main/java/cn/jiguang/plugins/core/JCoreModule.java +91 -0
- package/android/src/main/java/cn/jiguang/plugins/core/JCorePackage.java +27 -0
- package/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +773 -0
- package/android/src/main/java/cn/jiguang/plugins/push/JPushPackage.java +25 -0
- package/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java +88 -0
- package/android/src/main/java/cn/jiguang/plugins/push/common/JLogger.java +122 -0
- package/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java +710 -0
- package/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushBroadcastReceiver.java +37 -0
- package/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java +264 -0
- package/android/src/main/java/cn/jiguang/plugins/service/JCoreModuleService.java +7 -0
- package/android/src/main/java/cn/jpush/android/api/BasicPushNotificationBuilder.java +83 -0
- package/android/src/main/java/cn/jpush/android/api/CallBackParams.java +50 -0
- package/android/src/main/java/cn/jpush/android/api/CmdMessage.java +33 -0
- package/android/src/main/java/cn/jpush/android/api/CustomMessage.java +28 -0
- package/android/src/main/java/cn/jpush/android/api/CustomPushNotificationBuilder.java +81 -0
- package/android/src/main/java/cn/jpush/android/api/DefaultPushNotificationBuilder.java +90 -0
- package/android/src/main/java/cn/jpush/android/api/InAppSlotParams.java +65 -0
- package/android/src/main/java/cn/jpush/android/api/InstrumentedActivity.java +17 -0
- package/android/src/main/java/cn/jpush/android/api/InstrumentedListActivity.java +17 -0
- package/android/src/main/java/cn/jpush/android/api/JPushInterface.java +488 -0
- package/android/src/main/java/cn/jpush/android/api/JPushMessage.java +121 -0
- package/android/src/main/java/cn/jpush/android/api/JThirdPlatFormInterface.java +147 -0
- package/android/src/main/java/cn/jpush/android/api/MultiActionsNotificationBuilder.java +72 -0
- package/android/src/main/java/cn/jpush/android/api/NotificationCustomButton.java +50 -0
- package/android/src/main/java/cn/jpush/android/api/NotificationMessage.java +67 -0
- package/android/src/main/java/cn/jpush/android/api/PushNotificationBuilder.java +13 -0
- package/android/src/main/java/cn/jpush/android/api/TagAliasCallback.java +8 -0
- package/android/src/main/java/cn/jpush/android/data/JPushCollectControl.java +96 -0
- package/android/src/main/java/cn/jpush/android/data/JPushConfig.java +79 -0
- package/android/src/main/java/cn/jpush/android/data/JPushConfigEx.java +41 -0
- package/android/src/main/java/cn/jpush/android/data/JPushLocalNotification.java +155 -0
- package/android/src/main/java/cn/jpush/android/helper/JCoreHelper.java +70 -0
- package/android/src/main/java/cn/jpush/android/helper/Logger.java +82 -0
- package/android/src/main/java/cn/jpush/android/local/ActionHelper.java +1198 -0
- package/android/src/main/java/cn/jpush/android/local/ActivityLifeCallBack.java +47 -0
- package/android/src/main/java/cn/jpush/android/local/JPushAction.java +67 -0
- package/android/src/main/java/cn/jpush/android/local/JPushConstants.java +34 -0
- package/android/src/main/java/cn/jpush/android/local/JPushResponse.java +26 -0
- package/android/src/main/java/cn/jpush/android/local/ProxyActivityAction.java +34 -0
- package/android/src/main/java/cn/jpush/android/service/AlarmReceiver.java +15 -0
- package/android/src/main/java/cn/jpush/android/service/BActivity.java +19 -0
- package/android/src/main/java/cn/jpush/android/service/DActivity.java +19 -0
- package/android/src/main/java/cn/jpush/android/service/DaemonService.java +17 -0
- package/android/src/main/java/cn/jpush/android/service/DataProvider.java +136 -0
- package/android/src/main/java/cn/jpush/android/service/DataShare.java +129 -0
- package/android/src/main/java/cn/jpush/android/service/DownloadProvider.java +139 -0
- package/android/src/main/java/cn/jpush/android/service/InitProvider.java +48 -0
- package/android/src/main/java/cn/jpush/android/service/JCommonService.java +79 -0
- package/android/src/main/java/cn/jpush/android/service/JNotifyActivity.java +28 -0
- package/android/src/main/java/cn/jpush/android/service/JPushMessageReceiver.java +93 -0
- package/android/src/main/java/cn/jpush/android/service/PushReceiver.java +26 -0
- package/android/src/main/java/cn/jpush/android/service/PushService.java +28 -0
- package/android/src/main/java/cn/jpush/android/service/SchedulerReceiver.java +17 -0
- package/android/src/main/java/cn/jpush/android/service/TagAliasReceiver.java +11 -0
- package/android/src/main/java/cn/jpush/android/service/WakedResultReceiver.java +24 -0
- package/android/src/main/java/cn/jpush/android/ui/FullScreenView.java +11 -0
- package/android/src/main/java/cn/jpush/android/ui/PopWinActivity.java +16 -0
- package/android/src/main/java/cn/jpush/android/ui/PushActivity.java +27 -0
- package/android/src/main/java/cn/jpush/android/ui/RoundedImageView.java +63 -0
- package/android/src/main/java/cn/jpush/android/ui/ShadowViewCard.java +56 -0
- package/android/src/main/java/cn/jpush/android/ups/ICallbackResult.java +5 -0
- package/android/src/main/java/cn/jpush/android/ups/JPushUPSManager.java +37 -0
- package/android/src/main/java/cn/jpush/android/ups/TokenResult.java +47 -0
- package/android/src/main/java/cn/jpush/android/ups/UPSRegisterCallBack.java +4 -0
- package/android/src/main/java/cn/jpush/android/ups/UPSTurnCallBack.java +4 -0
- package/android/src/main/java/cn/jpush/android/ups/UPSUnRegisterCallBack.java +4 -0
- package/android/src/main/java/com/margelo/nitro/reactnativejpush/ReactNativeJpush.kt +455 -0
- package/android/src/main/java/com/margelo/nitro/reactnativejpush/ReactNativeJpushPackage.kt +50 -0
- package/android/src/main/res/values/jpush_string.xml +7 -0
- package/android/src/main/res/values/jpush_style.xml +22 -0
- package/android/src/test/java/com/margelo/nitro/reactnativejpush/ReactNativeJpushProtocolTest.java +1016 -0
- package/ios/ReactNativeJpush.swift +522 -0
- package/ios/bridge/RCTJCoreModule.h +5 -0
- package/ios/bridge/RCTJCoreModule.m +31 -0
- package/ios/bridge/RCTJPushEventQueue.h +14 -0
- package/ios/bridge/RCTJPushEventQueue.m +23 -0
- package/ios/bridge/RCTJPushModule.h +37 -0
- package/ios/bridge/RCTJPushModule.m +1165 -0
- package/ios/include/JCOREService.h +3 -0
- package/ios/include/JGCOREAPI.h +14 -0
- package/ios/include/JGInforCollectionAuth.h +17 -0
- package/ios/include/JGInforCollectionAuthItems.h +2 -0
- package/ios/include/JGPushNotificationTrigger.h +2 -0
- package/ios/include/JPUSHService.h +359 -0
- package/ios/jcore/JCOREConfiguration.h +141 -0
- package/ios/jcore/JCOREConfiguration.m +703 -0
- package/ios/jcore/JCORECrypto.h +73 -0
- package/ios/jcore/JCORECrypto.m +649 -0
- package/ios/jcore/JCORESisResolver.h +56 -0
- package/ios/jcore/JCORESisResolver.m +525 -0
- package/ios/jcore/JCORETcpSession.h +42 -0
- package/ios/jcore/JCORETcpSession.m +956 -0
- package/ios/jcore/JCOREWireProtocol.h +274 -0
- package/ios/jcore/JCOREWireProtocol.m +1453 -0
- package/ios/jpush/JPUSHModels.m +214 -0
- package/ios/jpush/JPUSHNotificationManager.h +34 -0
- package/ios/jpush/JPUSHNotificationManager.m +360 -0
- package/ios/jpush/JPUSHService.m +794 -0
- package/ios/tests/ReactNativeJpushTests.m +148 -0
- package/lib/module/ReactNativeJpush.nitro.js +4 -0
- package/lib/module/ReactNativeJpush.nitro.js.map +1 -0
- package/lib/module/index.js +801 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ReactNativeJpush.nitro.d.ts +60 -0
- package/lib/typescript/src/ReactNativeJpush.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +235 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +23 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeJpushSpec.cpp +310 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeJpushSpec.hpp +115 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/Func_void_bool.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/Func_void_std__string_std__string.kt +78 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/HybridReactNativeJpushSpec.kt +274 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativejpush/reactnativejpushOnLoad.kt +35 -0
- package/nitrogen/generated/android/reactnativejpush+autolinking.cmake +81 -0
- package/nitrogen/generated/android/reactnativejpush+autolinking.gradle +27 -0
- package/nitrogen/generated/android/reactnativejpushOnLoad.cpp +58 -0
- package/nitrogen/generated/android/reactnativejpushOnLoad.hpp +34 -0
- package/nitrogen/generated/ios/ReactNativeJpush+autolinking.rb +62 -0
- package/nitrogen/generated/ios/ReactNativeJpush-Swift-Cxx-Bridge.cpp +49 -0
- package/nitrogen/generated/ios/ReactNativeJpush-Swift-Cxx-Bridge.hpp +147 -0
- package/nitrogen/generated/ios/ReactNativeJpush-Swift-Cxx-Umbrella.hpp +46 -0
- package/nitrogen/generated/ios/ReactNativeJpushAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ReactNativeJpushAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeJpushSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeJpushSpecSwift.hpp +402 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeJpushSpec.swift +107 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeJpushSpec_cxx.swift +723 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeJpushSpec.cpp +73 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeJpushSpec.hpp +116 -0
- package/package.json +173 -4
- package/src/ReactNativeJpush.nitro.ts +93 -0
- package/src/index.tsx +1090 -0
package/src/index.tsx
ADDED
|
@@ -0,0 +1,1090 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DeviceEventEmitter,
|
|
3
|
+
type EmitterSubscription,
|
|
4
|
+
NativeModules,
|
|
5
|
+
Platform,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
8
|
+
import type { ReactNativeJpush } from './ReactNativeJpush.nitro';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Non-production demo test AppKey used solely for automated native and JS tests.
|
|
12
|
+
* Never used in production environments.
|
|
13
|
+
*/
|
|
14
|
+
export const DEMO_TEST_APP_KEY = '1f2027d3cfb1b51dac664c42';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Non-production sandbox package name bound to DEMO_TEST_APP_KEY for automated Android tests.
|
|
18
|
+
* Intentionally avoids 'onekey' and 'jpush' identifiers to prevent production confusion or vendor filtering.
|
|
19
|
+
*/
|
|
20
|
+
export const DEMO_TEST_PACKAGE_NAME = 'com.devstudio.msgbench';
|
|
21
|
+
|
|
22
|
+
export type Callback<T> = (result: T) => void;
|
|
23
|
+
|
|
24
|
+
export type Extra = {
|
|
25
|
+
[key: string]: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type Sequence = {
|
|
29
|
+
sequence: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type Tag = {
|
|
33
|
+
tag: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type Tags = {
|
|
37
|
+
tags: string[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type Alias = {
|
|
41
|
+
alias: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type NotificationId = {
|
|
45
|
+
notificationId: string | number;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type JPushInitParams = {
|
|
49
|
+
appKey: string;
|
|
50
|
+
channel: string;
|
|
51
|
+
production: boolean;
|
|
52
|
+
titchannelle?: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type JPushConnectEvent = {
|
|
56
|
+
connectEnable: boolean;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type JPushNotificationEvent = {
|
|
60
|
+
messageID: string;
|
|
61
|
+
title: string;
|
|
62
|
+
content: string;
|
|
63
|
+
badge?: string;
|
|
64
|
+
ring?: string;
|
|
65
|
+
extras?: Extra;
|
|
66
|
+
notificationEventType:
|
|
67
|
+
| 'notificationArrived'
|
|
68
|
+
| 'notificationOpened'
|
|
69
|
+
| 'notificationDismissed';
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type JPushLocalNotificationEvent = {
|
|
73
|
+
messageID: string;
|
|
74
|
+
title: string;
|
|
75
|
+
content: string;
|
|
76
|
+
extras?: Extra;
|
|
77
|
+
notificationEventType:
|
|
78
|
+
| 'notificationArrived'
|
|
79
|
+
| 'notificationOpened'
|
|
80
|
+
| 'notificationDismissed';
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export type JPushCustomMessageEvent = {
|
|
84
|
+
messageID: string;
|
|
85
|
+
title?: string;
|
|
86
|
+
content: string;
|
|
87
|
+
extras?: Extra;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type JPushNotifyButtonClickEvent = {
|
|
91
|
+
msgId: string;
|
|
92
|
+
platform: number;
|
|
93
|
+
name: string;
|
|
94
|
+
actionType: number;
|
|
95
|
+
action: string;
|
|
96
|
+
data: string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type JPushInappMessageEvent = {
|
|
100
|
+
mesageId: string;
|
|
101
|
+
title: string;
|
|
102
|
+
content: string;
|
|
103
|
+
target: string[];
|
|
104
|
+
clickAction: string;
|
|
105
|
+
extras?: Extra;
|
|
106
|
+
inappEventType: 'inappShow' | 'inappClick';
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export type JPushCommandEvent = {
|
|
110
|
+
command: number;
|
|
111
|
+
commandExtra: string;
|
|
112
|
+
commandMessage: string;
|
|
113
|
+
commandResult: number;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type JPushTagAliasEvent = {
|
|
117
|
+
code: number;
|
|
118
|
+
sequence: number;
|
|
119
|
+
tags?: string[] | string;
|
|
120
|
+
tag?: string;
|
|
121
|
+
tagEnable?: boolean;
|
|
122
|
+
alias?: string;
|
|
123
|
+
pros?: Record<string, string>;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export type JPushMobileNumberEvent = {
|
|
127
|
+
code: number;
|
|
128
|
+
sequence: number;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const ConnectEvent = 'ConnectEvent';
|
|
132
|
+
export const NotificationEvent = 'NotificationEvent';
|
|
133
|
+
export const LocalNotificationEvent = 'LocalNotificationEvent';
|
|
134
|
+
export const CustomMessageEvent = 'CustomMessageEvent';
|
|
135
|
+
export const NotifyButtonClickEvent = 'NotifyButtonClickEvent';
|
|
136
|
+
export const InappMessageEvent = 'InappMessageEvent';
|
|
137
|
+
export const TagAliasEvent = 'TagAliasEvent';
|
|
138
|
+
export const MobileNumberEvent = 'MobileNumberEvent';
|
|
139
|
+
export const CommandEvent = 'CommandEvent';
|
|
140
|
+
|
|
141
|
+
let cachedHybridObject: ReactNativeJpush | null | undefined;
|
|
142
|
+
|
|
143
|
+
function getNitroModule(): ReactNativeJpush | null {
|
|
144
|
+
if (cachedHybridObject !== undefined) {
|
|
145
|
+
return cachedHybridObject;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
cachedHybridObject =
|
|
149
|
+
NitroModules.createHybridObject<ReactNativeJpush>('ReactNativeJpush');
|
|
150
|
+
} catch {
|
|
151
|
+
cachedHybridObject = null;
|
|
152
|
+
}
|
|
153
|
+
return cachedHybridObject;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getLegacyJPushModule(): Record<string, any> | undefined {
|
|
157
|
+
return (NativeModules as Record<string, any>)?.JPushModule;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function ensureNativeEventBridgeInitialized(): void {
|
|
161
|
+
// Touch JPushModule so React Native instantiates RCTJPushModule / JPushModule
|
|
162
|
+
// and wires DeviceEventEmitter before Nitro or background events fire.
|
|
163
|
+
getLegacyJPushModule();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function getLegacyJCoreModule(): Record<string, any> | undefined {
|
|
167
|
+
return (NativeModules as Record<string, any>)?.JCoreModule;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const listeners = new Map<
|
|
171
|
+
(...args: any[]) => void,
|
|
172
|
+
EmitterSubscription | { remove: () => void }
|
|
173
|
+
>();
|
|
174
|
+
|
|
175
|
+
let sharedNitroListenerId: number | null = null;
|
|
176
|
+
const nitroSubscribersByEvent = new Map<string, Set<Callback<any>>>();
|
|
177
|
+
const pendingNitroEventsByEvent = new Map<string, any[]>();
|
|
178
|
+
|
|
179
|
+
function dispatchOrBufferNitroEvent(
|
|
180
|
+
eventName: string,
|
|
181
|
+
payloadJson: string
|
|
182
|
+
): void {
|
|
183
|
+
let parsed: any = {};
|
|
184
|
+
try {
|
|
185
|
+
parsed = payloadJson ? JSON.parse(payloadJson) : {};
|
|
186
|
+
} catch {
|
|
187
|
+
parsed = {};
|
|
188
|
+
}
|
|
189
|
+
const subs = nitroSubscribersByEvent.get(eventName);
|
|
190
|
+
if (subs && subs.size > 0) {
|
|
191
|
+
subs.forEach((cb) => {
|
|
192
|
+
cb(parsed);
|
|
193
|
+
});
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
let queue = pendingNitroEventsByEvent.get(eventName);
|
|
197
|
+
if (!queue) {
|
|
198
|
+
queue = [];
|
|
199
|
+
pendingNitroEventsByEvent.set(eventName, queue);
|
|
200
|
+
}
|
|
201
|
+
if (queue.length >= 32) {
|
|
202
|
+
queue.shift();
|
|
203
|
+
}
|
|
204
|
+
queue.push(parsed);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function ensureSharedNitroListener(nitro: ReactNativeJpush): void {
|
|
208
|
+
if (sharedNitroListenerId !== null) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
sharedNitroListenerId = nitro.addEventListener(
|
|
212
|
+
(eventName: string, payloadJson: string) => {
|
|
213
|
+
dispatchOrBufferNitroEvent(eventName, payloadJson);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function cleanupSharedNitroListenerIfIdle(nitro: ReactNativeJpush): void {
|
|
219
|
+
for (const subs of nitroSubscribersByEvent.values()) {
|
|
220
|
+
if (subs.size > 0) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (sharedNitroListenerId !== null) {
|
|
225
|
+
nitro.removeEventListener(sharedNitroListenerId);
|
|
226
|
+
sharedNitroListenerId = null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function registerEventListener<T>(
|
|
231
|
+
targetEventName: string,
|
|
232
|
+
callback: Callback<T>
|
|
233
|
+
): void {
|
|
234
|
+
if (typeof callback !== 'function') {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const existing = listeners.get(callback);
|
|
238
|
+
if (existing) {
|
|
239
|
+
existing.remove();
|
|
240
|
+
listeners.delete(callback);
|
|
241
|
+
}
|
|
242
|
+
const nitro = getNitroModule();
|
|
243
|
+
if (nitro && typeof nitro.addEventListener === 'function') {
|
|
244
|
+
let subs = nitroSubscribersByEvent.get(targetEventName);
|
|
245
|
+
if (!subs) {
|
|
246
|
+
subs = new Set();
|
|
247
|
+
nitroSubscribersByEvent.set(targetEventName, subs);
|
|
248
|
+
}
|
|
249
|
+
subs.add(callback);
|
|
250
|
+
ensureSharedNitroListener(nitro);
|
|
251
|
+
|
|
252
|
+
if (
|
|
253
|
+
targetEventName === NotificationEvent ||
|
|
254
|
+
targetEventName === LocalNotificationEvent
|
|
255
|
+
) {
|
|
256
|
+
nitro.loadJS?.();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const pending = pendingNitroEventsByEvent.get(targetEventName);
|
|
260
|
+
if (pending && pending.length > 0) {
|
|
261
|
+
const drained = pending.splice(0, pending.length);
|
|
262
|
+
for (const item of drained) {
|
|
263
|
+
callback(item as T);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
listeners.set(callback, {
|
|
268
|
+
remove: () => {
|
|
269
|
+
subs?.delete(callback);
|
|
270
|
+
cleanupSharedNitroListenerIfIdle(nitro);
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
ensureNativeEventBridgeInitialized();
|
|
276
|
+
listeners.set(
|
|
277
|
+
callback,
|
|
278
|
+
DeviceEventEmitter.addListener(targetEventName, (result) => {
|
|
279
|
+
callback(result);
|
|
280
|
+
})
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export class JCore {
|
|
285
|
+
static setAuth(auth: boolean): void {
|
|
286
|
+
const nitro = getNitroModule();
|
|
287
|
+
if (nitro) {
|
|
288
|
+
nitro.setAuth(Boolean(auth));
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
getLegacyJCoreModule()?.setAuth?.(Boolean(auth));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
static setCountryCode(params: { code: string }): void {
|
|
295
|
+
if (!params || typeof params.code !== 'string') {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const nitro = getNitroModule();
|
|
299
|
+
if (nitro) {
|
|
300
|
+
nitro.setCountryCode(params.code);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (Platform.OS === 'android') {
|
|
304
|
+
getLegacyJCoreModule()?.setCountryCode?.(params);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
static enableAutoWakeup(enable: boolean): void {
|
|
309
|
+
const nitro = getNitroModule();
|
|
310
|
+
if (nitro) {
|
|
311
|
+
nitro.enableAutoWakeup(Boolean(enable));
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (Platform.OS === 'android') {
|
|
315
|
+
getLegacyJCoreModule()?.enableAutoWakeup?.(Boolean(enable));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
static enableSDKLocalLog(params: {
|
|
320
|
+
enable: boolean;
|
|
321
|
+
uploadJgToServer: boolean;
|
|
322
|
+
}): void {
|
|
323
|
+
if (!params) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const nitro = getNitroModule();
|
|
327
|
+
if (nitro) {
|
|
328
|
+
nitro.enableSDKLocalLog(
|
|
329
|
+
Boolean(params.enable),
|
|
330
|
+
Boolean(params.uploadJgToServer)
|
|
331
|
+
);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (Platform.OS === 'android') {
|
|
335
|
+
getLegacyJCoreModule()?.enableSDKLocalLog?.(params);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
static readNewLogs(callback: Callback<{ logs: string }>): void {
|
|
340
|
+
if (typeof callback !== 'function') {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
const nitro = getNitroModule();
|
|
344
|
+
if (nitro) {
|
|
345
|
+
const logs = nitro.readNewLogs();
|
|
346
|
+
callback({ logs: logs || '' });
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (Platform.OS === 'android' && getLegacyJCoreModule()?.readNewLogs) {
|
|
350
|
+
getLegacyJCoreModule()?.readNewLogs(callback);
|
|
351
|
+
} else {
|
|
352
|
+
callback({ logs: '' });
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export default class JPush {
|
|
358
|
+
static setLoggerEnable(enable: boolean): void {
|
|
359
|
+
const nitro = getNitroModule();
|
|
360
|
+
if (nitro) {
|
|
361
|
+
nitro.setDebugMode(Boolean(enable));
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
getLegacyJPushModule()?.setDebugMode?.(Boolean(enable));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
static init(params?: JPushInitParams): void {
|
|
368
|
+
const appKey = params?.appKey ?? '';
|
|
369
|
+
const channel = params?.channel ?? 'dev';
|
|
370
|
+
const production = Boolean(params?.production ?? false);
|
|
371
|
+
const nitro = getNitroModule();
|
|
372
|
+
if (nitro) {
|
|
373
|
+
if (Platform.OS === 'android') {
|
|
374
|
+
if (appKey) {
|
|
375
|
+
nitro.setupWithConfig(appKey, channel, production);
|
|
376
|
+
} else {
|
|
377
|
+
nitro.initPush();
|
|
378
|
+
}
|
|
379
|
+
} else {
|
|
380
|
+
nitro.setupWithConfig(appKey, channel, production);
|
|
381
|
+
}
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
ensureNativeEventBridgeInitialized();
|
|
385
|
+
const legacy = getLegacyJPushModule();
|
|
386
|
+
if (!legacy) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
if (Platform.OS === 'android') {
|
|
390
|
+
legacy.init?.();
|
|
391
|
+
} else {
|
|
392
|
+
legacy.setupWithConfig?.(params ?? { appKey, channel, production });
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
static getRegistrationID(callback: Callback<{ registerID: string }>): void {
|
|
397
|
+
if (typeof callback !== 'function') {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
const nitro = getNitroModule();
|
|
401
|
+
if (nitro) {
|
|
402
|
+
const registerID = nitro.getRegistrationID() || '';
|
|
403
|
+
callback({ registerID });
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const legacy = getLegacyJPushModule();
|
|
407
|
+
if (!legacy) {
|
|
408
|
+
callback({ registerID: '' });
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (Platform.OS === 'android') {
|
|
412
|
+
legacy.getRegistrationID?.(callback);
|
|
413
|
+
} else {
|
|
414
|
+
legacy.getRegisterId?.(callback);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
static addTags(params: Sequence & Tags): void {
|
|
419
|
+
if (!params) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const nitro = getNitroModule();
|
|
423
|
+
if (nitro) {
|
|
424
|
+
nitro.addTags(params.sequence ?? -1, params.tags ?? []);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
getLegacyJPushModule()?.addTags?.(params);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
static updateTags(params: Sequence & Tags): void {
|
|
431
|
+
if (!params) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
const nitro = getNitroModule();
|
|
435
|
+
if (nitro) {
|
|
436
|
+
nitro.setTags(params.sequence ?? -1, params.tags ?? []);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
getLegacyJPushModule()?.setTags?.(params);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
static deleteTag(
|
|
443
|
+
params: Sequence & (Tags | { tag: string[] | string })
|
|
444
|
+
): void {
|
|
445
|
+
if (!params) {
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
const rawTags =
|
|
449
|
+
'tags' in params
|
|
450
|
+
? params.tags
|
|
451
|
+
: Array.isArray(params.tag)
|
|
452
|
+
? params.tag
|
|
453
|
+
: [params.tag];
|
|
454
|
+
const normalized = {
|
|
455
|
+
sequence: params.sequence ?? -1,
|
|
456
|
+
tags: rawTags ?? [],
|
|
457
|
+
};
|
|
458
|
+
const nitro = getNitroModule();
|
|
459
|
+
if (nitro) {
|
|
460
|
+
nitro.deleteTags(normalized.sequence, normalized.tags);
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
getLegacyJPushModule()?.deleteTags?.(normalized);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
static deleteTags(params: Sequence): void {
|
|
467
|
+
if (!params) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
const nitro = getNitroModule();
|
|
471
|
+
if (nitro) {
|
|
472
|
+
nitro.cleanTags(params.sequence ?? -1);
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
getLegacyJPushModule()?.cleanTags?.(params);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
static queryTag(params: Sequence & Tag): void {
|
|
479
|
+
if (!params) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const nitro = getNitroModule();
|
|
483
|
+
if (nitro) {
|
|
484
|
+
nitro.checkTagBindState(params.sequence ?? -1, params.tag ?? '');
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
const legacy = getLegacyJPushModule();
|
|
488
|
+
if (Platform.OS === 'android') {
|
|
489
|
+
legacy?.checkTagBindState?.(params);
|
|
490
|
+
} else {
|
|
491
|
+
legacy?.validTag?.(params);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
static queryTags(params: Sequence): void {
|
|
496
|
+
if (!params) {
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const nitro = getNitroModule();
|
|
500
|
+
if (nitro) {
|
|
501
|
+
nitro.getAllTags(params.sequence ?? -1);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
getLegacyJPushModule()?.getAllTags?.(params);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
static setAlias(params: Sequence & Alias): void {
|
|
508
|
+
if (!params) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
const nitro = getNitroModule();
|
|
512
|
+
if (nitro) {
|
|
513
|
+
nitro.setAlias(params.sequence ?? -1, params.alias ?? '');
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
getLegacyJPushModule()?.setAlias?.(params);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
static deleteAlias(params: Sequence): void {
|
|
520
|
+
if (!params) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
const nitro = getNitroModule();
|
|
524
|
+
if (nitro) {
|
|
525
|
+
nitro.deleteAlias(params.sequence ?? -1);
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
getLegacyJPushModule()?.deleteAlias?.(params);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
static queryAlias(params: Sequence): void {
|
|
532
|
+
if (!params) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
const nitro = getNitroModule();
|
|
536
|
+
if (nitro) {
|
|
537
|
+
nitro.getAlias(params.sequence ?? -1);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
getLegacyJPushModule()?.getAlias?.(params);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
static setProperties(
|
|
544
|
+
params: Sequence & {
|
|
545
|
+
pros?: Record<string, any>;
|
|
546
|
+
properties?: Record<string, any>;
|
|
547
|
+
}
|
|
548
|
+
): void {
|
|
549
|
+
if (!params) {
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const propsObj = params.pros ?? params.properties ?? {};
|
|
553
|
+
const nitro = getNitroModule();
|
|
554
|
+
if (nitro) {
|
|
555
|
+
nitro.setProperties(params.sequence ?? -1, JSON.stringify(propsObj));
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
getLegacyJPushModule()?.setProperties?.(params);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
static deleteProperties(
|
|
562
|
+
params: Sequence & {
|
|
563
|
+
pros?: Record<string, any>;
|
|
564
|
+
properties?: Record<string, any>;
|
|
565
|
+
}
|
|
566
|
+
): void {
|
|
567
|
+
if (!params) {
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const propsObj = params.pros ?? params.properties ?? {};
|
|
571
|
+
const nitro = getNitroModule();
|
|
572
|
+
if (nitro) {
|
|
573
|
+
nitro.deleteProperties(params.sequence ?? -1, Object.keys(propsObj));
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
getLegacyJPushModule()?.deleteProperties?.(params);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
static cleanProperties(params?: Sequence): void {
|
|
580
|
+
const seq = params?.sequence ?? -1;
|
|
581
|
+
const nitro = getNitroModule();
|
|
582
|
+
if (nitro) {
|
|
583
|
+
nitro.cleanProperties(seq);
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
getLegacyJPushModule()?.cleanProperties?.(params ?? { sequence: seq });
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
static pageEnterTo(pageName: string): void {
|
|
590
|
+
const nitro = getNitroModule();
|
|
591
|
+
if (nitro) {
|
|
592
|
+
nitro.pageEnterTo(pageName ?? '');
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
if (Platform.OS !== 'android') {
|
|
596
|
+
getLegacyJPushModule()?.pageEnterTo?.(pageName);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
static pageLeave(pageName: string): void {
|
|
601
|
+
const nitro = getNitroModule();
|
|
602
|
+
if (nitro) {
|
|
603
|
+
nitro.pageLeave(pageName ?? '');
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
if (Platform.OS !== 'android') {
|
|
607
|
+
getLegacyJPushModule()?.pageLeave?.(pageName);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
static setMobileNumber(params: { mobileNumber: string } & Sequence): void {
|
|
612
|
+
if (!params) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const nitro = getNitroModule();
|
|
616
|
+
if (nitro) {
|
|
617
|
+
nitro.setMobileNumber(params.sequence ?? -1, params.mobileNumber ?? '');
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
getLegacyJPushModule()?.setMobileNumber?.(params);
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
static initCrashHandler(): void {
|
|
624
|
+
const nitro = getNitroModule();
|
|
625
|
+
if (nitro) {
|
|
626
|
+
nitro.initCrashHandler();
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
const legacy = getLegacyJPushModule();
|
|
630
|
+
if (Platform.OS === 'android') {
|
|
631
|
+
legacy?.initCrashHandler?.();
|
|
632
|
+
} else {
|
|
633
|
+
legacy?.crashLogON?.(null);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
static setPowerSaveMode(enable: boolean): void {
|
|
638
|
+
const nitro = getNitroModule();
|
|
639
|
+
if (nitro) {
|
|
640
|
+
nitro.setPowerSaveMode(Boolean(enable));
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
if (Platform.OS === 'android') {
|
|
644
|
+
getLegacyJPushModule()?.setPowerSaveMode?.(Boolean(enable));
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
static isNotificationEnabled(callback: Callback<boolean>): void {
|
|
649
|
+
if (typeof callback !== 'function') {
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
const nitro = getNitroModule();
|
|
653
|
+
if (nitro) {
|
|
654
|
+
nitro.isNotificationEnabled((enabled: boolean) => {
|
|
655
|
+
callback(Boolean(enabled));
|
|
656
|
+
});
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
const legacy = getLegacyJPushModule();
|
|
660
|
+
if (legacy?.isNotificationEnabled) {
|
|
661
|
+
legacy.isNotificationEnabled((res: boolean | number) => {
|
|
662
|
+
callback(Boolean(res));
|
|
663
|
+
});
|
|
664
|
+
} else {
|
|
665
|
+
callback(false);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
static addLocalNotification(params: {
|
|
670
|
+
messageID: string;
|
|
671
|
+
title: string;
|
|
672
|
+
content: string;
|
|
673
|
+
extras?: Extra;
|
|
674
|
+
broadcastTime?: string;
|
|
675
|
+
builderName?: string;
|
|
676
|
+
category?: string;
|
|
677
|
+
priority?: number;
|
|
678
|
+
}): void {
|
|
679
|
+
if (!params) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
const nitro = getNitroModule();
|
|
683
|
+
if (nitro) {
|
|
684
|
+
nitro.addLocalNotification(
|
|
685
|
+
params.messageID ?? '',
|
|
686
|
+
params.title ?? '',
|
|
687
|
+
params.content ?? '',
|
|
688
|
+
params.broadcastTime ?? '0',
|
|
689
|
+
params.extras ? JSON.stringify(params.extras) : '{}'
|
|
690
|
+
);
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
const legacy = getLegacyJPushModule();
|
|
694
|
+
if (Platform.OS === 'android') {
|
|
695
|
+
legacy?.addLocalNotification?.(params);
|
|
696
|
+
} else {
|
|
697
|
+
legacy?.addNotification?.(params);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
static removeLocalNotification(params: { messageID: string }): void {
|
|
702
|
+
if (!params) {
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
const nitro = getNitroModule();
|
|
706
|
+
if (nitro) {
|
|
707
|
+
nitro.removeLocalNotification(params.messageID ?? '');
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
const legacy = getLegacyJPushModule();
|
|
711
|
+
if (Platform.OS === 'android') {
|
|
712
|
+
legacy?.removeLocalNotification?.(params);
|
|
713
|
+
} else {
|
|
714
|
+
legacy?.removeNotification?.(params);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
static clearLocalNotifications(): void {
|
|
719
|
+
const nitro = getNitroModule();
|
|
720
|
+
if (nitro) {
|
|
721
|
+
nitro.clearLocalNotifications();
|
|
722
|
+
return;
|
|
723
|
+
}
|
|
724
|
+
getLegacyJPushModule()?.clearLocalNotifications?.();
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
static clearAllNotifications(): void {
|
|
728
|
+
const nitro = getNitroModule();
|
|
729
|
+
if (nitro) {
|
|
730
|
+
nitro.clearAllNotifications();
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (Platform.OS === 'android') {
|
|
734
|
+
getLegacyJPushModule()?.clearAllNotifications?.();
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
static clearNotificationById(params: NotificationId): void {
|
|
739
|
+
if (!params) {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const nitro = getNitroModule();
|
|
743
|
+
if (nitro) {
|
|
744
|
+
nitro.clearNotificationById(Number(params.notificationId) || 0);
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
if (Platform.OS === 'android') {
|
|
748
|
+
getLegacyJPushModule()?.clearNotificationById?.(params);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
static setMaxGeofenceNumber(params: { geoFenceMaxNumber: number }): void {
|
|
753
|
+
if (!params) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
const nitro = getNitroModule();
|
|
757
|
+
if (nitro) {
|
|
758
|
+
nitro.setMaxGeofenceNumber(Number(params.geoFenceMaxNumber) || 10);
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
const legacy = getLegacyJPushModule();
|
|
762
|
+
if (Platform.OS === 'android') {
|
|
763
|
+
legacy?.setMaxGeofenceNumber?.(params);
|
|
764
|
+
} else {
|
|
765
|
+
legacy?.setGeofeneceMaxCount?.(params);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
static deleteGeofence(params: { geoFenceID: string }): void {
|
|
770
|
+
if (!params) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
const nitro = getNitroModule();
|
|
774
|
+
if (nitro) {
|
|
775
|
+
nitro.deleteGeofence(params.geoFenceID ?? '');
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
const legacy = getLegacyJPushModule();
|
|
779
|
+
if (Platform.OS === 'android') {
|
|
780
|
+
legacy?.deleteGeofence?.(params);
|
|
781
|
+
} else {
|
|
782
|
+
legacy?.removeGeofenceWithIdentifier?.(params);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
static addConnectEventListener(callback: Callback<JPushConnectEvent>): void {
|
|
787
|
+
registerEventListener(ConnectEvent, callback);
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
static addCommandEventListener(callback: Callback<JPushCommandEvent>): void {
|
|
791
|
+
registerEventListener(CommandEvent, callback);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
static addNotificationListener(
|
|
795
|
+
callback: Callback<JPushNotificationEvent>
|
|
796
|
+
): void {
|
|
797
|
+
registerEventListener(NotificationEvent, callback);
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
static addLocalNotificationListener(
|
|
801
|
+
callback: Callback<JPushLocalNotificationEvent>
|
|
802
|
+
): void {
|
|
803
|
+
registerEventListener(LocalNotificationEvent, callback);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
static addCustomMessageListener(
|
|
807
|
+
callback: Callback<JPushCustomMessageEvent>
|
|
808
|
+
): void {
|
|
809
|
+
registerEventListener(CustomMessageEvent, callback);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
static addNotifyButtonClickListener(
|
|
813
|
+
callback: Callback<JPushNotifyButtonClickEvent>
|
|
814
|
+
): void {
|
|
815
|
+
registerEventListener(NotifyButtonClickEvent, callback);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
static addInappMessageListener(
|
|
819
|
+
callback: Callback<JPushInappMessageEvent>
|
|
820
|
+
): void {
|
|
821
|
+
registerEventListener(InappMessageEvent, callback);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
static addTagAliasListener(callback: Callback<JPushTagAliasEvent>): void {
|
|
825
|
+
registerEventListener(TagAliasEvent, callback);
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
static addMobileNumberListener(
|
|
829
|
+
callback: Callback<JPushMobileNumberEvent>
|
|
830
|
+
): void {
|
|
831
|
+
registerEventListener(MobileNumberEvent, callback);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
static removeListener(callback: (...args: any[]) => void): void {
|
|
835
|
+
const sub = listeners.get(callback);
|
|
836
|
+
if (!sub) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
sub.remove();
|
|
840
|
+
listeners.delete(callback);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
static requestPermission(): void {
|
|
844
|
+
const nitro = getNitroModule();
|
|
845
|
+
if (nitro) {
|
|
846
|
+
nitro.requestPermission();
|
|
847
|
+
return;
|
|
848
|
+
}
|
|
849
|
+
if (Platform.OS === 'android') {
|
|
850
|
+
getLegacyJPushModule()?.requestPermission?.();
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
static stopPush(): void {
|
|
855
|
+
const nitro = getNitroModule();
|
|
856
|
+
if (nitro) {
|
|
857
|
+
nitro.stopPush();
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
getLegacyJPushModule()?.stopPush?.();
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
static resumePush(): void {
|
|
864
|
+
const nitro = getNitroModule();
|
|
865
|
+
if (nitro) {
|
|
866
|
+
nitro.resumePush();
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
getLegacyJPushModule()?.resumePush?.();
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
static isPushStopped(callback: Callback<boolean>): void {
|
|
873
|
+
if (typeof callback !== 'function') {
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
const nitro = getNitroModule();
|
|
877
|
+
if (nitro) {
|
|
878
|
+
callback(Boolean(nitro.isPushStopped()));
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
if (Platform.OS === 'android' && getLegacyJPushModule()?.isPushStopped) {
|
|
882
|
+
getLegacyJPushModule()?.isPushStopped(callback);
|
|
883
|
+
} else {
|
|
884
|
+
callback(false);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
static setPushTime(params: {
|
|
889
|
+
pushTimeDays: number[];
|
|
890
|
+
pushTimeStartHour: number;
|
|
891
|
+
pushTimeEndHour: number;
|
|
892
|
+
}): void {
|
|
893
|
+
if (!params) {
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
const nitro = getNitroModule();
|
|
897
|
+
if (nitro) {
|
|
898
|
+
nitro.setPushTime(
|
|
899
|
+
params.pushTimeDays ?? [],
|
|
900
|
+
params.pushTimeStartHour ?? 0,
|
|
901
|
+
params.pushTimeEndHour ?? 23
|
|
902
|
+
);
|
|
903
|
+
return;
|
|
904
|
+
}
|
|
905
|
+
if (Platform.OS === 'android') {
|
|
906
|
+
getLegacyJPushModule()?.setPushTime?.(params);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
static setSilenceTime(params: {
|
|
911
|
+
silenceTimeStartHour: number;
|
|
912
|
+
silenceTimeStartMinute: number;
|
|
913
|
+
silenceTimeEndHour: number;
|
|
914
|
+
silenceTimeEndMinute: number;
|
|
915
|
+
}): void {
|
|
916
|
+
if (!params) {
|
|
917
|
+
return;
|
|
918
|
+
}
|
|
919
|
+
const nitro = getNitroModule();
|
|
920
|
+
if (nitro) {
|
|
921
|
+
nitro.setSilenceTime(
|
|
922
|
+
params.silenceTimeStartHour ?? 0,
|
|
923
|
+
params.silenceTimeStartMinute ?? 0,
|
|
924
|
+
params.silenceTimeEndHour ?? 0,
|
|
925
|
+
params.silenceTimeEndMinute ?? 0
|
|
926
|
+
);
|
|
927
|
+
return;
|
|
928
|
+
}
|
|
929
|
+
if (Platform.OS === 'android') {
|
|
930
|
+
getLegacyJPushModule()?.setSilenceTime?.(params);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
static setLatestNotificationNumber(params: {
|
|
935
|
+
notificationMaxNumber: number;
|
|
936
|
+
}): void {
|
|
937
|
+
if (!params) {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
const nitro = getNitroModule();
|
|
941
|
+
if (nitro) {
|
|
942
|
+
nitro.setLatestNotificationNumber(params.notificationMaxNumber ?? 5);
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
if (Platform.OS === 'android') {
|
|
946
|
+
getLegacyJPushModule()?.setLatestNotificationNumber?.(params);
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
static setChannel(params: { channel: string }): void {
|
|
951
|
+
if (!params) {
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
const nitro = getNitroModule();
|
|
955
|
+
if (nitro) {
|
|
956
|
+
nitro.setChannel(params.channel ?? '');
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
if (Platform.OS === 'android') {
|
|
960
|
+
getLegacyJPushModule()?.setChannel?.(params);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
static setChannelAndSound(params: {
|
|
965
|
+
channel: string;
|
|
966
|
+
channelId?: string;
|
|
967
|
+
sound?: string;
|
|
968
|
+
}): void {
|
|
969
|
+
if (!params) {
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const nitro = getNitroModule();
|
|
973
|
+
if (nitro) {
|
|
974
|
+
nitro.setChannelAndSound(
|
|
975
|
+
params.channel ?? '',
|
|
976
|
+
params.channelId ?? '',
|
|
977
|
+
params.sound ?? ''
|
|
978
|
+
);
|
|
979
|
+
return;
|
|
980
|
+
}
|
|
981
|
+
if (Platform.OS === 'android') {
|
|
982
|
+
getLegacyJPushModule()?.setChannelAndSound?.(params);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
static setBadge(params: { badge: number; appBadge?: number }): void {
|
|
987
|
+
if (!params) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
const badge = params.badge ?? 0;
|
|
991
|
+
const appBadge = params.appBadge ?? badge;
|
|
992
|
+
const nitro = getNitroModule();
|
|
993
|
+
if (nitro) {
|
|
994
|
+
nitro.setBadge(badge, appBadge);
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
const legacy = getLegacyJPushModule();
|
|
998
|
+
if (Platform.OS === 'ios') {
|
|
999
|
+
legacy?.setBadge?.(params);
|
|
1000
|
+
} else if (Platform.OS === 'android') {
|
|
1001
|
+
legacy?.setBadgeNumber?.(params);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
static setLinkMergeEnable(enable: boolean): void {
|
|
1006
|
+
const nitro = getNitroModule();
|
|
1007
|
+
if (nitro) {
|
|
1008
|
+
nitro.setLinkMergeEnable(Boolean(enable));
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (Platform.OS === 'android') {
|
|
1012
|
+
getLegacyJPushModule()?.setLinkMergeEnable?.(Boolean(enable));
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
static setSmartPushEnable(enable: boolean): void {
|
|
1017
|
+
const nitro = getNitroModule();
|
|
1018
|
+
if (nitro) {
|
|
1019
|
+
nitro.setSmartPushEnable(Boolean(enable));
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
getLegacyJPushModule()?.setSmartPushEnable?.(Boolean(enable));
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
static setDataInsightsEnable(enable: boolean): void {
|
|
1026
|
+
const nitro = getNitroModule();
|
|
1027
|
+
if (nitro) {
|
|
1028
|
+
nitro.setDataInsightsEnable(Boolean(enable));
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
if (Platform.OS === 'android') {
|
|
1032
|
+
getLegacyJPushModule()?.setDataInsightsEnable?.(Boolean(enable));
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
static setGeofenceEnable(enable: boolean): void {
|
|
1037
|
+
const nitro = getNitroModule();
|
|
1038
|
+
if (nitro) {
|
|
1039
|
+
nitro.setGeofenceEnable(Boolean(enable));
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
if (Platform.OS === 'android') {
|
|
1043
|
+
getLegacyJPushModule()?.setGeofenceEnable?.(Boolean(enable));
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
static setCollectControl(params: {
|
|
1048
|
+
cell?: boolean;
|
|
1049
|
+
bssid?: boolean;
|
|
1050
|
+
imei?: boolean;
|
|
1051
|
+
imsi?: boolean;
|
|
1052
|
+
mac?: boolean;
|
|
1053
|
+
wifi?: boolean;
|
|
1054
|
+
ssid?: boolean;
|
|
1055
|
+
gps?: boolean;
|
|
1056
|
+
}): void {
|
|
1057
|
+
if (!params) {
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
const nitro = getNitroModule();
|
|
1061
|
+
if (nitro) {
|
|
1062
|
+
nitro.setCollectControl(
|
|
1063
|
+
params.imei ?? true,
|
|
1064
|
+
params.imsi ?? true,
|
|
1065
|
+
params.mac ?? true,
|
|
1066
|
+
params.wifi ?? true,
|
|
1067
|
+
params.bssid ?? true,
|
|
1068
|
+
params.ssid ?? true,
|
|
1069
|
+
params.cell ?? true,
|
|
1070
|
+
params.gps ?? true
|
|
1071
|
+
);
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
getLegacyJPushModule()?.setCollectControl?.(params);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
static setBackgroundEnable(enable: boolean): void {
|
|
1078
|
+
const nitro = getNitroModule();
|
|
1079
|
+
if (nitro) {
|
|
1080
|
+
nitro.setBackgroundEnable(Boolean(enable));
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
if (Platform.OS === 'ios') {
|
|
1084
|
+
getLegacyJPushModule()?.setBackgroundEnable?.(Boolean(enable));
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
export { JPush };
|
|
1090
|
+
export type { ReactNativeJpush };
|