Releases: react-native-webrtc/react-native-voip-push-notification
Release 3.3.1
Release 3.3.0
Change
- typescript support
- Fix singletone class initialisation
3.3.0
452dc9c release 3.3.0 ( zxcpoiu 2021-05-20 02:28:56 -0700)
3e7f1a8 misc: normalize package.json ( zxcpoiu 2021-05-20 01:50:13 -0700)
c299bae #86 Fix singletone class initialisation (#87) ( Romick2005 2021-05-19 11:37:06 +0300)
3.2.0
54356e0 release 3.2.0 ( zxcpoiu 2021-04-17 02:12:48 +0800)
99feae8 feat: add typescript support ( dayze 2021-02-23 11:36:48 +0100)
Release 3.1.0
release 3.1.0
- remove unused import
- cache lastVoipToken and return it when subsequently call to
registerVoipToken
on JS (will fireregister
event with the cached token immediately, note it may be empty if no token at all)
detailed in #80
Change Log
35a4fe0 readme: update doc for registerVoipToken
will fire cached token ( zxcpoiu 2021-01-15 19:03:13 +0800)
bb5485b remove unused import ( zxcpoiu 2021-01-15 18:44:22 +0800)
3d1b675 cache lastVoipToken and return it when subsequently call to registerVoipToken ( zxcpoiu 2021-01-15 18:15:55 +0800)
ab54fd9 readme: update usage doc add some notes ( zxcpoiu 2020-12-08 16:16:07 +0800)
Release 3.0.0
Breaking Change:
Removal and Deprecation
remove unused codes, keep this lib simple, lots functionalities should be easily implemented in the modern RN eco system
- remove
requestPermission
( should usePushNotificationIOS
instead if needed ) - remove
wakeupByPush
constant with push event ( should useAppState
instead if needed )
Changes:
- use
NativeEventEmitter
instead the deprecatedDeviceEventEmitter
- tweak event handler logic
- support caching events before js initialize
you can subscribedidLoadWithEvents
when app ready
Upgrade Guide:
- remove deprecation functions or use corresponded 3rd party library to implement it
- Follow the new doc in README to tweak your logic
Mainly, you just have to subscribe a new event didLoadWithEvent
, which helps you to catch the initial event before JS bridge initialed.
This event
NOTE: You still need to subscribe / handle the rest events as usuall. This is just a helper whcih cache and propagate early fired events if and only if for "the native events which DID fire BEFORE js bridge is initialed", it does NOT mean this will have events each time when the app reopened.
For the discussion, see #69
Doc copied from the readme at the time of writing below
API and Usage:
Native API:
Voip Push is time sensitive, these native API mainly used in AppDelegate.m, especially before JS bridge is up.
This usually
(void)voipRegistration
---
register delegate for PushKit if you like to register in AppDelegate.m ASAP instead JS side ( too late for some use cases )(void)didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
---
call this api to fire 'register' event to JS(void)didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
---
call this api to fire 'notification' event to JS(void)addCompletionHandler:(NSString *)uuid completionHandler:(RNVoipPushNotificationCompletion)completionHandler
---
add completionHandler to RNVoipPush module(void)removeCompletionHandler:(NSString *)uuid
---
remove completionHandler to RNVoipPush module
JS API:
registerVoipToken()
--- JS method to register PushKit delegateonVoipNotificationCompleted(notification.uuid)
--- JS mehtod to tell PushKit we have handled received voip push
Events:
'register'
--- fired when PushKit give us the latest token'notification'
--- fired when received voip push notification'didLoadWithEvents'
--- fired when there are not-fired events been cached before js bridge is up
JS usage
...
import VoipPushNotification from 'react-native-voip-push-notification';
...
class MyComponent extends React.Component {
...
// --- anywhere which is most comfortable and appropriate for you,
// --- usually ASAP, ex: in your app.js or at some global scope.
componentDidMount() {
// --- NOTE: You still need to subscribe / handle the rest events as usuall.
// --- This is just a helper whcih cache and propagate early fired events if and only if for
// --- "the native events which DID fire BEFORE js bridge is initialed",
// --- it does NOT mean this will have events each time when the app reopened.
// ===== Step 1: subscribe `register` event =====
// --- this.onVoipPushNotificationRegistered
VoipPushNotification.addEventListener('register', (token) => {
// --- send token to your apn provider server
});
// ===== Step 2: subscribe `notification` event =====
// --- this.onVoipPushNotificationiReceived
VoipPushNotification.addEventListener('notification', (notification) => {
// --- when receive remote voip push, register your VoIP client, show local notification ... etc
this.doSomething();
// --- optionally, if you `addCompletionHandler` from the native side, once you have done the js jobs to initiate a call, call `completion()`
VoipPushNotification.onVoipNotificationCompleted(notification.uuid);
});
// ===== Step 3: subscribe `didLoadWithEvents` event =====
VoipPushNotification.addEventListener('didLoadWithEvents', (events) => {
// --- this will fire when there are events occured before js bridge initialized
// --- use this event to execute your event handler manually by event type
if (!events || !Array.isArray(events) || events.length < 1) {
return;
}
for (let voipPushEvent of events) {
let { name, data } = voipPushEvent;
if (name === VoipPushNotification.RNVoipPushRemoteNotificationsRegisteredEvent) {
this.onVoipPushNotificationRegistered(data);
} else if (name === VoipPushNotification.RNVoipPushRemoteNotificationReceivedEvent) {
this.onVoipPushNotificationiReceived(data);
}
}
});
// ===== Step 4: register =====
// --- it will be no-op ( no event will be fired ) if you have subscribed before like in native side.
VoipPushNotification.registerVoipToken(); // --- register token
}
// --- unsubscribe event listeners
componentWillUnmount() {
VoipPushNotification.removeEventListener('didLoadWithEvents');
VoipPushNotification.removeEventListener('register');
VoipPushNotification.removeEventListener('notification');
}
...
}
AppDelegate.m Modification Optional Change
You can now register token ASAP in your AppDelegate.m
if you want
This is optional but recommended way
...
#import <PushKit/PushKit.h> /* <------ add this line */
#import "RNVoipPushNotificationManager.h" /* <------ add this line */
...
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
// ===== (THIS IS OPTIONAL BUT RECOMMENDED) =====
// --- register VoipPushNotification here ASAP rather than in JS. Doing this from the JS side may be too slow for some use cases
// --- see: https://github.com/react-native-webrtc/react-native-voip-push-notification/issues/59#issuecomment-691685841
[RNVoipPushNotificationManager voipRegistration];
// ===== (THIS IS OPTIONAL BUT RECOMMENDED) =====
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"AppName" initialProperties:nil];
}
2.1.0
Release 2.0.0
This is a Breaking Change
1. update pod file for RN60+
2. separate api requestPermissions() and registerVoipToken()
Original:
request permissions and register voip token in the same function
VoipPushNotification.requestPermissions();
Now:
Separate into two specific functions
VoipPushNotification.requestPermissions(); // --- optional, you can use another library to request permissions
VoipPushNotification.registerVoipToken(); // --- required