Skip to content
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

CallMessageListener does not work for incoming calls #611

Closed
amritashan opened this issue Jun 28, 2024 · 2 comments
Closed

CallMessageListener does not work for incoming calls #611

amritashan opened this issue Jun 28, 2024 · 2 comments

Comments

@amritashan
Copy link

Description

My telephony platform uses in-call messaging to communicate about various call states during a call.

The call-message implementation on the javascript counterpart works quite well and the app is able to receive and send messages for both incoming calls and outgoing calls.

The same, however, is not working for Android (as well as iOS). While I am able to send and receive messages for outgoing calls, incoming calls do not work at all.

Code

CallMessageListener implementation

public class TwilioCallMessageListener implements Call.CallMessageListener {
  private static final String TAG = TwilioCallMessageListener.class.getSimpleName();

  @Override
  public void onMessageReceived(String callSid, CallMessage callMesssage) {
    Log.d(TAG, "Message received");
  }

  @Override
  public void onMessageSent(String callSid, String voiceEventSID) {
    Log.d(TAG, "message sent. voiceEventSID: " + voiceEventSID);
  }

  @Override
  public void onMessageFailure(String callSid, String voiceEventSID, VoiceException error) {
    Log.e(TAG, "message failed. voiceEventSID: " + voiceEventSID + ", error: " + error.getMessage());
  }
}

FirebaseMessagingService

public class TwilioFirebaseMessagingService extends FirebaseMessagingService {
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    Log.d(TAG, "Received onMessageReceived()");
    Log.d(TAG, "Bundle data: " + remoteMessage.getData());
    Log.d(TAG, "From: " + remoteMessage.getFrom());
    Log.d(TAG, "Bundle data size: " + remoteMessage.getData().size());

    // Check if message contains a data payload.
    if (remoteMessage.getData().size() > 0) {
      boolean valid = Voice.handleMessage(this, remoteMessage.getData(), new MessageListener() {
        @Override
        public void onCallInvite(@NonNull CallInvite callInvite) {
          Log.d(TAG, "[onCallInvite] " + callInvite.getCallSid());
          final int notificationId = (int) System.currentTimeMillis();
          handleInvite(callInvite, notificationId);
        }

        @Override
        public void onCancelledCallInvite(@NonNull CancelledCallInvite cancelledCallInvite, @Nullable CallException callException) {
          handleCanceledCallInvite(cancelledCallInvite);
        }
      }, new TwilioCallMessageListener());

      if (!valid) {
        Log.e(TAG, "The message was not a valid Twilio Voice SDK payload: " +
          remoteMessage.getData());
      }
    }
  }
}

MainActivity

public class MainActivity {
  ...
  ...
  void call() {
   ...
   ...
    ConnectOptions connectOptions = new ConnectOptions.Builder(mainActivity.getAccessToken())
          .params(callParams)
          .callMessageListener(new TwilioCallMessageListener())
          .build();

   Call call = Voice.connect(mainActivity, connectOptions, new CallListener());
  ...
  ...
  }
  ...
  ...
}

Expected Behavior

For outbound and inbound calls, the TwilioCallMessageListener.onMessageReceived() gets called.

Actual Behavior

TwilioCallMessageListener.onMessageReceived() gets called only for outbound calls.

For incoming calls, the interface implementation never gets called.

Reproduces How Often

100%

Twilio Call SID(s)

N/A

Logs

N/A

Versions

minSdkVersion = 26
compileSdkVersion = 34
targetSdkVersion = 33

Voice Android SDK

com.twilio:voice-android:6.5.0

OS Version

Android 14, Build AP2A.240605.024

Device Model

Pixel 8 Pro

@afalls-twilio
Copy link
Contributor

afalls-twilio commented Jul 8, 2024

@amritashan

Are you also registering a TwilioCallMessageListener() object with your accept options when you accept an incoming call?

@afalls-twilio
Copy link
Contributor

Closing due to a lack of customer engagement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants