Skip to content

Commit ab54fd9

Browse files
authored
readme: update usage doc add some notes
1 parent cf1d446 commit ab54fd9

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

README.md

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ Make sure you enabled the folowing in `Xcode` -> `Signing & Capabilities`:
9797

9898

9999

100-
// ===== (THIS IS OPTIONAL) =====
100+
// ===== (THIS IS OPTIONAL BUT RECOMMENDED) =====
101101
// --- register VoipPushNotification here ASAP rather than in JS. Doing this from the JS side may be too slow for some use cases
102102
// --- see: https://github.com/react-native-webrtc/react-native-voip-push-notification/issues/59#issuecomment-691685841
103103
[RNVoipPushNotificationManager voipRegistration];
104-
// ===== (THIS IS OPTIONAL) =====
104+
// ===== (THIS IS OPTIONAL BUT RECOMMENDED) =====
105105

106106

107107

@@ -224,10 +224,33 @@ class MyComponent extends React.Component {
224224

225225
...
226226

227-
// --- or anywhere which is most comfortable and appropriate for you, usually ASAP
227+
// --- anywhere which is most comfortable and appropriate for you,
228+
// --- usually ASAP, ex: in your app.js or at some global scope.
228229
componentDidMount() {
229-
VoipPushNotification.registerVoipToken(); // --- register token
230230

231+
// --- NOTE: You still need to subscribe / handle the rest events as usuall.
232+
// --- This is just a helper whcih cache and propagate early fired events if and only if for
233+
// --- "the native events which DID fire BEFORE js bridge is initialed",
234+
// --- it does NOT mean this will have events each time when the app reopened.
235+
236+
237+
// ===== Step 1: subscribe `register` event =====
238+
// --- this.onVoipPushNotificationRegistered
239+
VoipPushNotification.addEventListener('register', (token) => {
240+
// --- send token to your apn provider server
241+
});
242+
243+
// ===== Step 2: subscribe `notification` event =====
244+
// --- this.onVoipPushNotificationiReceived
245+
VoipPushNotification.addEventListener('notification', (notification) => {
246+
// --- when receive remote voip push, register your VoIP client, show local notification ... etc
247+
this.doSomething();
248+
249+
// --- optionally, if you `addCompletionHandler` from the native side, once you have done the js jobs to initiate a call, call `completion()`
250+
VoipPushNotification.onVoipNotificationCompleted(notification.uuid);
251+
});
252+
253+
// ===== Step 3: subscribe `didLoadWithEvents` event =====
231254
VoipPushNotification.addEventListener('didLoadWithEvents', (events) => {
232255
// --- this will fire when there are events occured before js bridge initialized
233256
// --- use this event to execute your event handler manually by event type
@@ -244,20 +267,10 @@ class MyComponent extends React.Component {
244267
}
245268
}
246269
});
247-
248-
// --- onVoipPushNotificationRegistered
249-
VoipPushNotification.addEventListener('register', (token) => {
250-
// --- send token to your apn provider server
251-
});
252270

253-
// --- onVoipPushNotificationiReceived
254-
VoipPushNotification.addEventListener('notification', (notification) => {
255-
// --- when receive remote voip push, register your VoIP client, show local notification ... etc
256-
this.doSomething();
257-
258-
// --- optionally, if you `addCompletionHandler` from the native side, once you have done the js jobs to initiate a call, call `completion()`
259-
VoipPushNotification.onVoipNotificationCompleted(notification.uuid);
260-
});
271+
// ===== Step 4: register =====
272+
// --- it will be no-op ( no event will be fired ) if you have subscribed before like in native side.
273+
VoipPushNotification.registerVoipToken(); // --- register token
261274
}
262275

263276
// --- unsubscribe event listeners

0 commit comments

Comments
 (0)