6969import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_CONNECTION_DID_CONNECT ;
7070import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_CONNECTION_DID_DISCONNECT ;
7171import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_DEVICE_DID_RECEIVE_INCOMING ;
72- import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_CALL_INVITE_CANCELLED ;
7372import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_DEVICE_NOT_READY ;
7473import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_DEVICE_READY ;
7574import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_CALL_STATE_RINGING ;
75+ import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_CALL_INVITE_CANCELLED ;
7676import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_CONNECTION_IS_RECONNECTING ;
7777import static com .hoxfon .react .RNTwilioVoice .EventManager .EVENT_CONNECTION_DID_RECONNECT ;
7878
@@ -111,7 +111,7 @@ public class TwilioVoiceModule extends ReactContextBaseJavaModule implements Act
111111 private AudioFocusRequest focusRequest ;
112112 private HeadsetManager headsetManager ;
113113 private EventManager eventManager ;
114- private int callInviteIntent ;
114+ private int existingCallInviteIntent ;
115115
116116 public TwilioVoiceModule (ReactApplicationContext reactContext ,
117117 boolean shouldAskForMicPermission ) {
@@ -170,8 +170,8 @@ public void onHostResume() {
170170 if (BuildConfig .DEBUG ) {
171171 Log .d (TAG , "Module creation " +action +". Intent " + intent .getExtras ());
172172 }
173- if (action .equals (ACTION_ACCEPT ) && callInviteIntent != currentCallInviteIntent ) {
174- callInviteIntent = currentCallInviteIntent ;
173+ if (action .equals (ACTION_ACCEPT ) && currentCallInviteIntent != existingCallInviteIntent ) {
174+ existingCallInviteIntent = currentCallInviteIntent ;
175175 handleIncomingCallIntent (intent );
176176 }
177177 }
@@ -189,6 +189,11 @@ public void onHostDestroy() {
189189 unsetAudioFocus ();
190190 }
191191
192+ @ Override
193+ public String getName () {
194+ return TAG ;
195+ }
196+
192197 @ Override
193198 public void onNewIntent (Intent intent ) {
194199 // This is called only when the App is in the foreground
@@ -198,11 +203,6 @@ public void onNewIntent(Intent intent) {
198203 handleIncomingCallIntent (intent );
199204 }
200205
201- @ Override
202- public String getName () {
203- return TAG ;
204- }
205-
206206 private RegistrationListener registrationListener () {
207207 return new RegistrationListener () {
208208 @ Override
@@ -698,26 +698,11 @@ public void connect(ReadableMap params) {
698698 twiMLParams .put (key , params .getString (key ));
699699 break ;
700700 default :
701- Log .d (TAG , "Could not convert with key: " + key + "." );
701+ Log .d (TAG , "Could not convert key: " + key + ". ReadableType: " + readableType . toString () );
702702 break ;
703703 }
704704 }
705705
706- // Set<IceServer> iceServers = new HashSet<>();
707- // iceServers.add(new IceServer("stun:global.stun.twilio.com:3478?transport=udp"));
708- // iceServers.add(new IceServer("turn:global.turn.twilio.com:3478?transport=udp","8e6467be547b969ad913f7bdcfb73e411b35f648bd19f2c1cb4161b4d4a067be","n8zwmkgjIOphHN93L/aQxnkUp1xJwrZVLKc/RXL0ZpM="));
709- // iceServers.add(new IceServer("turn:global.turn.twilio.com:3478?transport=tcp","8e6467be547b969ad913f7bdcfb73e411b35f648bd19f2c1cb4161b4d4a067be","n8zwmkgjIOphHN93L/aQxnkUp1xJwrZVLKc/RXL0ZpM="));
710- // iceServers.add(new IceServer("turn:global.turn.twilio.com:443?transport=tcp","8e6467be547b969ad913f7bdcfb73e411b35f648bd19f2c1cb4161b4d4a067be","n8zwmkgjIOphHN93L/aQxnkUp1xJwrZVLKc/RXL0ZpM="));
711- //
712- // IceOptions iceOptions = new IceOptions.Builder()
713- // .iceServers(iceServers)
714- // .build();
715- //
716- // ConnectOptions connectOptions = new ConnectOptions.Builder(accessToken)
717- // .iceOptions(iceOptions)
718- // .enableDscp(true)
719- // .params(twiMLParams)
720- // .build();
721706 ConnectOptions connectOptions = new ConnectOptions .Builder (accessToken )
722707 .enableDscp (true )
723708 .params (twiMLParams )
@@ -807,7 +792,7 @@ private void setAudioFocus() {
807792 }
808793 savedAudioMode = audioManager .getMode ();
809794 // Request audio focus before making any device switch
810- if (Build .VERSION .SDK_INT >= 26 ) {
795+ if (Build .VERSION .SDK_INT >= Build . VERSION_CODES . O ) {
811796 AudioAttributes playbackAttributes = new AudioAttributes .Builder ()
812797 .setUsage (AudioAttributes .USAGE_VOICE_COMMUNICATION )
813798 .setContentType (AudioAttributes .CONTENT_TYPE_SPEECH )
@@ -845,7 +830,7 @@ private void unsetAudioFocus() {
845830 return ;
846831 }
847832 audioManager .setMode (savedAudioMode );
848- if (Build .VERSION .SDK_INT >= 26 ) {
833+ if (Build .VERSION .SDK_INT >= Build . VERSION_CODES . O ) {
849834 if (focusRequest != null ) {
850835 audioManager .abandonAudioFocusRequest (focusRequest );
851836 }
@@ -864,9 +849,7 @@ private void requestPermissionForMicrophone() {
864849 return ;
865850 }
866851 if (ActivityCompat .shouldShowRequestPermissionRationale (getCurrentActivity (), Manifest .permission .RECORD_AUDIO )) {
867- // Snackbar.make(coordinatorLayout,
868- // "Microphone permissions needed. Please allow in your application settings.",
869- // SNACKBAR_DURATION).show();
852+ // TODO
870853 } else {
871854 ActivityCompat .requestPermissions (getCurrentActivity (), new String []{Manifest .permission .RECORD_AUDIO }, MIC_PERMISSION_REQUEST_CODE );
872855 }
0 commit comments