Block outgoing SIP messages like INVITE or chat messages if linphonecore.isNetworkUnreachable
This commit is contained in:
parent
275131cb00
commit
55e3400a54
4 changed files with 34 additions and 15 deletions
|
@ -364,6 +364,7 @@
|
|||
<string name="error_user_not_found">Utilisateur non trouvé</string>
|
||||
<string name="error_incompatible_media">Paramètres média incompatibles</string>
|
||||
<string name="error_low_bandwidth">Votre correspondant à un débit faible, la vidéo ne peut démarrer</string>
|
||||
<string name="error_network_unreachable">Le réseau n\'est pas joignable</string>
|
||||
|
||||
<string name="today">Aujourd\'hui</string>
|
||||
<string name="yesterday">Hier</string>
|
||||
|
|
|
@ -411,6 +411,7 @@
|
|||
<string name="error_user_not_found">User not found</string>
|
||||
<string name="error_incompatible_media">Incompatible media parameters</string>
|
||||
<string name="error_low_bandwidth">Your correspondent has low bandwidth, video can\'t be started</string>
|
||||
<string name="error_network_unreachable">Network is unreachable</string>
|
||||
|
||||
<string name="today">Today</string>
|
||||
<string name="yesterday">Yesterday</string>
|
||||
|
|
|
@ -458,7 +458,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
}
|
||||
|
||||
private void sendTextMessage() {
|
||||
if (chatRoom != null && message != null && message.getText().length() > 0) {
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();
|
||||
|
||||
if (chatRoom != null && message != null && message.getText().length() > 0 && isNetworkReachable) {
|
||||
String messageToSend = message.getText().toString();
|
||||
message.setText("");
|
||||
|
||||
|
@ -472,11 +475,16 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
|
||||
displayMessage(newId, messageToSend, String.valueOf(System.currentTimeMillis()), false, State.InProgress, messagesLayout);
|
||||
scrollToEnd();
|
||||
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendImageMessage(String url, Bitmap bitmap) {
|
||||
if (chatRoom != null && url != null && url.length() > 0) {
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
boolean isNetworkReachable = lc == null ? false : lc.isNetworkReachable();
|
||||
|
||||
if (chatRoom != null && url != null && url.length() > 0 && isNetworkReachable) {
|
||||
LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage("");
|
||||
chatMessage.setExternalBodyUrl(url);
|
||||
chatRoom.sendMessage(chatMessage, this);
|
||||
|
@ -489,6 +497,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
|
||||
displayImageMessage(newId, bitmap, String.valueOf(System.currentTimeMillis()), false, State.InProgress, messagesLayout);
|
||||
scrollToEnd();
|
||||
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -277,20 +278,26 @@ public final class LinphoneManager implements LinphoneCoreListener {
|
|||
|
||||
boolean isLowBandwidthConnection = !LinphoneUtils.isHightBandwidthConnection(LinphoneService.instance().getApplicationContext());
|
||||
|
||||
try {
|
||||
if (Version.isVideoCapable()) {
|
||||
boolean prefVideoEnable = isVideoEnabled();
|
||||
int key = R.string.pref_video_initiate_call_with_video_key;
|
||||
boolean prefInitiateWithVideo = getPrefBoolean(key, false);
|
||||
CallManager.getInstance().inviteAddress(lAddress, prefVideoEnable && prefInitiateWithVideo, isLowBandwidthConnection);
|
||||
} else {
|
||||
CallManager.getInstance().inviteAddress(lAddress, false, isLowBandwidthConnection);
|
||||
if (mLc.isNetworkReachable()) {
|
||||
try {
|
||||
if (Version.isVideoCapable()) {
|
||||
boolean prefVideoEnable = isVideoEnabled();
|
||||
int key = R.string.pref_video_initiate_call_with_video_key;
|
||||
boolean prefInitiateWithVideo = getPrefBoolean(key, false);
|
||||
CallManager.getInstance().inviteAddress(lAddress, prefVideoEnable && prefInitiateWithVideo, isLowBandwidthConnection);
|
||||
} else {
|
||||
CallManager.getInstance().inviteAddress(lAddress, false, isLowBandwidthConnection);
|
||||
}
|
||||
|
||||
|
||||
} catch (LinphoneCoreException e) {
|
||||
mListenerDispatcher.tryingNewOutgoingCallButCannotGetCallParameters();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
} catch (LinphoneCoreException e) {
|
||||
mListenerDispatcher.tryingNewOutgoingCallButCannotGetCallParameters();
|
||||
return;
|
||||
} else if (LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
|
||||
} else {
|
||||
Log.e("Error: " + getString(R.string.error_network_unreachable));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue