-
Notifications
You must be signed in to change notification settings - Fork 150
Added unregistration for android #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5b0d757
fdc9e44
299d172
ed67be7
8d368f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ | |
| import com.twilio.voice.LogLevel; | ||
| import com.twilio.voice.RegistrationException; | ||
| import com.twilio.voice.RegistrationListener; | ||
| import com.twilio.voice.UnregistrationListener; | ||
| import com.twilio.voice.Voice; | ||
|
|
||
| import java.util.HashMap; | ||
|
|
@@ -118,6 +119,7 @@ public class TwilioVoiceModule extends ReactContextBaseJavaModule implements Act | |
| static Map<String, Integer> callNotificationMap; | ||
|
|
||
| private RegistrationListener registrationListener = registrationListener(); | ||
| private UnregistrationListener unregistrationListener = unregistrationListener(); // | ||
| private Call.Listener callListener = callListener(); | ||
|
|
||
| private CallInvite activeCallInvite; | ||
|
|
@@ -225,6 +227,27 @@ public void onError(RegistrationException error, String accessToken, String fcmT | |
| }; | ||
| } | ||
|
|
||
| private UnregistrationListener unregistrationListener() { // | ||
ro-mgh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return new UnregistrationListener() { | ||
| @Override | ||
| public void onUnregistered(String accessToken, String fcmToken) { | ||
| if (BuildConfig.DEBUG) { | ||
| Log.d(TAG, "Successfully unregistered FCM"); | ||
| } | ||
| // eventManager.sendEvent(EVENT_DEVICE_UNREGISTERED, null); | ||
ro-mgh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| eventManager.sendEvent(EVENT_DEVICE_NOT_READY, null); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError(RegistrationException error, String accessToken, String fcmToken) { | ||
| Log.e(TAG, String.format("Unregistration Error: %d, %s", error.getErrorCode(), error.getMessage())); | ||
| WritableMap params = Arguments.createMap(); | ||
| params.putString("err", error.getMessage()); | ||
| eventManager.sendEvent(EVENT_DEVICE_NOT_READY, params); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private Call.Listener callListener() { | ||
| return new Call.Listener() { | ||
| /* | ||
|
|
@@ -618,6 +641,41 @@ public void onComplete(@NonNull Task<InstanceIdResult> task) { | |
| }); | ||
| } | ||
|
|
||
| /* | ||
| * Unregister your android device with Twilio | ||
| * | ||
| */ | ||
|
|
||
| @ReactMethod // | ||
ro-mgh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public void unregister(Promise promise) { | ||
| unregisterForCallInvites(); | ||
| WritableMap params = Arguments.createMap(); | ||
| params.putBoolean("initialized", false); | ||
| promise.resolve(params); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't you want to resolve the promise once There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jesse, you can fix this part, if you think it would be correct (or more accurate), as you know the library in more depth than I am. |
||
| } | ||
|
|
||
| private void unregisterForCallInvites() { | ||
| FirebaseInstanceId.getInstance().getInstanceId() | ||
| .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { | ||
| @Override | ||
| public void onComplete(@NonNull Task<InstanceIdResult> task) { | ||
| if (!task.isSuccessful()) { | ||
| Log.w(TAG, "getInstanceId failed", task.getException()); | ||
| return; | ||
| } | ||
|
|
||
| // Get new Instance ID token | ||
| String fcmToken = task.getResult().getToken(); | ||
| if (fcmToken != null) { | ||
| if (BuildConfig.DEBUG) { | ||
| Log.d(TAG, "Unregistering with FCM"); | ||
| } | ||
| Voice.unregister(accessToken, Voice.RegistrationChannel.FCM, fcmToken, unregistrationListener); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @ReactMethod | ||
| public void accept() { | ||
| callAccepted = true; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.