react-native-notify-sphere 1.0.0

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 ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 madhav
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "NotifySphere"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://code.dothejob.in/sandeepplanet/notifySphere.git.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,cpp}"
17
+ s.private_header_files = "ios/**/*.h"
18
+
19
+
20
+ install_modules_dependencies(s)
21
+ end
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # react-native-notify-sphere
2
+
3
+ test
4
+
5
+ ## Installation
6
+
7
+
8
+ ```sh
9
+ npm install react-native-notify-sphere
10
+ ```
11
+
12
+
13
+ ## Usage
14
+
15
+
16
+ ```js
17
+ import { multiply } from 'react-native-notify-sphere';
18
+
19
+ // ...
20
+
21
+ const result = multiply(3, 7);
22
+ ```
23
+
24
+
25
+ ## Contributing
26
+
27
+ - [Development workflow](CONTRIBUTING.md#development-workflow)
28
+ - [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
29
+ - [Code of conduct](CODE_OF_CONDUCT.md)
30
+
31
+ ## License
32
+
33
+ MIT
34
+
35
+ ---
36
+
37
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,77 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['NotifySphere_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ def getExtOrIntegerDefault(name) {
25
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["NotifySphere_" + name]).toInteger()
26
+ }
27
+
28
+ android {
29
+ namespace "com.notifysphere"
30
+
31
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
+
33
+ defaultConfig {
34
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
+ }
37
+
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
41
+
42
+ buildTypes {
43
+ release {
44
+ minifyEnabled false
45
+ }
46
+ }
47
+
48
+ lintOptions {
49
+ disable "GradleCompatible"
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_1_8
54
+ targetCompatibility JavaVersion.VERSION_1_8
55
+ }
56
+
57
+ sourceSets {
58
+ main {
59
+ java.srcDirs += [
60
+ "generated/java",
61
+ "generated/jni"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+
67
+ repositories {
68
+ mavenCentral()
69
+ google()
70
+ }
71
+
72
+ def kotlin_version = getExtOrDefault("kotlinVersion")
73
+
74
+ dependencies {
75
+ implementation "com.facebook.react:react-android"
76
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
+ }
@@ -0,0 +1,5 @@
1
+ NotifySphere_kotlinVersion=2.0.21
2
+ NotifySphere_minSdkVersion=24
3
+ NotifySphere_targetSdkVersion=34
4
+ NotifySphere_compileSdkVersion=35
5
+ NotifySphere_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,23 @@
1
+ package com.notifysphere
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.module.annotations.ReactModule
5
+
6
+ @ReactModule(name = NotifySphereModule.NAME)
7
+ class NotifySphereModule(reactContext: ReactApplicationContext) :
8
+ NativeNotifySphereSpec(reactContext) {
9
+
10
+ override fun getName(): String {
11
+ return NAME
12
+ }
13
+
14
+ // Example method
15
+ // See https://reactnative.dev/docs/native-modules-android
16
+ override fun multiply(a: Double, b: Double): Double {
17
+ return a * b
18
+ }
19
+
20
+ companion object {
21
+ const val NAME = "NotifySphere"
22
+ }
23
+ }
@@ -0,0 +1,33 @@
1
+ package com.notifysphere
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import java.util.HashMap
9
+
10
+ class NotifySpherePackage : BaseReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
+ return if (name == NotifySphereModule.NAME) {
13
+ NotifySphereModule(reactContext)
14
+ } else {
15
+ null
16
+ }
17
+ }
18
+
19
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
+ return ReactModuleInfoProvider {
21
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
+ moduleInfos[NotifySphereModule.NAME] = ReactModuleInfo(
23
+ NotifySphereModule.NAME,
24
+ NotifySphereModule.NAME,
25
+ false, // canOverrideExistingModule
26
+ false, // needsEagerInit
27
+ false, // isCxxModule
28
+ true // isTurboModule
29
+ )
30
+ moduleInfos
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,5 @@
1
+ #import <NotifySphereSpec/NotifySphereSpec.h>
2
+
3
+ @interface NotifySphere : NSObject <NativeNotifySphereSpec>
4
+
5
+ @end
@@ -0,0 +1,18 @@
1
+ #import "NotifySphere.h"
2
+
3
+ @implementation NotifySphere
4
+ RCT_EXPORT_MODULE()
5
+
6
+ - (NSNumber *)multiply:(double)a b:(double)b {
7
+ NSNumber *result = @(a * b);
8
+
9
+ return result;
10
+ }
11
+
12
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
13
+ (const facebook::react::ObjCTurboModule::InitParams &)params
14
+ {
15
+ return std::make_shared<facebook::react::NativeNotifySphereSpecJSI>(params);
16
+ }
17
+
18
+ @end
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+ export default TurboModuleRegistry.getEnforcing('NotifySphere');
5
+ //# sourceMappingURL=NativeNotifySphere.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeNotifySphere.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AAMpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,cAAc,CAAC","ignoreList":[]}
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+
3
+ import messaging from '@react-native-firebase/messaging';
4
+ import notifee, { AndroidImportance, AndroidStyle, EventType // Import EventType if available
5
+ } from '@notifee/react-native';
6
+ import axios from 'axios';
7
+ import { PermissionsAndroid, Platform } from 'react-native';
8
+ import DeviceInfo from "react-native-device-info";
9
+ import * as RNLocalize from "react-native-localize";
10
+ class NotifySphere {
11
+ static callback = null;
12
+
13
+ // ✅ Permission check remains fully here
14
+
15
+ static async callbackOnpress(remoteMessage, status) {
16
+ console.log('remoteMessage413123', remoteMessage);
17
+ try {
18
+ const data = JSON.stringify({
19
+ notifiction_id: remoteMessage?.data?.notification_id,
20
+ // 🔑 keep same spelling as backend expects
21
+ onPressStatus: 1
22
+ });
23
+ const config = {
24
+ method: 'post',
25
+ maxBodyLength: Infinity,
26
+ url: 'https://notifysphere.dothejob.in:3008/onpress/handle',
27
+ headers: {
28
+ 'Content-Type': 'application/json',
29
+ 'Cookie': 'token=sYPT8POivlxfFSR54MWd3reaArvODMiIcM4KM39cqkXBLVu%2B8b1zV2csabU9byzo'
30
+ },
31
+ data
32
+ };
33
+ const response = await axios.request(config);
34
+ console.log('onPress API response:', response);
35
+ NotifySphere.sendCallback(remoteMessage, status);
36
+ } catch (error) {
37
+ console.error('Error in callbackOnpress:', error);
38
+ }
39
+ }
40
+ static async checkApplicationPermission() {
41
+ try {
42
+ if (Platform.OS === 'android' && Platform.Version >= 33) {
43
+ const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
44
+ return granted === PermissionsAndroid.RESULTS.GRANTED;
45
+ } else if (Platform.OS === 'ios') {
46
+ const authStatus = await messaging().requestPermission();
47
+ return authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL;
48
+ }
49
+ return true;
50
+ } catch (error) {
51
+ console.error('Error requesting notification permission:', error);
52
+ return false;
53
+ }
54
+ }
55
+ static async getDeviceInfo() {
56
+ return {
57
+ sdk: DeviceInfo.getApiLevel()?.toString(),
58
+ // e.g. "34"
59
+ device_model: DeviceInfo.getModel(),
60
+ // e.g. "iPhone 14" or "TECNO CK6"
61
+ device_os: DeviceInfo.getSystemName(),
62
+ // e.g. "Android" or "iOS"
63
+ device_version: DeviceInfo.getSystemVersion(),
64
+ // e.g. "15"
65
+ carrier: await DeviceInfo.getCarrier(),
66
+ // e.g. "airtel"
67
+ app_version: DeviceInfo.getVersion(),
68
+ // e.g. "1.0.2"
69
+ timezone_id: RNLocalize.getTimeZone() // e.g. "Asia/Kolkata"
70
+ };
71
+ }
72
+ static async initialize(config) {
73
+ const hasPermission = await NotifySphere.checkApplicationPermission();
74
+ const devInfo = await NotifySphere.getDeviceInfo();
75
+ if (!hasPermission) return;
76
+ const fcmToken = await messaging().getToken();
77
+ console.log('fcmToken31232', fcmToken, config);
78
+ if (!config.appId) return;
79
+ let subscription_id = await axios.post(`https://notifysphere.dothejob.in:3008/apps/${config.appId}/users`, {
80
+ applicationUserId: config.applicationUserId,
81
+ token: fcmToken,
82
+ type: config.type,
83
+ user: {
84
+ userName: config.name,
85
+ lat: config.lat,
86
+ long: config.long,
87
+ city: config.city,
88
+ state: config.state,
89
+ email: config.email,
90
+ phone: config.phone,
91
+ tags: config.tags,
92
+ sdk: devInfo.sdk,
93
+ device_model: devInfo.device_model,
94
+ device_os: devInfo.device_os,
95
+ device_version: devInfo.device_version,
96
+ carrier: devInfo.carrier,
97
+ app_version: devInfo.app_version,
98
+ timezone_id: devInfo.timezone_id
99
+ }
100
+ }, {
101
+ headers: {
102
+ 'Content-Type': 'application/json'
103
+ },
104
+ maxBodyLength: Infinity
105
+ }).then(async res => {
106
+ console.log('res313132', res);
107
+ return res.data.subscription_id;
108
+ }).catch(err => {
109
+ console.log('err31232', err);
110
+ });
111
+ NotifySphere.setupListeners();
112
+ return subscription_id;
113
+ }
114
+ static onNotification(callback) {
115
+ NotifySphere.callback = callback;
116
+ }
117
+ static setupListeners() {
118
+ messaging().onMessage(async remoteMessage => {
119
+ await NotifySphere.displayLocalNotification(remoteMessage);
120
+ });
121
+ messaging().onNotificationOpenedApp(async remoteMessage => {
122
+ console.log('data34234', remoteMessage);
123
+ NotifySphere.callbackOnpress(remoteMessage, 'opened');
124
+ });
125
+ messaging().getInitialNotification().then(remoteMessage => {
126
+ if (remoteMessage) {
127
+ NotifySphere.callbackOnpress(remoteMessage, 'initial');
128
+ }
129
+ });
130
+ notifee.onForegroundEvent(({
131
+ type,
132
+ detail
133
+ }) => {
134
+ if (type === EventType.PRESS) {
135
+ console.log('detail323213', detail);
136
+ NotifySphere.callbackOnpress(detail.notification, 'opened');
137
+ }
138
+ });
139
+ notifee.onBackgroundEvent(async ({
140
+ type,
141
+ detail
142
+ }) => {
143
+ console.log('detail323213111111', type, detail);
144
+ if (type === EventType.PRESS) {
145
+ console.log('detail323213', detail);
146
+ NotifySphere.callbackOnpress(detail.notification, 'press');
147
+ }
148
+ });
149
+ }
150
+ static async displayLocalNotification(remoteMessage) {
151
+ const soundRaw = remoteMessage.data?.sound || 'default';
152
+ const androidChannelId = `channel_${soundRaw}`;
153
+ const androidSoundName = soundRaw.replace(/\..+$/, '');
154
+ console.log('remoteMessage1312', remoteMessage);
155
+ await notifee.createChannel({
156
+ id: androidChannelId,
157
+ name: `Channel ${androidSoundName}`,
158
+ importance: AndroidImportance.HIGH,
159
+ sound: androidSoundName !== 'default' ? androidSoundName : undefined
160
+ });
161
+ const image = remoteMessage?.data?.fcm_options?.image || remoteMessage.notification?.android?.imageUrl || remoteMessage.notification?.imageUrl || remoteMessage.notification?.ios?.attachments?.[0]?.url;
162
+ await notifee.displayNotification({
163
+ title: remoteMessage.notification?.title,
164
+ body: remoteMessage.notification?.body,
165
+ android: {
166
+ channelId: androidChannelId,
167
+ importance: AndroidImportance.HIGH,
168
+ sound: androidSoundName !== 'default' ? androidSoundName : undefined,
169
+ largeIcon: image,
170
+ style: image ? {
171
+ type: AndroidStyle.BIGPICTURE,
172
+ picture: image
173
+ } : undefined
174
+ },
175
+ ios: {
176
+ sound: soundRaw,
177
+ // must be a bundled sound file or "default"
178
+ attachments: image ? [{
179
+ url: image
180
+ }] : undefined,
181
+ // ✅ this is correct
182
+ foregroundPresentationOptions: {
183
+ alert: true,
184
+ badge: true,
185
+ sound: true
186
+ }
187
+ },
188
+ data: remoteMessage.data
189
+ });
190
+ }
191
+ static sendCallback(remoteMessage, type) {
192
+ if (!NotifySphere.callback) return;
193
+ const image = remoteMessage.notification?.android?.imageUrl || remoteMessage.notification?.imageUrl || remoteMessage.notification?.ios?.attachments?.[0]?.url;
194
+ NotifySphere.callback({
195
+ title: remoteMessage.notification?.title,
196
+ body: remoteMessage.notification?.body,
197
+ data: remoteMessage.data,
198
+ image,
199
+ sound: remoteMessage.data?.sound
200
+ }, type);
201
+ }
202
+ }
203
+ export default NotifySphere;
204
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["messaging","notifee","AndroidImportance","AndroidStyle","EventType","axios","PermissionsAndroid","Platform","DeviceInfo","RNLocalize","NotifySphere","callback","callbackOnpress","remoteMessage","status","console","log","data","JSON","stringify","notifiction_id","notification_id","onPressStatus","config","method","maxBodyLength","Infinity","url","headers","response","request","sendCallback","error","checkApplicationPermission","OS","Version","granted","PERMISSIONS","POST_NOTIFICATIONS","RESULTS","GRANTED","authStatus","requestPermission","AuthorizationStatus","AUTHORIZED","PROVISIONAL","getDeviceInfo","sdk","getApiLevel","toString","device_model","getModel","device_os","getSystemName","device_version","getSystemVersion","carrier","getCarrier","app_version","getVersion","timezone_id","getTimeZone","initialize","hasPermission","devInfo","fcmToken","getToken","appId","subscription_id","post","applicationUserId","token","type","user","userName","name","lat","long","city","state","email","phone","tags","then","res","catch","err","setupListeners","onNotification","onMessage","displayLocalNotification","onNotificationOpenedApp","getInitialNotification","onForegroundEvent","detail","PRESS","notification","onBackgroundEvent","soundRaw","sound","androidChannelId","androidSoundName","replace","createChannel","id","importance","HIGH","undefined","image","fcm_options","android","imageUrl","ios","attachments","displayNotification","title","body","channelId","largeIcon","style","BIGPICTURE","picture","foregroundPresentationOptions","alert","badge"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,SAAS,MAAM,kCAAkC;AACxD,OAAOC,OAAO,IACZC,iBAAiB,EACjBC,YAAY,EACZC,SAAS,CAAE;AAAA,OACN,uBAAuB;AAC9B,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAC3D,OAAOC,UAAU,MAAM,0BAA0B;AACjD,OAAO,KAAKC,UAAU,MAAM,uBAAuB;AAkBnD,MAAMC,YAAY,CAAC;EACjB,OAAeC,QAAQ,GAAgC,IAAI;;EAE3D;;EAEA,aAAaC,eAAeA,CAACC,aAAkB,EAAEC,MAAc,EAAE;IAC/DC,OAAO,CAACC,GAAG,CAAC,qBAAqB,EAAEH,aAAa,CAAC;IACjD,IAAI;MACF,MAAMI,IAAI,GAAGC,IAAI,CAACC,SAAS,CAAC;QAC1BC,cAAc,EAAEP,aAAa,EAAEI,IAAI,EAAEI,eAAe;QAAE;QACtDC,aAAa,EAAE;MACjB,CAAC,CAAC;MAEF,MAAMC,MAAM,GAAG;QACbC,MAAM,EAAE,MAAe;QACvBC,aAAa,EAAEC,QAAQ;QACvBC,GAAG,EAAE,sDAAsD;QAC3DC,OAAO,EAAE;UACP,cAAc,EAAE,kBAAkB;UAClC,QAAQ,EACN;QACJ,CAAC;QACDX;MACF,CAAC;MAED,MAAMY,QAAQ,GAAG,MAAMxB,KAAK,CAACyB,OAAO,CAACP,MAAM,CAAC;MAC5CR,OAAO,CAACC,GAAG,CAAC,uBAAuB,EAAEa,QAAQ,CAAC;MAE9CnB,YA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AO,EAAEC,QAAQ,IAC7ClG,aAAa,CAACmF,YAAY,EAAEe,QAAQ,IACpClG,aAAa,CAACmF,YAAY,EAAEgB,GAAG,EAAEC,WAAW,GAAG,CAAC,CAAC,EAAEtF,GAAG;IAExDjB,YAAY,CAACC,QAAQ,CACnB;MACEwG,KAAK,EAAEtG,aAAa,CAACmF,YAAY,EAAEmB,KAAK;MACxCC,IAAI,EAAEvG,aAAa,CAACmF,YAAY,EAAEoB,IAAI;MACtCnG,IAAI,EAAEJ,aAAa,CAACI,IAAI;MACxB2F,KAAK;MACLT,KAAK,EAAEtF,aAAa,CAACI,IAAI,EAAEkF;IAC7B,CAAC,EACD3B,IACF,CAAC;EACH;AACF;AAEA,eAAe9D,YAAY","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,7 @@
1
+ import { type TurboModule } from 'react-native';
2
+ export interface Spec extends TurboModule {
3
+ multiply(a: number, b: number): number;
4
+ }
5
+ declare const _default: Spec;
6
+ export default _default;
7
+ //# sourceMappingURL=NativeNotifySphere.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeNotifySphere.d.ts","sourceRoot":"","sources":["../../../src/NativeNotifySphere.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACxC;;AAED,wBAAsE"}
@@ -0,0 +1,44 @@
1
+ type NotificationData = {
2
+ title?: string;
3
+ body?: string;
4
+ data?: any;
5
+ image?: string;
6
+ sound?: string;
7
+ };
8
+ type Tags = {
9
+ [key: string]: string;
10
+ };
11
+ type NotificationCallback = (notification: NotificationData, type?: string) => void;
12
+ declare class NotifySphere {
13
+ private static callback;
14
+ static callbackOnpress(remoteMessage: any, status: string): Promise<void>;
15
+ static checkApplicationPermission(): Promise<boolean>;
16
+ static getDeviceInfo(): Promise<{
17
+ sdk: string;
18
+ device_model: string;
19
+ device_os: string;
20
+ device_version: string;
21
+ carrier: string;
22
+ app_version: string;
23
+ timezone_id: string;
24
+ }>;
25
+ static initialize(config: {
26
+ applicationUserId: number;
27
+ type: string;
28
+ name?: string;
29
+ lat?: string;
30
+ long?: string;
31
+ city?: string;
32
+ state?: string;
33
+ email?: string;
34
+ appId?: string;
35
+ phone?: number;
36
+ tags?: Tags;
37
+ }): Promise<any>;
38
+ static onNotification(callback: NotificationCallback): void;
39
+ private static setupListeners;
40
+ private static displayLocalNotification;
41
+ private static sendCallback;
42
+ }
43
+ export default NotifySphere;
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAUA,KAAK,gBAAgB,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,IAAI,GAAG;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,oBAAoB,GAAG,CAC1B,YAAY,EAAE,gBAAgB,EAC9B,IAAI,CAAC,EAAE,MAAM,KACV,IAAI,CAAC;AAEV,cAAM,YAAY;IAChB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAqC;WAI/C,eAAe,CAAC,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM;WA6BlD,0BAA0B,IAAI,OAAO,CAAC,OAAO,CAAC;WAsB9C,aAAa;;;;;;;;;WAYb,UAAU,CAAC,MAAM,EAAE;QAC9B,iBAAiB,EAAE,MAAM,CAAC;QAC1B,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAC,IAAI,CAAA;KACX;IAoDD,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,oBAAoB;IAIpD,OAAO,CAAC,MAAM,CAAC,cAAc;mBAoCR,wBAAwB;IA8C7C,OAAO,CAAC,MAAM,CAAC,YAAY;CAmB5B;AAED,eAAe,YAAY,CAAC"}
package/package.json ADDED
@@ -0,0 +1,171 @@
1
+ {
2
+ "name": "react-native-notify-sphere",
3
+ "version": "1.0.0",
4
+ "description": "Notify sphere npm package",
5
+ "main": "./lib/module/index",
6
+ "private": false,
7
+ "types": "lib/typescript/src/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "*.podspec",
17
+ "react-native.config.js",
18
+ "!ios/build",
19
+ "!android/build",
20
+ "!android/gradle",
21
+ "!android/gradlew",
22
+ "!android/gradlew.bat",
23
+ "!android/local.properties",
24
+ "!**/__tests__",
25
+ "!**/__fixtures__",
26
+ "!**/__mocks__",
27
+ "!**/.*"
28
+ ],
29
+ "scripts": {
30
+ "example": "yarn workspace react-native-notify-sphere-example",
31
+ "test": "jest",
32
+ "typecheck": "tsc",
33
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
34
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
35
+ "prepare": "bob build",
36
+ "release": "release-it --only-version"
37
+ },
38
+ "keywords": [
39
+ "react-native",
40
+ "ios",
41
+ "android"
42
+ ],
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "git+https://github.com/SandeepTribond/NotifySphere.git"
46
+ },
47
+ "author": "Tribond Infosystem Pvt. Ltd.",
48
+ "license": "MIT",
49
+ "bugs": {
50
+ "url": "https://github.com/SandeepTribond/NotifySphere.git/issues"
51
+ },
52
+ "homepage": "https://github.com/SandeepTribond/NotifySphere.git#readme",
53
+ "publishConfig": {
54
+ "registry": "https://registry.npmjs.org/"
55
+ },
56
+ "devDependencies": {
57
+ "@commitlint/config-conventional": "^19.8.1",
58
+ "@eslint/compat": "^1.3.2",
59
+ "@eslint/eslintrc": "^3.3.1",
60
+ "@eslint/js": "^9.35.0",
61
+ "@evilmartians/lefthook": "^1.12.3",
62
+ "@react-native-community/cli": "20.0.1",
63
+ "@react-native-firebase/app": "^22.2.1",
64
+ "@react-native-firebase/messaging": "^22.2.1",
65
+ "@react-native/babel-preset": "0.81.1",
66
+ "@react-native/eslint-config": "^0.81.1",
67
+ "@release-it/conventional-changelog": "^10.0.1",
68
+ "@types/jest": "^29.5.14",
69
+ "@types/react": "^19.1.0",
70
+ "commitlint": "^19.8.1",
71
+ "del-cli": "^6.0.0",
72
+ "eslint": "^9.35.0",
73
+ "eslint-config-prettier": "^10.1.8",
74
+ "eslint-plugin-prettier": "^5.5.4",
75
+ "jest": "^29.7.0",
76
+ "prettier": "^3.6.2",
77
+ "react": "19.1.0",
78
+ "react-native": "0.81.1",
79
+ "react-native-builder-bob": "^0.40.13",
80
+ "react-native-device-info": "^15.0.1",
81
+ "react-native-localize": "^3.6.1",
82
+ "release-it": "^19.0.4",
83
+ "turbo": "^2.5.6",
84
+ "typescript": "^5.9.2"
85
+ },
86
+ "peerDependencies": {
87
+ "@react-native-firebase/app": "^22.2.1",
88
+ "@react-native-firebase/messaging": "^22.2.1",
89
+ "react": "*",
90
+ "react-native": "*",
91
+ "react-native-device-info": "^15.0.1",
92
+ "react-native-localize": "^3.6.0"
93
+ },
94
+ "workspaces": [
95
+ "example"
96
+ ],
97
+ "packageManager": "yarn@3.6.1",
98
+ "jest": {
99
+ "preset": "react-native",
100
+ "modulePathIgnorePatterns": [
101
+ "<rootDir>/example/node_modules",
102
+ "<rootDir>/lib/"
103
+ ]
104
+ },
105
+ "commitlint": {
106
+ "extends": [
107
+ "@commitlint/config-conventional"
108
+ ]
109
+ },
110
+ "release-it": {
111
+ "git": {
112
+ "commitMessage": "chore: release ${version}",
113
+ "tagName": "v${version}"
114
+ },
115
+ "npm": {
116
+ "publish": true
117
+ },
118
+ "github": {
119
+ "release": true
120
+ },
121
+ "plugins": {
122
+ "@release-it/conventional-changelog": {
123
+ "preset": {
124
+ "name": "angular"
125
+ }
126
+ }
127
+ }
128
+ },
129
+ "prettier": {
130
+ "quoteProps": "consistent",
131
+ "singleQuote": true,
132
+ "tabWidth": 2,
133
+ "trailingComma": "es5",
134
+ "useTabs": false
135
+ },
136
+ "react-native-builder-bob": {
137
+ "source": "src",
138
+ "output": "lib",
139
+ "targets": [
140
+ [
141
+ "module",
142
+ {
143
+ "esm": true
144
+ }
145
+ ],
146
+ [
147
+ "typescript",
148
+ {
149
+ "project": "tsconfig.build.json"
150
+ }
151
+ ]
152
+ ]
153
+ },
154
+ "codegenConfig": {
155
+ "name": "NotifySphereSpec",
156
+ "type": "modules",
157
+ "jsSrcsDir": "src",
158
+ "android": {
159
+ "javaPackageName": "com.notifysphere"
160
+ }
161
+ },
162
+ "create-react-native-library": {
163
+ "languages": "kotlin-objc",
164
+ "type": "turbo-module",
165
+ "version": "0.54.2"
166
+ },
167
+ "dependencies": {
168
+ "@notifee/react-native": "^9.1.8",
169
+ "axios": "^1.12.2"
170
+ }
171
+ }
@@ -0,0 +1,7 @@
1
+ import { TurboModuleRegistry, type TurboModule } from 'react-native';
2
+
3
+ export interface Spec extends TurboModule {
4
+ multiply(a: number, b: number): number;
5
+ }
6
+
7
+ export default TurboModuleRegistry.getEnforcing<Spec>('NotifySphere');
package/src/index.tsx ADDED
@@ -0,0 +1,267 @@
1
+ import messaging from '@react-native-firebase/messaging';
2
+ import notifee, {
3
+ AndroidImportance,
4
+ AndroidStyle,
5
+ EventType, // Import EventType if available
6
+ } from '@notifee/react-native';
7
+ import axios from 'axios';
8
+ import { PermissionsAndroid, Platform } from 'react-native';
9
+ import DeviceInfo from "react-native-device-info";
10
+ import * as RNLocalize from "react-native-localize";
11
+ type NotificationData = {
12
+ title?: string;
13
+ body?: string;
14
+ data?: any;
15
+ image?: string;
16
+ sound?: string;
17
+ };
18
+
19
+ type Tags = {
20
+ [key: string]: string;
21
+ };
22
+
23
+ type NotificationCallback = (
24
+ notification: NotificationData,
25
+ type?: string
26
+ ) => void;
27
+
28
+ class NotifySphere {
29
+ private static callback: NotificationCallback | null = null;
30
+
31
+ // ✅ Permission check remains fully here
32
+
33
+ static async callbackOnpress(remoteMessage: any, status: string) {
34
+ console.log('remoteMessage413123', remoteMessage);
35
+ try {
36
+ const data = JSON.stringify({
37
+ notifiction_id: remoteMessage?.data?.notification_id, // 🔑 keep same spelling as backend expects
38
+ onPressStatus: 1,
39
+ });
40
+
41
+ const config = {
42
+ method: 'post' as const,
43
+ maxBodyLength: Infinity,
44
+ url: 'https://notifysphere.dothejob.in:3008/onpress/handle',
45
+ headers: {
46
+ 'Content-Type': 'application/json',
47
+ 'Cookie':
48
+ 'token=sYPT8POivlxfFSR54MWd3reaArvODMiIcM4KM39cqkXBLVu%2B8b1zV2csabU9byzo',
49
+ },
50
+ data,
51
+ };
52
+
53
+ const response = await axios.request(config);
54
+ console.log('onPress API response:', response);
55
+
56
+ NotifySphere.sendCallback(remoteMessage, status);
57
+ } catch (error) {
58
+ console.error('Error in callbackOnpress:', error);
59
+ }
60
+ }
61
+
62
+ static async checkApplicationPermission(): Promise<boolean> {
63
+ try {
64
+ if (Platform.OS === 'android' && Platform.Version >= 33) {
65
+ const granted = await PermissionsAndroid.request(
66
+ PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS
67
+ );
68
+ return granted === PermissionsAndroid.RESULTS.GRANTED;
69
+ } else if (Platform.OS === 'ios') {
70
+ const authStatus = await messaging().requestPermission();
71
+ return (
72
+ authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
73
+ authStatus === messaging.AuthorizationStatus.PROVISIONAL
74
+ );
75
+ }
76
+ return true;
77
+ } catch (error) {
78
+ console.error('Error requesting notification permission:', error);
79
+ return false;
80
+ }
81
+ }
82
+
83
+
84
+ static async getDeviceInfo() {
85
+ return {
86
+ sdk: DeviceInfo.getApiLevel()?.toString(), // e.g. "34"
87
+ device_model: DeviceInfo.getModel(), // e.g. "iPhone 14" or "TECNO CK6"
88
+ device_os: DeviceInfo.getSystemName(), // e.g. "Android" or "iOS"
89
+ device_version: DeviceInfo.getSystemVersion(), // e.g. "15"
90
+ carrier: await DeviceInfo.getCarrier(), // e.g. "airtel"
91
+ app_version: DeviceInfo.getVersion(), // e.g. "1.0.2"
92
+ timezone_id: RNLocalize.getTimeZone(), // e.g. "Asia/Kolkata"
93
+ };
94
+ }
95
+
96
+ static async initialize(config: {
97
+ applicationUserId: number;
98
+ type: string;
99
+ name?: string;
100
+ lat?: string;
101
+ long?: string;
102
+ city?: string;
103
+ state?: string;
104
+ email?: string;
105
+ appId?: string;
106
+ phone?: number;
107
+ tags?:Tags
108
+ }) {
109
+ const hasPermission = await NotifySphere.checkApplicationPermission();
110
+ const devInfo = await NotifySphere.getDeviceInfo();
111
+ if (!hasPermission) return;
112
+
113
+ const fcmToken = await messaging().getToken();
114
+ console.log('fcmToken31232', fcmToken, config);
115
+
116
+ if (!config.appId) return;
117
+
118
+ let subscription_id = await axios
119
+ .post(
120
+ `https://notifysphere.dothejob.in:3008/apps/${config.appId}/users`,
121
+ {
122
+ applicationUserId: config.applicationUserId,
123
+ token: fcmToken,
124
+ type: config.type,
125
+ user: {
126
+ userName: config.name,
127
+ lat: config.lat,
128
+ long: config.long,
129
+ city: config.city,
130
+ state: config.state,
131
+ email: config.email,
132
+ phone: config.phone,
133
+ tags: config.tags,
134
+ sdk: devInfo.sdk,
135
+ device_model: devInfo.device_model,
136
+ device_os: devInfo.device_os,
137
+ device_version: devInfo.device_version,
138
+ carrier: devInfo.carrier,
139
+ app_version: devInfo.app_version,
140
+ timezone_id: devInfo.timezone_id
141
+ },
142
+ },
143
+ {
144
+ headers: { 'Content-Type': 'application/json' },
145
+ maxBodyLength: Infinity,
146
+ }
147
+ )
148
+ .then(async (res: any) => {
149
+ console.log('res313132', res);
150
+ return res.data.subscription_id;
151
+ })
152
+ .catch((err) => {
153
+ console.log('err31232', err);
154
+ });
155
+
156
+ NotifySphere.setupListeners();
157
+ return subscription_id;
158
+ }
159
+
160
+ static onNotification(callback: NotificationCallback) {
161
+ NotifySphere.callback = callback;
162
+ }
163
+
164
+ private static setupListeners() {
165
+ messaging().onMessage(async (remoteMessage) => {
166
+ await NotifySphere.displayLocalNotification(remoteMessage);
167
+ });
168
+
169
+ messaging().onNotificationOpenedApp(async (remoteMessage: any) => {
170
+ console.log('data34234', remoteMessage);
171
+ NotifySphere.callbackOnpress(remoteMessage, 'opened');
172
+ });
173
+
174
+ messaging()
175
+ .getInitialNotification()
176
+ .then((remoteMessage) => {
177
+ if (remoteMessage) {
178
+ NotifySphere.callbackOnpress(remoteMessage, 'initial');
179
+ }
180
+ });
181
+
182
+ notifee.onForegroundEvent(({ type, detail }) => {
183
+ if (type === EventType.PRESS) {
184
+ console.log('detail323213', detail);
185
+ NotifySphere.callbackOnpress(detail.notification, 'opened');
186
+ }
187
+ });
188
+
189
+ notifee.onBackgroundEvent(async ({ type, detail }) => {
190
+ console.log('detail323213111111', type, detail);
191
+
192
+ if (type === EventType.PRESS) {
193
+ console.log('detail323213', detail);
194
+
195
+ NotifySphere.callbackOnpress(detail.notification, 'press');
196
+ }
197
+ });
198
+ }
199
+
200
+ private static async displayLocalNotification(remoteMessage: any) {
201
+ const soundRaw = remoteMessage.data?.sound || 'default';
202
+ const androidChannelId = `channel_${soundRaw}`;
203
+ const androidSoundName = soundRaw.replace(/\..+$/, '');
204
+ console.log('remoteMessage1312', remoteMessage);
205
+
206
+ await notifee.createChannel({
207
+ id: androidChannelId,
208
+ name: `Channel ${androidSoundName}`,
209
+ importance: AndroidImportance.HIGH,
210
+ sound: androidSoundName !== 'default' ? androidSoundName : undefined,
211
+ });
212
+
213
+ const image =
214
+ remoteMessage?.data?.fcm_options?.image ||
215
+ remoteMessage.notification?.android?.imageUrl ||
216
+ remoteMessage.notification?.imageUrl ||
217
+ remoteMessage.notification?.ios?.attachments?.[0]?.url;
218
+ await notifee.displayNotification({
219
+ title: remoteMessage.notification?.title,
220
+ body: remoteMessage.notification?.body,
221
+ android: {
222
+ channelId: androidChannelId,
223
+ importance: AndroidImportance.HIGH,
224
+ sound: androidSoundName !== 'default' ? androidSoundName : undefined,
225
+ largeIcon: image,
226
+ style: image
227
+ ? {
228
+ type: AndroidStyle.BIGPICTURE,
229
+ picture: image,
230
+ }
231
+ : undefined,
232
+ },
233
+ ios: {
234
+ sound: soundRaw, // must be a bundled sound file or "default"
235
+ attachments: image ? [{ url: image }] : undefined, // ✅ this is correct
236
+ foregroundPresentationOptions: {
237
+ alert: true,
238
+ badge: true,
239
+ sound: true,
240
+ },
241
+ },
242
+ data: remoteMessage.data,
243
+ });
244
+ }
245
+
246
+ private static sendCallback(remoteMessage: any, type?: string) {
247
+ if (!NotifySphere.callback) return;
248
+
249
+ const image =
250
+ remoteMessage.notification?.android?.imageUrl ||
251
+ remoteMessage.notification?.imageUrl ||
252
+ remoteMessage.notification?.ios?.attachments?.[0]?.url;
253
+
254
+ NotifySphere.callback(
255
+ {
256
+ title: remoteMessage.notification?.title,
257
+ body: remoteMessage.notification?.body,
258
+ data: remoteMessage.data,
259
+ image,
260
+ sound: remoteMessage.data?.sound,
261
+ },
262
+ type
263
+ );
264
+ }
265
+ }
266
+
267
+ export default NotifySphere;