12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194 |
- /*
- * Nextcloud Talk application
- *
- * @author Mario Danic
- * @author Tim Krüger
- * @author Marcel Hibbe
- * Copyright (C) 2022 Marcel Hibbe <dev@mhibbe.de>
- * Copyright (C) 2022 Tim Krüger <t@timkrueger.me>
- * Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.nextcloud.talk.activities;
- import android.Manifest;
- import android.animation.Animator;
- import android.animation.AnimatorListenerAdapter;
- import android.annotation.SuppressLint;
- import android.app.PendingIntent;
- import android.app.RemoteAction;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.content.pm.PackageManager;
- import android.content.res.Configuration;
- import android.graphics.Color;
- import android.graphics.drawable.Icon;
- import android.media.AudioAttributes;
- import android.media.MediaPlayer;
- import android.net.Uri;
- import android.os.Build;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Looper;
- import android.text.TextUtils;
- import android.util.DisplayMetrics;
- import android.util.Log;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.ViewTreeObserver;
- import android.widget.FrameLayout;
- import android.widget.RelativeLayout;
- import android.widget.Toast;
- import com.bluelinelabs.logansquare.LoganSquare;
- import com.google.android.material.dialog.MaterialAlertDialogBuilder;
- import com.nextcloud.talk.R;
- import com.nextcloud.talk.adapters.ParticipantDisplayItem;
- import com.nextcloud.talk.adapters.ParticipantsAdapter;
- import com.nextcloud.talk.api.NcApi;
- import com.nextcloud.talk.application.NextcloudTalkApplication;
- import com.nextcloud.talk.call.CallParticipant;
- import com.nextcloud.talk.call.CallParticipantList;
- import com.nextcloud.talk.call.CallParticipantModel;
- import com.nextcloud.talk.call.ReactionAnimator;
- import com.nextcloud.talk.chat.ChatActivity;
- import com.nextcloud.talk.data.user.model.User;
- import com.nextcloud.talk.databinding.CallActivityBinding;
- import com.nextcloud.talk.events.ConfigurationChangeEvent;
- import com.nextcloud.talk.events.NetworkEvent;
- import com.nextcloud.talk.events.ProximitySensorEvent;
- import com.nextcloud.talk.events.WebSocketCommunicationEvent;
- import com.nextcloud.talk.models.ExternalSignalingServer;
- import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall;
- import com.nextcloud.talk.models.json.conversations.Conversation;
- import com.nextcloud.talk.models.json.conversations.RoomOverall;
- import com.nextcloud.talk.models.json.conversations.RoomsOverall;
- import com.nextcloud.talk.models.json.generic.GenericOverall;
- import com.nextcloud.talk.models.json.participants.Participant;
- import com.nextcloud.talk.models.json.signaling.DataChannelMessage;
- import com.nextcloud.talk.models.json.signaling.NCMessagePayload;
- import com.nextcloud.talk.models.json.signaling.NCSignalingMessage;
- import com.nextcloud.talk.models.json.signaling.Signaling;
- import com.nextcloud.talk.models.json.signaling.SignalingOverall;
- import com.nextcloud.talk.models.json.signaling.settings.IceServer;
- import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall;
- import com.nextcloud.talk.raisehand.viewmodel.RaiseHandViewModel;
- import com.nextcloud.talk.signaling.SignalingMessageReceiver;
- import com.nextcloud.talk.signaling.SignalingMessageSender;
- import com.nextcloud.talk.ui.dialog.AudioOutputDialog;
- import com.nextcloud.talk.ui.dialog.MoreCallActionsDialog;
- import com.nextcloud.talk.users.UserManager;
- import com.nextcloud.talk.utils.ApiUtils;
- import com.nextcloud.talk.utils.DisplayUtils;
- import com.nextcloud.talk.utils.NotificationUtils;
- import com.nextcloud.talk.utils.VibrationUtils;
- import com.nextcloud.talk.utils.animations.PulseAnimation;
- import com.nextcloud.talk.utils.database.user.CapabilitiesUtilNew;
- import com.nextcloud.talk.utils.database.user.CurrentUserProviderNew;
- import com.nextcloud.talk.utils.permissions.PlatformPermissionUtil;
- import com.nextcloud.talk.utils.power.PowerManagerUtils;
- import com.nextcloud.talk.utils.singletons.ApplicationWideCurrentRoomHolder;
- import com.nextcloud.talk.viewmodels.CallRecordingViewModel;
- import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
- import com.nextcloud.talk.webrtc.PeerConnectionWrapper;
- import com.nextcloud.talk.webrtc.WebRtcAudioManager;
- import com.nextcloud.talk.webrtc.WebSocketConnectionHelper;
- import com.nextcloud.talk.webrtc.WebSocketInstance;
- import com.wooplr.spotlight.SpotlightView;
- import org.apache.commons.lang3.StringEscapeUtils;
- import org.greenrobot.eventbus.Subscribe;
- import org.greenrobot.eventbus.ThreadMode;
- import org.webrtc.AudioSource;
- import org.webrtc.AudioTrack;
- import org.webrtc.Camera1Enumerator;
- import org.webrtc.Camera2Enumerator;
- import org.webrtc.CameraEnumerator;
- import org.webrtc.CameraVideoCapturer;
- import org.webrtc.DefaultVideoDecoderFactory;
- import org.webrtc.DefaultVideoEncoderFactory;
- import org.webrtc.EglBase;
- import org.webrtc.Logging;
- import org.webrtc.MediaConstraints;
- import org.webrtc.MediaStream;
- import org.webrtc.PeerConnection;
- import org.webrtc.PeerConnectionFactory;
- import org.webrtc.RendererCommon;
- import org.webrtc.SurfaceTextureHelper;
- import org.webrtc.VideoCapturer;
- import org.webrtc.VideoSource;
- import org.webrtc.VideoTrack;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- import java.util.Set;
- import java.util.concurrent.TimeUnit;
- import java.util.concurrent.atomic.AtomicInteger;
- import javax.inject.Inject;
- import androidx.activity.result.ActivityResultLauncher;
- import androidx.activity.result.contract.ActivityResultContracts;
- import androidx.annotation.DrawableRes;
- import androidx.annotation.NonNull;
- import androidx.annotation.Nullable;
- import androidx.annotation.RequiresApi;
- import androidx.appcompat.app.AlertDialog;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.core.content.ContextCompat;
- import androidx.core.graphics.drawable.DrawableCompat;
- import androidx.lifecycle.ViewModelProvider;
- import autodagger.AutoInjector;
- import io.reactivex.Observable;
- import io.reactivex.Observer;
- import io.reactivex.android.schedulers.AndroidSchedulers;
- import io.reactivex.disposables.Disposable;
- import io.reactivex.schedulers.Schedulers;
- import me.zhanghai.android.effortlesspermissions.AfterPermissionDenied;
- import me.zhanghai.android.effortlesspermissions.EffortlessPermissions;
- import me.zhanghai.android.effortlesspermissions.OpenAppDetailsDialogFragment;
- import okhttp3.Cache;
- import pub.devrel.easypermissions.AfterPermissionGranted;
- import static android.app.PendingIntent.FLAG_IMMUTABLE;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CALL_VOICE_ONLY;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CALL_WITHOUT_NOTIFICATION;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_PASSWORD;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FROM_NOTIFICATION_START_CALL;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_BREAKOUT_ROOM;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_MODERATOR;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_MODIFIED_BASE_URL;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_RECORDING_STATE;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH;
- import static com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SWITCH_TO_ROOM;
- @AutoInjector(NextcloudTalkApplication.class)
- public class CallActivity extends CallBaseActivity {
- public static boolean active = false;
- public static final String VIDEO_STREAM_TYPE_SCREEN = "screen";
- public static final String VIDEO_STREAM_TYPE_VIDEO = "video";
- @Inject
- NcApi ncApi;
- @Inject
- CurrentUserProviderNew currentUserProvider;
- @Inject
- UserManager userManager;
- @Inject
- Cache cache;
- @Inject
- PlatformPermissionUtil permissionUtil;
- @Inject
- ViewModelProvider.Factory viewModelFactory;
- public static final String TAG = "CallActivity";
- public WebRtcAudioManager audioManager;
- public CallRecordingViewModel callRecordingViewModel;
- public RaiseHandViewModel raiseHandViewModel;
- private static final String[] PERMISSIONS_CALL = {
- Manifest.permission.CAMERA,
- Manifest.permission.RECORD_AUDIO
- };
- private static final String[] PERMISSIONS_CAMERA = {
- Manifest.permission.CAMERA
- };
- private static final String[] PERMISSIONS_MICROPHONE = {
- Manifest.permission.RECORD_AUDIO
- };
- private static final String MICROPHONE_PIP_INTENT_NAME = "microphone_pip_intent";
- private static final String MICROPHONE_PIP_INTENT_EXTRA_ACTION = "microphone_pip_action";
- private static final int MICROPHONE_PIP_REQUEST_MUTE = 1;
- private static final int MICROPHONE_PIP_REQUEST_UNMUTE = 2;
- private BroadcastReceiver mReceiver;
- private PeerConnectionFactory peerConnectionFactory;
- private MediaConstraints audioConstraints;
- private MediaConstraints videoConstraints;
- private MediaConstraints sdpConstraints;
- private MediaConstraints sdpConstraintsForMCU;
- private VideoSource videoSource;
- private VideoTrack localVideoTrack;
- private AudioSource audioSource;
- private AudioTrack localAudioTrack;
- private VideoCapturer videoCapturer;
- private EglBase rootEglBase;
- private Disposable signalingDisposable;
- private List<PeerConnection.IceServer> iceServers;
- private CameraEnumerator cameraEnumerator;
- private String roomToken;
- public User conversationUser;
- private String conversationName;
- private String callSession;
- private MediaStream localStream;
- private String credentials;
- private List<PeerConnectionWrapper> peerConnectionWrapperList = new ArrayList<>();
- private boolean videoOn = false;
- private boolean microphoneOn = false;
- private boolean isVoiceOnlyCall;
- private boolean isCallWithoutNotification;
- private boolean isIncomingCallFromNotification;
- private Handler callControlHandler = new Handler();
- private Handler callInfosHandler = new Handler();
- private Handler cameraSwitchHandler = new Handler();
- // push to talk
- private boolean isPushToTalkActive = false;
- private PulseAnimation pulseAnimation;
- private String baseUrl;
- private String roomId;
- private SpotlightView spotlightView;
- private InternalSignalingMessageReceiver internalSignalingMessageReceiver = new InternalSignalingMessageReceiver();
- private SignalingMessageReceiver signalingMessageReceiver;
- private InternalSignalingMessageSender internalSignalingMessageSender = new InternalSignalingMessageSender();
- private SignalingMessageSender signalingMessageSender;
- private Map<String, OfferAnswerNickProvider> offerAnswerNickProviders = new HashMap<>();
- private Map<String, SignalingMessageReceiver.CallParticipantMessageListener> callParticipantMessageListeners =
- new HashMap<>();
- private PeerConnectionWrapper.PeerConnectionObserver selfPeerConnectionObserver = new CallActivitySelfPeerConnectionObserver();
- private Map<String, CallParticipant> callParticipants = new HashMap<>();
- private Map<String, ScreenParticipantDisplayItemManager> screenParticipantDisplayItemManagers = new HashMap<>();
- private Handler screenParticipantDisplayItemManagersHandler = new Handler(Looper.getMainLooper());
- private Map<String, CallParticipantEventDisplayer> callParticipantEventDisplayers = new HashMap<>();
- private Handler callParticipantEventDisplayersHandler = new Handler(Looper.getMainLooper());
- private CallParticipantList.Observer callParticipantListObserver = new CallParticipantList.Observer() {
- @Override
- public void onCallParticipantsChanged(Collection<Participant> joined, Collection<Participant> updated,
- Collection<Participant> left, Collection<Participant> unchanged) {
- handleCallParticipantsChanged(joined, updated, left, unchanged);
- }
- @Override
- public void onCallEndedForAll() {
- Log.d(TAG, "A moderator ended the call for all.");
- hangup(true);
- }
- };
- private CallParticipantList callParticipantList;
- private String switchToRoomToken = "";
- private boolean isBreakoutRoom = false;
- private SignalingMessageReceiver.LocalParticipantMessageListener localParticipantMessageListener =
- new SignalingMessageReceiver.LocalParticipantMessageListener() {
- @Override
- public void onSwitchTo(String token) {
- switchToRoomToken = token;
- hangup(true);
- }
- };
- private SignalingMessageReceiver.OfferMessageListener offerMessageListener = new SignalingMessageReceiver.OfferMessageListener() {
- @Override
- public void onOffer(String sessionId, String roomType, String sdp, String nick) {
- getOrCreatePeerConnectionWrapperForSessionIdAndType(sessionId, roomType, false);
- }
- };
- private ExternalSignalingServer externalSignalingServer;
- private WebSocketInstance webSocketClient;
- private WebSocketConnectionHelper webSocketConnectionHelper;
- private boolean hasMCU;
- private boolean hasExternalSignalingServer;
- private String conversationPassword;
- private PowerManagerUtils powerManagerUtils;
- private Handler handler;
- private CallStatus currentCallStatus;
- private MediaPlayer mediaPlayer;
- private Map<String, ParticipantDisplayItem> participantDisplayItems;
- private ParticipantsAdapter participantsAdapter;
- private CallActivityBinding binding;
- private AudioOutputDialog audioOutputDialog;
- private MoreCallActionsDialog moreCallActionsDialog;
- private final ActivityResultLauncher<String> requestBluetoothPermissionLauncher =
- registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
- if (isGranted) {
- enableBluetoothManager();
- }
- });
- private boolean canPublishAudioStream;
- private boolean canPublishVideoStream;
- private boolean isModerator;
- private ReactionAnimator reactionAnimator;
- @SuppressLint("ClickableViewAccessibility")
- @Override
- public void onCreate(Bundle savedInstanceState) {
- Log.d(TAG, "onCreate");
- super.onCreate(savedInstanceState);
- NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
- binding = CallActivityBinding.inflate(getLayoutInflater());
- setContentView(binding.getRoot());
- hideNavigationIfNoPipAvailable();
- conversationUser = currentUserProvider.getCurrentUser().blockingGet();
- Bundle extras = getIntent().getExtras();
- roomId = extras.getString(KEY_ROOM_ID, "");
- roomToken = extras.getString(KEY_ROOM_TOKEN, "");
- conversationPassword = extras.getString(KEY_CONVERSATION_PASSWORD, "");
- conversationName = extras.getString(KEY_CONVERSATION_NAME, "");
- isVoiceOnlyCall = extras.getBoolean(KEY_CALL_VOICE_ONLY, false);
- isCallWithoutNotification = extras.getBoolean(KEY_CALL_WITHOUT_NOTIFICATION, false);
- canPublishAudioStream = extras.getBoolean(KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_AUDIO);
- canPublishVideoStream = extras.getBoolean(KEY_PARTICIPANT_PERMISSION_CAN_PUBLISH_VIDEO);
- isModerator = extras.getBoolean(KEY_IS_MODERATOR, false);
- if (extras.containsKey(KEY_FROM_NOTIFICATION_START_CALL)) {
- isIncomingCallFromNotification = extras.getBoolean(KEY_FROM_NOTIFICATION_START_CALL);
- }
- if (extras.containsKey(KEY_IS_BREAKOUT_ROOM)) {
- isBreakoutRoom = extras.getBoolean(KEY_IS_BREAKOUT_ROOM);
- }
- credentials = ApiUtils.getCredentials(conversationUser.getUsername(), conversationUser.getToken());
- baseUrl = extras.getString(KEY_MODIFIED_BASE_URL, "");
- if (TextUtils.isEmpty(baseUrl)) {
- baseUrl = conversationUser.getBaseUrl();
- }
- powerManagerUtils = new PowerManagerUtils();
- if ("resume".equalsIgnoreCase(extras.getString("state", ""))) {
- setCallState(CallStatus.IN_CONVERSATION);
- } else {
- setCallState(CallStatus.CONNECTING);
- }
- raiseHandViewModel = new ViewModelProvider(this, viewModelFactory).get((RaiseHandViewModel.class));
- raiseHandViewModel.setData(roomToken, isBreakoutRoom);
- raiseHandViewModel.getViewState().observe(this, viewState -> {
- boolean raised = false;
- if (viewState instanceof RaiseHandViewModel.RaisedHandState) {
- binding.lowerHandButton.setVisibility(View.VISIBLE);
- raised = true;
- } else if (viewState instanceof RaiseHandViewModel.LoweredHandState) {
- binding.lowerHandButton.setVisibility(View.GONE);
- raised = false;
- }
- if (isConnectionEstablished() && peerConnectionWrapperList != null) {
- for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
- peerConnectionWrapper.raiseHand(raised);
- }
- }
- });
- callRecordingViewModel = new ViewModelProvider(this, viewModelFactory).get((CallRecordingViewModel.class));
- callRecordingViewModel.setData(roomToken);
- callRecordingViewModel.setRecordingState(extras.getInt(KEY_RECORDING_STATE));
- callRecordingViewModel.getViewState().observe(this, viewState -> {
- if (viewState instanceof CallRecordingViewModel.RecordingStartedState) {
- binding.callRecordingIndicator.setImageResource(R.drawable.record_stop);
- binding.callRecordingIndicator.setVisibility(View.VISIBLE);
- if (((CallRecordingViewModel.RecordingStartedState) viewState).getShowStartedInfo()) {
- VibrationUtils.INSTANCE.vibrateShort(context);
- Toast.makeText(context, context.getResources().getString(R.string.record_active_info), Toast.LENGTH_LONG).show();
- }
- } else if (viewState instanceof CallRecordingViewModel.RecordingStartingState) {
- if (isAllowedToStartOrStopRecording()) {
- binding.callRecordingIndicator.setImageResource(R.drawable.record_starting);
- binding.callRecordingIndicator.setVisibility(View.VISIBLE);
- } else {
- binding.callRecordingIndicator.setVisibility(View.GONE);
- }
- } else if (viewState instanceof CallRecordingViewModel.RecordingConfirmStopState) {
- if (isAllowedToStartOrStopRecording()) {
- MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(this)
- .setTitle(R.string.record_stop_confirm_title)
- .setMessage(R.string.record_stop_confirm_message)
- .setPositiveButton(R.string.record_stop_description,
- (dialog, which) -> callRecordingViewModel.stopRecording())
- .setNegativeButton(R.string.nc_common_dismiss,
- (dialog, which) -> callRecordingViewModel.dismissStopRecording());
- viewThemeUtils.dialog.colorMaterialAlertDialogBackground(this, dialogBuilder);
- AlertDialog dialog = dialogBuilder.show();
- viewThemeUtils.platform.colorTextButtons(
- dialog.getButton(AlertDialog.BUTTON_POSITIVE),
- dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
- );
- } else {
- Log.e(TAG, "Being in RecordingConfirmStopState as non moderator. This should not happen!");
- }
- } else if (viewState instanceof CallRecordingViewModel.RecordingErrorState) {
- if (isAllowedToStartOrStopRecording()) {
- Toast.makeText(context, context.getResources().getString(R.string.record_failed_info),
- Toast.LENGTH_LONG).show();
- }
- binding.callRecordingIndicator.setVisibility(View.GONE);
- } else {
- binding.callRecordingIndicator.setVisibility(View.GONE);
- }
- });
- initClickListeners();
- binding.microphoneButton.setOnTouchListener(new MicrophoneButtonTouchListener());
- pulseAnimation = PulseAnimation.create().with(binding.microphoneButton)
- .setDuration(310)
- .setRepeatCount(PulseAnimation.INFINITE)
- .setRepeatMode(PulseAnimation.REVERSE);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- requestBluetoothPermission();
- }
- basicInitialization();
- callParticipants = new HashMap<>();
- participantDisplayItems = new HashMap<>();
- initViews();
- if (!isConnectionEstablished()) {
- initiateCall();
- }
- updateSelfVideoViewPosition();
- reactionAnimator = new ReactionAnimator(context, binding.reactionAnimationWrapper, viewThemeUtils);
- }
- public void sendReaction(String emoji) {
- addReactionForAnimation(emoji, conversationUser.getDisplayName());
- if (isConnectionEstablished() && peerConnectionWrapperList != null) {
- for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
- peerConnectionWrapper.sendReaction(emoji);
- }
- }
- }
- @Override
- public void onStart() {
- super.onStart();
- active = true;
- initFeaturesVisibility();
- try {
- cache.evictAll();
- } catch (IOException e) {
- Log.e(TAG, "Failed to evict cache");
- }
- }
- @Override
- public void onStop() {
- super.onStop();
- active = false;
- }
- @RequiresApi(api = Build.VERSION_CODES.S)
- private void requestBluetoothPermission() {
- if (ContextCompat.checkSelfPermission(
- getContext(), Manifest.permission.BLUETOOTH_CONNECT) ==
- PackageManager.PERMISSION_DENIED) {
- requestBluetoothPermissionLauncher.launch(Manifest.permission.BLUETOOTH_CONNECT);
- }
- }
- private void enableBluetoothManager() {
- if (audioManager != null) {
- audioManager.startBluetoothManager();
- }
- }
- private void initFeaturesVisibility() {
- if (isAllowedToStartOrStopRecording() || isAllowedToRaiseHand()) {
- binding.moreCallActions.setVisibility(View.VISIBLE);
- } else {
- binding.moreCallActions.setVisibility(View.GONE);
- }
- }
- private void initClickListeners() {
- binding.pictureInPictureButton.setOnClickListener(l -> enterPipMode());
- binding.audioOutputButton.setOnClickListener(v -> {
- audioOutputDialog = new AudioOutputDialog(this);
- audioOutputDialog.show();
- });
- binding.moreCallActions.setOnClickListener(v -> {
- moreCallActionsDialog = new MoreCallActionsDialog(this);
- moreCallActionsDialog.show();
- });
- if (canPublishAudioStream) {
- binding.microphoneButton.setOnClickListener(l -> onMicrophoneClick());
- binding.microphoneButton.setOnLongClickListener(l -> {
- if (!microphoneOn) {
- callControlHandler.removeCallbacksAndMessages(null);
- callInfosHandler.removeCallbacksAndMessages(null);
- cameraSwitchHandler.removeCallbacksAndMessages(null);
- isPushToTalkActive = true;
- binding.callControls.setVisibility(View.VISIBLE);
- if (!isVoiceOnlyCall) {
- binding.switchSelfVideoButton.setVisibility(View.VISIBLE);
- }
- }
- onMicrophoneClick();
- return true;
- });
- } else {
- binding.microphoneButton.setOnClickListener(
- l -> Toast.makeText(context,
- R.string.nc_not_allowed_to_activate_audio,
- Toast.LENGTH_SHORT
- ).show()
- );
- }
- if (canPublishVideoStream) {
- binding.cameraButton.setOnClickListener(l -> onCameraClick());
- } else {
- binding.cameraButton.setOnClickListener(
- l -> Toast.makeText(context,
- R.string.nc_not_allowed_to_activate_video,
- Toast.LENGTH_SHORT
- ).show()
- );
- }
- binding.hangupButton.setOnClickListener(l -> {
- hangup(true);
- });
- binding.switchSelfVideoButton.setOnClickListener(l -> switchCamera());
- binding.gridview.setOnItemClickListener((parent, view, position, id) -> animateCallControls(true, 0));
- binding.callStates.callStateRelativeLayout.setOnClickListener(l -> {
- if (currentCallStatus == CallStatus.CALLING_TIMEOUT) {
- setCallState(CallStatus.RECONNECTING);
- hangupNetworkCalls(false);
- }
- });
- binding.callRecordingIndicator.setOnClickListener(l -> {
- if (isAllowedToStartOrStopRecording()) {
- if (callRecordingViewModel.getViewState().getValue() instanceof CallRecordingViewModel.RecordingStartingState) {
- if (moreCallActionsDialog == null) {
- moreCallActionsDialog = new MoreCallActionsDialog(this);
- }
- moreCallActionsDialog.show();
- } else {
- callRecordingViewModel.clickRecordButton();
- }
- } else {
- Toast.makeText(context, context.getResources().getString(R.string.record_active_info), Toast.LENGTH_LONG).show();
- }
- });
- binding.lowerHandButton.setOnClickListener(l -> {
- raiseHandViewModel.lowerHand();
- });
- }
- private void createCameraEnumerator() {
- boolean camera2EnumeratorIsSupported = false;
- try {
- camera2EnumeratorIsSupported = Camera2Enumerator.isSupported(this);
- } catch (final Throwable t) {
- Log.w(TAG, "Camera2Enumerator threw an error", t);
- }
- if (camera2EnumeratorIsSupported) {
- cameraEnumerator = new Camera2Enumerator(this);
- } else {
- cameraEnumerator = new Camera1Enumerator(MagicWebRTCUtils.shouldEnableVideoHardwareAcceleration());
- }
- }
- private void basicInitialization() {
- rootEglBase = EglBase.create();
- createCameraEnumerator();
- //Create a new PeerConnectionFactory instance.
- PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
- DefaultVideoEncoderFactory defaultVideoEncoderFactory = new DefaultVideoEncoderFactory(
- rootEglBase.getEglBaseContext(), true, true);
- DefaultVideoDecoderFactory defaultVideoDecoderFactory = new DefaultVideoDecoderFactory(
- rootEglBase.getEglBaseContext());
- peerConnectionFactory = PeerConnectionFactory.builder()
- .setOptions(options)
- .setVideoEncoderFactory(defaultVideoEncoderFactory)
- .setVideoDecoderFactory(defaultVideoDecoderFactory)
- .createPeerConnectionFactory();
- //Create MediaConstraints - Will be useful for specifying video and audio constraints.
- audioConstraints = new MediaConstraints();
- videoConstraints = new MediaConstraints();
- localStream = peerConnectionFactory.createLocalMediaStream("NCMS");
- // Create and audio manager that will take care of audio routing,
- // audio modes, audio device enumeration etc.
- audioManager = WebRtcAudioManager.create(getApplicationContext(), isVoiceOnlyCall);
- // Store existing audio settings and change audio mode to
- // MODE_IN_COMMUNICATION for best possible VoIP performance.
- Log.d(TAG, "Starting the audio manager...");
- audioManager.start(this::onAudioManagerDevicesChanged);
- if (isVoiceOnlyCall) {
- setAudioOutputChannel(WebRtcAudioManager.AudioDevice.EARPIECE);
- } else {
- setAudioOutputChannel(WebRtcAudioManager.AudioDevice.SPEAKER_PHONE);
- }
- iceServers = new ArrayList<>();
- //create sdpConstraints
- sdpConstraints = new MediaConstraints();
- sdpConstraintsForMCU = new MediaConstraints();
- sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
- String offerToReceiveVideoString = "true";
- if (isVoiceOnlyCall) {
- offerToReceiveVideoString = "false";
- }
- sdpConstraints.mandatory.add(
- new MediaConstraints.KeyValuePair("OfferToReceiveVideo", offerToReceiveVideoString));
- sdpConstraintsForMCU.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "false"));
- sdpConstraintsForMCU.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "false"));
- sdpConstraintsForMCU.optional.add(new MediaConstraints.KeyValuePair("internalSctpDataChannels", "true"));
- sdpConstraintsForMCU.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
- sdpConstraints.optional.add(new MediaConstraints.KeyValuePair("internalSctpDataChannels", "true"));
- sdpConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
- if (!isVoiceOnlyCall) {
- cameraInitialization();
- }
- microphoneInitialization();
- }
- public void setAudioOutputChannel(WebRtcAudioManager.AudioDevice selectedAudioDevice) {
- if (audioManager != null) {
- audioManager.selectAudioDevice(selectedAudioDevice);
- updateAudioOutputButton(audioManager.getCurrentAudioDevice());
- }
- }
- private void updateAudioOutputButton(WebRtcAudioManager.AudioDevice activeAudioDevice) {
- switch (activeAudioDevice) {
- case BLUETOOTH:
- binding.audioOutputButton.setImageResource(R.drawable.ic_baseline_bluetooth_audio_24);
- break;
- case SPEAKER_PHONE:
- binding.audioOutputButton.setImageResource(R.drawable.ic_volume_up_white_24dp);
- break;
- case EARPIECE:
- binding.audioOutputButton.setImageResource(R.drawable.ic_baseline_phone_in_talk_24);
- break;
- case WIRED_HEADSET:
- binding.audioOutputButton.setImageResource(R.drawable.ic_baseline_headset_mic_24);
- break;
- default:
- Log.e(TAG, "Icon for audio output not available");
- break;
- }
- DrawableCompat.setTint(binding.audioOutputButton.getDrawable(), Color.WHITE);
- }
- private void handleFromNotification() {
- int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[]{ApiUtils.APIv4, 1});
- ncApi.getRooms(credentials, ApiUtils.getUrlForRooms(apiVersion, baseUrl), Boolean.FALSE)
- .retry(3)
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(new Observer<RoomsOverall>() {
- @Override
- public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
- // unused atm
- }
- @Override
- public void onNext(@io.reactivex.annotations.NonNull RoomsOverall roomsOverall) {
- for (Conversation conversation : roomsOverall.getOcs().getData()) {
- if (roomId.equals(conversation.getRoomId())) {
- roomToken = conversation.getToken();
- break;
- }
- }
- checkDevicePermissions();
- }
- @Override
- public void onError(@io.reactivex.annotations.NonNull Throwable e) {
- // unused atm
- }
- @Override
- public void onComplete() {
- // unused atm
- }
- });
- }
- @SuppressLint("ClickableViewAccessibility")
- private void initViews() {
- Log.d(TAG, "initViews");
- binding.callInfosLinearLayout.setVisibility(View.VISIBLE);
- binding.selfVideoViewWrapper.setVisibility(View.VISIBLE);
- if (!isPipModePossible()) {
- binding.pictureInPictureButton.setVisibility(View.GONE);
- }
- if (isVoiceOnlyCall) {
- binding.switchSelfVideoButton.setVisibility(View.GONE);
- binding.cameraButton.setVisibility(View.GONE);
- binding.selfVideoRenderer.setVisibility(View.GONE);
- RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- params.addRule(RelativeLayout.BELOW, R.id.callInfosLinearLayout);
- int callControlsHeight = Math.round(getApplicationContext().getResources().getDimension(R.dimen.call_controls_height));
- params.setMargins(0, 0, 0, callControlsHeight);
- binding.gridview.setLayoutParams(params);
- } else {
- RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- params.setMargins(0, 0, 0, 0);
- binding.gridview.setLayoutParams(params);
- if (cameraEnumerator.getDeviceNames().length < 2) {
- binding.switchSelfVideoButton.setVisibility(View.GONE);
- }
- initSelfVideoView();
- }
- binding.gridview.setOnTouchListener(new View.OnTouchListener() {
- public boolean onTouch(View v, MotionEvent me) {
- int action = me.getActionMasked();
- if (action == MotionEvent.ACTION_DOWN) {
- animateCallControls(true, 0);
- }
- return false;
- }
- });
- binding.conversationRelativeLayout.setOnTouchListener(new View.OnTouchListener() {
- public boolean onTouch(View v, MotionEvent me) {
- int action = me.getActionMasked();
- if (action == MotionEvent.ACTION_DOWN) {
- animateCallControls(true, 0);
- }
- return false;
- }
- });
- animateCallControls(true, 0);
- initGridAdapter();
- }
- @SuppressLint("ClickableViewAccessibility")
- private void initSelfVideoView() {
- try {
- binding.selfVideoRenderer.init(rootEglBase.getEglBaseContext(), null);
- } catch (IllegalStateException e) {
- Log.d(TAG, "selfVideoRenderer already initialized", e);
- }
- binding.selfVideoRenderer.setZOrderMediaOverlay(true);
- // disabled because it causes some devices to crash
- binding.selfVideoRenderer.setEnableHardwareScaler(false);
- binding.selfVideoRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
- binding.selfVideoRenderer.setOnTouchListener(new SelfVideoTouchListener());
- }
- private void initGridAdapter() {
- Log.d(TAG, "initGridAdapter");
- int columns;
- int participantsInGrid = participantDisplayItems.size();
- if (getResources() != null
- && getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
- if (participantsInGrid > 2) {
- columns = 2;
- } else {
- columns = 1;
- }
- } else {
- if (participantsInGrid > 2) {
- columns = 3;
- } else if (participantsInGrid > 1) {
- columns = 2;
- } else {
- columns = 1;
- }
- }
- binding.gridview.setNumColumns(columns);
- binding.conversationRelativeLayout
- .getViewTreeObserver()
- .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- binding.conversationRelativeLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
- int height = binding.conversationRelativeLayout.getMeasuredHeight();
- binding.gridview.setMinimumHeight(height);
- }
- });
- binding
- .callInfosLinearLayout
- .getViewTreeObserver()
- .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- binding.callInfosLinearLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
- }
- });
- if (participantsAdapter != null) {
- participantsAdapter.destroy();
- }
- participantsAdapter = new ParticipantsAdapter(
- this,
- participantDisplayItems,
- binding.conversationRelativeLayout,
- binding.callInfosLinearLayout,
- columns,
- isVoiceOnlyCall);
- binding.gridview.setAdapter(participantsAdapter);
- if (isInPipMode) {
- updateUiForPipMode();
- }
- }
- private void checkDevicePermissions() {
- if (isVoiceOnlyCall) {
- onMicrophoneClick();
- } else {
- if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_CALL)) {
- onPermissionsGranted();
- } else {
- requestPermissions(PERMISSIONS_CALL, 100);
- }
- }
- }
- private boolean isConnectionEstablished() {
- return (currentCallStatus == CallStatus.JOINED || currentCallStatus == CallStatus.IN_CONVERSATION);
- }
- @AfterPermissionGranted(100)
- private void onPermissionsGranted() {
- if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_CALL)) {
- if (!videoOn && !isVoiceOnlyCall) {
- onCameraClick();
- }
- if (!microphoneOn) {
- onMicrophoneClick();
- }
- if (!isVoiceOnlyCall) {
- if (cameraEnumerator.getDeviceNames().length == 0) {
- binding.cameraButton.setVisibility(View.GONE);
- }
- if (cameraEnumerator.getDeviceNames().length > 1) {
- binding.switchSelfVideoButton.setVisibility(View.VISIBLE);
- }
- }
- if (!isConnectionEstablished()) {
- fetchSignalingSettings();
- }
- } else if (EffortlessPermissions.somePermissionPermanentlyDenied(this, PERMISSIONS_CALL)) {
- checkIfSomeAreApproved();
- }
- }
- private void checkIfSomeAreApproved() {
- if (!isVoiceOnlyCall) {
- if (cameraEnumerator.getDeviceNames().length == 0) {
- binding.cameraButton.setVisibility(View.GONE);
- }
- if (cameraEnumerator.getDeviceNames().length > 1) {
- binding.switchSelfVideoButton.setVisibility(View.VISIBLE);
- }
- if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_CAMERA) && canPublishVideoStream) {
- if (!videoOn) {
- onCameraClick();
- }
- } else {
- binding.cameraButton.setImageResource(R.drawable.ic_videocam_off_white_24px);
- binding.cameraButton.setAlpha(0.7f);
- binding.switchSelfVideoButton.setVisibility(View.GONE);
- }
- }
- if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_MICROPHONE) && canPublishAudioStream) {
- if (!microphoneOn) {
- onMicrophoneClick();
- }
- } else {
- binding.microphoneButton.setImageResource(R.drawable.ic_mic_off_white_24px);
- }
- if (!isConnectionEstablished()) {
- fetchSignalingSettings();
- }
- }
- @AfterPermissionDenied(100)
- private void onPermissionsDenied() {
- if (!isVoiceOnlyCall) {
- if (cameraEnumerator.getDeviceNames().length == 0) {
- binding.cameraButton.setVisibility(View.GONE);
- } else if (cameraEnumerator.getDeviceNames().length == 1) {
- binding.switchSelfVideoButton.setVisibility(View.GONE);
- }
- }
- if ((EffortlessPermissions.hasPermissions(this, PERMISSIONS_CAMERA) ||
- EffortlessPermissions.hasPermissions(this, PERMISSIONS_MICROPHONE))) {
- checkIfSomeAreApproved();
- } else if (!isConnectionEstablished()) {
- fetchSignalingSettings();
- }
- }
- private void onAudioManagerDevicesChanged(
- final WebRtcAudioManager.AudioDevice currentDevice,
- final Set<WebRtcAudioManager.AudioDevice> availableDevices) {
- Log.d(TAG, "onAudioManagerDevicesChanged: " + availableDevices + ", "
- + "currentDevice: " + currentDevice);
- final boolean shouldDisableProximityLock = (currentDevice == WebRtcAudioManager.AudioDevice.WIRED_HEADSET
- || currentDevice == WebRtcAudioManager.AudioDevice.SPEAKER_PHONE
- || currentDevice == WebRtcAudioManager.AudioDevice.BLUETOOTH);
- if (shouldDisableProximityLock) {
- powerManagerUtils.updatePhoneState(PowerManagerUtils.PhoneState.WITHOUT_PROXIMITY_SENSOR_LOCK);
- } else {
- powerManagerUtils.updatePhoneState(PowerManagerUtils.PhoneState.WITH_PROXIMITY_SENSOR_LOCK);
- }
- if (audioOutputDialog != null) {
- audioOutputDialog.updateOutputDeviceList();
- }
- updateAudioOutputButton(currentDevice);
- }
- private void cameraInitialization() {
- videoCapturer = createCameraCapturer(cameraEnumerator);
- //Create a VideoSource instance
- if (videoCapturer != null) {
- SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread",
- rootEglBase.getEglBaseContext());
- videoSource = peerConnectionFactory.createVideoSource(false);
- videoCapturer.initialize(surfaceTextureHelper, getApplicationContext(), videoSource.getCapturerObserver());
- }
- localVideoTrack = peerConnectionFactory.createVideoTrack("NCv0", videoSource);
- localStream.addTrack(localVideoTrack);
- localVideoTrack.setEnabled(false);
- localVideoTrack.addSink(binding.selfVideoRenderer);
- }
- private void microphoneInitialization() {
- //create an AudioSource instance
- audioSource = peerConnectionFactory.createAudioSource(audioConstraints);
- localAudioTrack = peerConnectionFactory.createAudioTrack("NCa0", audioSource);
- localAudioTrack.setEnabled(false);
- localStream.addTrack(localAudioTrack);
- }
- private VideoCapturer createCameraCapturer(CameraEnumerator enumerator) {
- final String[] deviceNames = enumerator.getDeviceNames();
- // First, try to find front facing camera
- Logging.d(TAG, "Looking for front facing cameras.");
- for (String deviceName : deviceNames) {
- if (enumerator.isFrontFacing(deviceName)) {
- Logging.d(TAG, "Creating front facing camera capturer.");
- VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null);
- if (videoCapturer != null) {
- binding.selfVideoRenderer.setMirror(true);
- return videoCapturer;
- }
- }
- }
- // Front facing camera not found, try something else
- Logging.d(TAG, "Looking for other cameras.");
- for (String deviceName : deviceNames) {
- if (!enumerator.isFrontFacing(deviceName)) {
- Logging.d(TAG, "Creating other camera capturer.");
- VideoCapturer videoCapturer = enumerator.createCapturer(deviceName, null);
- if (videoCapturer != null) {
- binding.selfVideoRenderer.setMirror(false);
- return videoCapturer;
- }
- }
- }
- return null;
- }
- public void onMicrophoneClick() {
- if (!canPublishAudioStream) {
- microphoneOn = false;
- binding.microphoneButton.setImageResource(R.drawable.ic_mic_off_white_24px);
- toggleMedia(false, false);
- }
- if (isVoiceOnlyCall && !isConnectionEstablished()) {
- fetchSignalingSettings();
- }
- if (!canPublishAudioStream) {
- // In the case no audio stream will be published it's not needed to check microphone permissions
- return;
- }
- if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_MICROPHONE)) {
- if (!appPreferences.getPushToTalkIntroShown()) {
- int primary = viewThemeUtils.getScheme(binding.audioOutputButton.getContext()).getPrimary();
- spotlightView = new SpotlightView.Builder(this)
- .introAnimationDuration(300)
- .enableRevealAnimation(true)
- .performClick(false)
- .fadeinTextDuration(400)
- .headingTvColor(primary)
- .headingTvSize(20)
- .headingTvText(getResources().getString(R.string.nc_push_to_talk))
- .subHeadingTvColor(getResources().getColor(R.color.bg_default))
- .subHeadingTvSize(16)
- .subHeadingTvText(getResources().getString(R.string.nc_push_to_talk_desc))
- .maskColor(Color.parseColor("#dc000000"))
- .target(binding.microphoneButton)
- .lineAnimDuration(400)
- .lineAndArcColor(primary)
- .enableDismissAfterShown(true)
- .dismissOnBackPress(true)
- .usageId("pushToTalk")
- .show();
- appPreferences.setPushToTalkIntroShown(true);
- }
- if (!isPushToTalkActive) {
- microphoneOn = !microphoneOn;
- if (microphoneOn) {
- binding.microphoneButton.setImageResource(R.drawable.ic_mic_white_24px);
- updatePictureInPictureActions(R.drawable.ic_mic_white_24px,
- getResources().getString(R.string.nc_pip_microphone_mute),
- MICROPHONE_PIP_REQUEST_MUTE);
- } else {
- binding.microphoneButton.setImageResource(R.drawable.ic_mic_off_white_24px);
- updatePictureInPictureActions(R.drawable.ic_mic_off_white_24px,
- getResources().getString(R.string.nc_pip_microphone_unmute),
- MICROPHONE_PIP_REQUEST_UNMUTE);
- }
- toggleMedia(microphoneOn, false);
- } else {
- binding.microphoneButton.setImageResource(R.drawable.ic_mic_white_24px);
- pulseAnimation.start();
- toggleMedia(true, false);
- }
- } else if (EffortlessPermissions.somePermissionPermanentlyDenied(this, PERMISSIONS_MICROPHONE)) {
- // Microphone permission is permanently denied so we cannot request it normally.
- OpenAppDetailsDialogFragment.show(
- R.string.nc_microphone_permission_permanently_denied,
- R.string.nc_permissions_settings, (AppCompatActivity) this);
- } else {
- requestPermissions(PERMISSIONS_MICROPHONE, 100);
- }
- }
- public void onCameraClick() {
- if (!canPublishVideoStream) {
- videoOn = false;
- binding.cameraButton.setImageResource(R.drawable.ic_videocam_off_white_24px);
- binding.switchSelfVideoButton.setVisibility(View.GONE);
- return;
- }
- if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_CAMERA)) {
- videoOn = !videoOn;
- if (videoOn) {
- binding.cameraButton.setImageResource(R.drawable.ic_videocam_white_24px);
- if (cameraEnumerator.getDeviceNames().length > 1) {
- binding.switchSelfVideoButton.setVisibility(View.VISIBLE);
- }
- } else {
- binding.cameraButton.setImageResource(R.drawable.ic_videocam_off_white_24px);
- binding.switchSelfVideoButton.setVisibility(View.GONE);
- }
- toggleMedia(videoOn, true);
- } else if (EffortlessPermissions.somePermissionPermanentlyDenied(this, PERMISSIONS_CAMERA)) {
- // Camera permission is permanently denied so we cannot request it normally.
- OpenAppDetailsDialogFragment.show(
- R.string.nc_camera_permission_permanently_denied,
- R.string.nc_permissions_settings, (AppCompatActivity) this);
- } else {
- requestPermissions(PERMISSIONS_CAMERA, 100);
- }
- }
- public void switchCamera() {
- CameraVideoCapturer cameraVideoCapturer = (CameraVideoCapturer) videoCapturer;
- if (cameraVideoCapturer != null) {
- cameraVideoCapturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() {
- @Override
- public void onCameraSwitchDone(boolean currentCameraIsFront) {
- binding.selfVideoRenderer.setMirror(currentCameraIsFront);
- }
- @Override
- public void onCameraSwitchError(String s) {
- }
- });
- }
- }
- private void toggleMedia(boolean enable, boolean video) {
- String message;
- if (video) {
- message = "videoOff";
- if (enable) {
- binding.cameraButton.setAlpha(1.0f);
- message = "videoOn";
- startVideoCapture();
- } else {
- binding.cameraButton.setAlpha(0.7f);
- if (videoCapturer != null) {
- try {
- videoCapturer.stopCapture();
- } catch (InterruptedException e) {
- Log.d(TAG, "Failed to stop capturing video while sensor is near the ear");
- }
- }
- }
- if (localStream != null && localStream.videoTracks.size() > 0) {
- localStream.videoTracks.get(0).setEnabled(enable);
- }
- if (enable) {
- binding.selfVideoRenderer.setVisibility(View.VISIBLE);
- } else {
- binding.selfVideoRenderer.setVisibility(View.INVISIBLE);
- }
- } else {
- message = "audioOff";
- if (enable) {
- message = "audioOn";
- binding.microphoneButton.setAlpha(1.0f);
- } else {
- binding.microphoneButton.setAlpha(0.7f);
- }
- if (localStream != null && localStream.audioTracks.size() > 0) {
- localStream.audioTracks.get(0).setEnabled(enable);
- }
- }
- if (isConnectionEstablished() && peerConnectionWrapperList != null) {
- if (!hasMCU) {
- for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
- peerConnectionWrapper.sendChannelData(new DataChannelMessage(message));
- }
- } else {
- for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
- if (peerConnectionWrapper.getSessionId().equals(webSocketClient.getSessionId())) {
- peerConnectionWrapper.sendChannelData(new DataChannelMessage(message));
- break;
- }
- }
- }
- }
- }
- public void clickRaiseOrLowerHandButton() {
- raiseHandViewModel.clickHandButton();
- }
- private void animateCallControls(boolean show, long startDelay) {
- if (isVoiceOnlyCall) {
- if (spotlightView != null && spotlightView.getVisibility() != View.GONE) {
- spotlightView.setVisibility(View.GONE);
- }
- } else if (!isPushToTalkActive) {
- float alpha;
- long duration;
- if (show) {
- callControlHandler.removeCallbacksAndMessages(null);
- callInfosHandler.removeCallbacksAndMessages(null);
- cameraSwitchHandler.removeCallbacksAndMessages(null);
- alpha = 1.0f;
- duration = 1000;
- if (binding.callControls.getVisibility() != View.VISIBLE) {
- binding.callControls.setAlpha(0.0f);
- binding.callControls.setVisibility(View.VISIBLE);
- binding.callInfosLinearLayout.setAlpha(0.0f);
- binding.callInfosLinearLayout.setVisibility(View.VISIBLE);
- binding.switchSelfVideoButton.setAlpha(0.0f);
- if (videoOn) {
- binding.switchSelfVideoButton.setVisibility(View.VISIBLE);
- }
- } else {
- callControlHandler.postDelayed(() -> animateCallControls(false, 0), 5000);
- return;
- }
- } else {
- alpha = 0.0f;
- duration = 1000;
- }
- binding.callControls.setEnabled(false);
- binding.callControls.animate()
- .translationY(0)
- .alpha(alpha)
- .setDuration(duration)
- .setStartDelay(startDelay)
- .setListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- super.onAnimationEnd(animation);
- if (!show) {
- binding.callControls.setVisibility(View.GONE);
- if (spotlightView != null && spotlightView.getVisibility() != View.GONE) {
- spotlightView.setVisibility(View.GONE);
- }
- } else {
- callControlHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (!isPushToTalkActive) {
- animateCallControls(false, 0);
- }
- }
- }, 7500);
- }
- binding.callControls.setEnabled(true);
- }
- });
- binding.callInfosLinearLayout.setEnabled(false);
- binding.callInfosLinearLayout.animate()
- .translationY(0)
- .alpha(alpha)
- .setDuration(duration)
- .setStartDelay(startDelay)
- .setListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- super.onAnimationEnd(animation);
- if (!show) {
- binding.callInfosLinearLayout.setVisibility(View.GONE);
- } else {
- callInfosHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- if (!isPushToTalkActive) {
- animateCallControls(false, 0);
- }
- }
- }, 7500);
- }
- binding.callInfosLinearLayout.setEnabled(true);
- }
- });
- binding.switchSelfVideoButton.setEnabled(false);
- binding.switchSelfVideoButton.animate()
- .translationY(0)
- .alpha(alpha)
- .setDuration(duration)
- .setStartDelay(startDelay)
- .setListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationEnd(Animator animation) {
- super.onAnimationEnd(animation);
- if (!show) {
- binding.switchSelfVideoButton.setVisibility(View.GONE);
- }
- binding.switchSelfVideoButton.setEnabled(true);
- }
- });
- }
- }
- @Override
- public void onDestroy() {
- if (signalingMessageReceiver != null) {
- signalingMessageReceiver.removeListener(localParticipantMessageListener);
- signalingMessageReceiver.removeListener(offerMessageListener);
- }
- if (localStream != null) {
- localStream.dispose();
- localStream = null;
- Log.d(TAG, "Disposed localStream");
- } else {
- Log.d(TAG, "localStream is null");
- }
- if (currentCallStatus != CallStatus.LEAVING) {
- hangup(true);
- }
- powerManagerUtils.updatePhoneState(PowerManagerUtils.PhoneState.IDLE);
- super.onDestroy();
- }
- private void fetchSignalingSettings() {
- Log.d(TAG, "fetchSignalingSettings");
- int apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[]{ApiUtils.APIv3, 2, 1});
- ncApi.getSignalingSettings(credentials, ApiUtils.getUrlForSignalingSettings(apiVersion, baseUrl))
- .subscribeOn(Schedulers.io())
- .retry(3)
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(new Observer<SignalingSettingsOverall>() {
- @Override
- public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
- // unused atm
- }
- @Override
- public void onNext(@io.reactivex.annotations.NonNull SignalingSettingsOverall signalingSettingsOverall) {
- if (signalingSettingsOverall.getOcs() != null
- && signalingSettingsOverall.getOcs().getSettings() != null) {
- externalSignalingServer = new ExternalSignalingServer();
- if (!TextUtils.isEmpty(
- signalingSettingsOverall.getOcs().getSettings().getExternalSignalingServer()) &&
- !TextUtils.isEmpty(
- signalingSettingsOverall.getOcs().getSettings().getExternalSignalingTicket())) {
- externalSignalingServer = new ExternalSignalingServer();
- externalSignalingServer.setExternalSignalingServer(
- signalingSettingsOverall.getOcs().getSettings().getExternalSignalingServer());
- externalSignalingServer.setExternalSignalingTicket(
- signalingSettingsOverall.getOcs().getSettings().getExternalSignalingTicket());
- hasExternalSignalingServer = true;
- } else {
- hasExternalSignalingServer = false;
- }
- Log.d(TAG, " hasExternalSignalingServer: " + hasExternalSignalingServer);
- if (!"?".equals(conversationUser.getUserId()) && conversationUser.getId() != null) {
- Log.d(TAG, "Update externalSignalingServer for: " + conversationUser.getId() +
- " / " + conversationUser.getUserId());
- userManager.updateExternalSignalingServer(conversationUser.getId(), externalSignalingServer)
- .subscribeOn(Schedulers.io())
- .subscribe();
- } else {
- conversationUser.setExternalSignalingServer(externalSignalingServer);
- }
- if (signalingSettingsOverall.getOcs().getSettings().getStunServers() != null) {
- List<IceServer> stunServers =
- signalingSettingsOverall.getOcs().getSettings().getStunServers();
- if (apiVersion == ApiUtils.APIv3) {
- for (IceServer stunServer : stunServers) {
- if (stunServer.getUrls() != null) {
- for (String url : stunServer.getUrls()) {
- Log.d(TAG, " STUN server url: " + url);
- iceServers.add(new PeerConnection.IceServer(url));
- }
- }
- }
- } else {
- if (signalingSettingsOverall.getOcs().getSettings().getStunServers() != null) {
- for (IceServer stunServer : stunServers) {
- Log.d(TAG, " STUN server url: " + stunServer.getUrl());
- iceServers.add(new PeerConnection.IceServer(stunServer.getUrl()));
- }
- }
- }
- }
- if (signalingSettingsOverall.getOcs().getSettings().getTurnServers() != null) {
- List<IceServer> turnServers =
- signalingSettingsOverall.getOcs().getSettings().getTurnServers();
- for (IceServer turnServer : turnServers) {
- if (turnServer.getUrls() != null) {
- for (String url : turnServer.getUrls()) {
- Log.d(TAG, " TURN server url: " + url);
- iceServers.add(new PeerConnection.IceServer(
- url, turnServer.getUsername(), turnServer.getCredential()
- ));
- }
- }
- }
- }
- }
- checkCapabilities();
- }
- @Override
- public void onError(@io.reactivex.annotations.NonNull Throwable e) {
- Log.e(TAG, e.getMessage(), e);
- }
- @Override
- public void onComplete() {
- // unused atm
- }
- });
- }
- private void checkCapabilities() {
- ncApi.getCapabilities(credentials, ApiUtils.getUrlForCapabilities(baseUrl))
- .retry(3)
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(new Observer<CapabilitiesOverall>() {
- @Override
- public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
- // unused atm
- }
- @Override
- public void onNext(@io.reactivex.annotations.NonNull CapabilitiesOverall capabilitiesOverall) {
- // FIXME check for compatible Call API version
- if (hasExternalSignalingServer) {
- setupAndInitiateWebSocketsConnection();
- } else {
- signalingMessageReceiver = internalSignalingMessageReceiver;
- signalingMessageReceiver.addListener(localParticipantMessageListener);
- signalingMessageReceiver.addListener(offerMessageListener);
- signalingMessageSender = internalSignalingMessageSender;
- joinRoomAndCall();
- }
- }
- @Override
- public void onError(@io.reactivex.annotations.NonNull Throwable e) {
- // unused atm
- }
- @Override
- public void onComplete() {
- // unused atm
- }
- });
- }
- private void joinRoomAndCall() {
- callSession = ApplicationWideCurrentRoomHolder.getInstance().getSession();
- int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[]{ApiUtils.APIv4, 1});
- Log.d(TAG, "joinRoomAndCall");
- Log.d(TAG, " baseUrl= " + baseUrl);
- Log.d(TAG, " roomToken= " + roomToken);
- Log.d(TAG, " callSession= " + callSession);
- String url = ApiUtils.getUrlForParticipantsActive(apiVersion, baseUrl, roomToken);
- Log.d(TAG, " url= " + url);
- if (TextUtils.isEmpty(callSession)) {
- ncApi.joinRoom(credentials, url, conversationPassword)
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .retry(3)
- .subscribe(new Observer<RoomOverall>() {
- @Override
- public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
- // unused atm
- }
- @Override
- public void onNext(@io.reactivex.annotations.NonNull RoomOverall roomOverall) {
- Conversation conversation = roomOverall.getOcs().getData();
- callRecordingViewModel.setRecordingState(conversation.getCallRecording());
- callSession = conversation.getSessionId();
- Log.d(TAG, " new callSession by joinRoom= " + callSession);
- ApplicationWideCurrentRoomHolder.getInstance().setSession(callSession);
- ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomId(conversation.getRoomId());
- ApplicationWideCurrentRoomHolder.getInstance().setCurrentRoomToken(roomToken);
- ApplicationWideCurrentRoomHolder.getInstance().setUserInRoom(conversationUser);
- callOrJoinRoomViaWebSocket();
- }
- @Override
- public void onError(@io.reactivex.annotations.NonNull Throwable e) {
- Log.e(TAG, "joinRoom onError", e);
- }
- @Override
- public void onComplete() {
- Log.d(TAG, "joinRoom onComplete");
- }
- });
- } else {
- // we are in a room and start a call -> same session needs to be used
- callOrJoinRoomViaWebSocket();
- }
- }
- private void callOrJoinRoomViaWebSocket() {
- if (hasExternalSignalingServer) {
- webSocketClient.joinRoomWithRoomTokenAndSession(roomToken, callSession);
- } else {
- performCall();
- }
- }
- private void performCall() {
- int inCallFlag = Participant.InCallFlags.IN_CALL;
- if (canPublishAudioStream) {
- inCallFlag += Participant.InCallFlags.WITH_AUDIO;
- }
- if (!isVoiceOnlyCall && canPublishVideoStream) {
- inCallFlag += Participant.InCallFlags.WITH_VIDEO;
- }
- callParticipantList = new CallParticipantList(signalingMessageReceiver);
- callParticipantList.addObserver(callParticipantListObserver);
- int apiVersion = ApiUtils.getCallApiVersion(conversationUser, new int[]{ApiUtils.APIv4, 1});
- ncApi.joinCall(
- credentials,
- ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken),
- inCallFlag,
- isCallWithoutNotification)
- .subscribeOn(Schedulers.io())
- .retry(3)
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(new Observer<GenericOverall>() {
- @Override
- public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
- // unused atm
- }
- @Override
- public void onNext(@io.reactivex.annotations.NonNull GenericOverall genericOverall) {
- if (currentCallStatus != CallStatus.LEAVING) {
- if (currentCallStatus != CallStatus.IN_CONVERSATION) {
- setCallState(CallStatus.JOINED);
- }
- ApplicationWideCurrentRoomHolder.getInstance().setInCall(true);
- ApplicationWideCurrentRoomHolder.getInstance().setDialing(false);
- if (!TextUtils.isEmpty(roomToken)) {
- NotificationUtils.INSTANCE.cancelExistingNotificationsForRoom(getApplicationContext(),
- conversationUser,
- roomToken);
- }
- if (!hasExternalSignalingServer) {
- int apiVersion = ApiUtils.getSignalingApiVersion(conversationUser,
- new int[]{ApiUtils.APIv3, 2, 1});
- AtomicInteger delayOnError = new AtomicInteger(0);
- ncApi.pullSignalingMessages(credentials,
- ApiUtils.getUrlForSignaling(apiVersion,
- baseUrl,
- roomToken))
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .repeatWhen(observable -> observable)
- .takeWhile(observable -> isConnectionEstablished())
- .doOnNext(value -> delayOnError.set(0))
- .retryWhen(errors -> errors
- .flatMap(error -> {
- if (!isConnectionEstablished()) {
- return Observable.error(error);
- }
- if (delayOnError.get() == 0) {
- delayOnError.set(1);
- } else if (delayOnError.get() < 16) {
- delayOnError.set(delayOnError.get() * 2);
- }
- return Observable.timer(delayOnError.get(), TimeUnit.SECONDS);
- })
- )
- .subscribe(new Observer<SignalingOverall>() {
- @Override
- public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
- signalingDisposable = d;
- }
- @Override
- public void onNext(
- @io.reactivex.annotations.NonNull
- SignalingOverall signalingOverall) {
- receivedSignalingMessages(signalingOverall.getOcs().getSignalings());
- }
- @Override
- public void onError(@io.reactivex.annotations.NonNull Throwable e) {
- dispose(signalingDisposable);
- }
- @Override
- public void onComplete() {
- dispose(signalingDisposable);
- }
- });
- }
- }
- }
- @Override
- public void onError(@io.reactivex.annotations.NonNull Throwable e) {
- // unused atm
- }
- @Override
- public void onComplete() {
- // unused atm
- }
- });
- }
- private void setupAndInitiateWebSocketsConnection() {
- if (webSocketConnectionHelper == null) {
- webSocketConnectionHelper = new WebSocketConnectionHelper();
- }
- if (webSocketClient == null) {
- webSocketClient = WebSocketConnectionHelper.getExternalSignalingInstanceForServer(
- externalSignalingServer.getExternalSignalingServer(),
- conversationUser, externalSignalingServer.getExternalSignalingTicket(),
- TextUtils.isEmpty(credentials));
- // Although setupAndInitiateWebSocketsConnection could be called several times the web socket is
- // initialized just once, so the message receiver is also initialized just once.
- signalingMessageReceiver = webSocketClient.getSignalingMessageReceiver();
- signalingMessageReceiver.addListener(localParticipantMessageListener);
- signalingMessageReceiver.addListener(offerMessageListener);
- signalingMessageSender = webSocketClient.getSignalingMessageSender();
- } else {
- if (webSocketClient.isConnected() && currentCallStatus == CallStatus.PUBLISHER_FAILED) {
- webSocketClient.restartWebSocket();
- }
- }
- joinRoomAndCall();
- }
- private void initiateCall() {
- if (!TextUtils.isEmpty(roomToken)) {
- checkDevicePermissions();
- } else {
- handleFromNotification();
- }
- }
- @Subscribe(threadMode = ThreadMode.BACKGROUND)
- public void onMessageEvent(WebSocketCommunicationEvent webSocketCommunicationEvent) {
- if (currentCallStatus == CallStatus.LEAVING) {
- return;
- }
- if (webSocketCommunicationEvent.getHashMap() != null) {
- switch (webSocketCommunicationEvent.getType()) {
- case "hello":
- Log.d(TAG, "onMessageEvent 'hello'");
- if (!webSocketCommunicationEvent.getHashMap().containsKey("oldResumeId")) {
- if (currentCallStatus == CallStatus.RECONNECTING) {
- hangup(false);
- } else {
- setCallState(CallStatus.RECONNECTING);
- runOnUiThread(this::initiateCall);
- }
- }
- break;
- case "roomJoined":
- Log.d(TAG, "onMessageEvent 'roomJoined'");
- startSendingNick();
- if (webSocketCommunicationEvent.getHashMap().get("roomToken").equals(roomToken)) {
- performCall();
- }
- break;
- case "recordingStatus":
- Log.d(TAG, "onMessageEvent 'recordingStatus'");
- if (webSocketCommunicationEvent.getHashMap().containsKey(KEY_RECORDING_STATE)) {
- String recordingStateString =
- webSocketCommunicationEvent.getHashMap().get(KEY_RECORDING_STATE);
- if (recordingStateString != null) {
- runOnUiThread(() -> {
- callRecordingViewModel.setRecordingState(Integer.parseInt(recordingStateString));
- });
- }
- }
- break;
- }
- }
- }
- private void dispose(@Nullable Disposable disposable) {
- if (disposable != null && !disposable.isDisposed()) {
- disposable.dispose();
- } else if (disposable == null) {
- if (signalingDisposable != null && !signalingDisposable.isDisposed()) {
- signalingDisposable.dispose();
- signalingDisposable = null;
- }
- }
- }
- private void receivedSignalingMessages(@Nullable List<Signaling> signalingList) {
- if (signalingList != null) {
- for (Signaling signaling : signalingList) {
- try {
- receivedSignalingMessage(signaling);
- } catch (IOException e) {
- Log.e(TAG, "Failed to process received signaling message", e);
- }
- }
- }
- }
- private void receivedSignalingMessage(Signaling signaling) throws IOException {
- String messageType = signaling.getType();
- if (!isConnectionEstablished() && currentCallStatus != CallStatus.CONNECTING) {
- return;
- }
- if ("usersInRoom".equals(messageType)) {
- internalSignalingMessageReceiver.process((List<Map<String, Object>>) signaling.getMessageWrapper());
- } else if ("message".equals(messageType)) {
- NCSignalingMessage ncSignalingMessage = LoganSquare.parse(signaling.getMessageWrapper().toString(),
- NCSignalingMessage.class);
- internalSignalingMessageReceiver.process(ncSignalingMessage);
- } else {
- Log.e(TAG, "unexpected message type when receiving signaling message");
- }
- }
- private void hangup(boolean shutDownView) {
- Log.d(TAG, "hangup! shutDownView=" + shutDownView);
- if (shutDownView) {
- setCallState(CallStatus.LEAVING);
- }
- stopCallingSound();
- dispose(null);
- if (shutDownView) {
- if (videoCapturer != null) {
- try {
- videoCapturer.stopCapture();
- } catch (InterruptedException e) {
- Log.e(TAG, "Failed to stop capturing while hanging up");
- }
- videoCapturer.dispose();
- videoCapturer = null;
- }
- binding.selfVideoRenderer.release();
- if (audioSource != null) {
- audioSource.dispose();
- audioSource = null;
- }
- runOnUiThread(() -> {
- if (audioManager != null) {
- audioManager.stop();
- audioManager = null;
- }
- });
- if (videoSource != null) {
- videoSource = null;
- }
- if (peerConnectionFactory != null) {
- peerConnectionFactory = null;
- }
- localAudioTrack = null;
- localVideoTrack = null;
- if (TextUtils.isEmpty(credentials) && hasExternalSignalingServer) {
- WebSocketConnectionHelper.deleteExternalSignalingInstanceForUserEntity(-1);
- }
- }
- List<String> peerConnectionIdsToEnd = new ArrayList<String>(peerConnectionWrapperList.size());
- for (PeerConnectionWrapper wrapper : peerConnectionWrapperList) {
- peerConnectionIdsToEnd.add(wrapper.getSessionId());
- }
- for (String sessionId : peerConnectionIdsToEnd) {
- endPeerConnection(sessionId, "video");
- endPeerConnection(sessionId, "screen");
- }
- List<String> callParticipantIdsToEnd = new ArrayList<String>(peerConnectionWrapperList.size());
- for (CallParticipant callParticipant : callParticipants.values()) {
- callParticipantIdsToEnd.add(callParticipant.getCallParticipantModel().getSessionId());
- }
- for (String sessionId : callParticipantIdsToEnd) {
- removeCallParticipant(sessionId);
- }
- ApplicationWideCurrentRoomHolder.getInstance().clear();
- hangupNetworkCalls(shutDownView);
- }
- private void hangupNetworkCalls(boolean shutDownView) {
- Log.d(TAG, "hangupNetworkCalls. shutDownView=" + shutDownView);
- int apiVersion = ApiUtils.getCallApiVersion(conversationUser, new int[]{ApiUtils.APIv4, 1});
- if (callParticipantList != null) {
- callParticipantList.removeObserver(callParticipantListObserver);
- callParticipantList.destroy();
- }
- ncApi.leaveCall(credentials, ApiUtils.getUrlForCall(apiVersion, baseUrl, roomToken))
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(new Observer<GenericOverall>() {
- @Override
- public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
- // unused atm
- }
- @Override
- public void onNext(@io.reactivex.annotations.NonNull GenericOverall genericOverall) {
- if (!switchToRoomToken.isEmpty()) {
- Intent intent = new Intent(context, ChatActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- Bundle bundle = new Bundle();
- bundle.putBoolean(KEY_SWITCH_TO_ROOM, true);
- bundle.putBoolean(KEY_START_CALL_AFTER_ROOM_SWITCH, true);
- bundle.putString(KEY_ROOM_TOKEN, switchToRoomToken);
- bundle.putBoolean(KEY_CALL_VOICE_ONLY, isVoiceOnlyCall);
- intent.putExtras(bundle);
- startActivity(intent);
- finish();
- } else if (shutDownView) {
- finish();
- } else if (currentCallStatus == CallStatus.RECONNECTING
- || currentCallStatus == CallStatus.PUBLISHER_FAILED) {
- initiateCall();
- }
- }
- @Override
- public void onError(@io.reactivex.annotations.NonNull Throwable e) {
- // unused atm
- }
- @Override
- public void onComplete() {
- // unused atm
- }
- });
- }
- private void startVideoCapture() {
- if (videoCapturer != null) {
- videoCapturer.startCapture(1280, 720, 30);
- }
- }
- private void handleCallParticipantsChanged(Collection<Participant> joined, Collection<Participant> updated,
- Collection<Participant> left, Collection<Participant> unchanged) {
- Log.d(TAG, "handleCallParticipantsChanged");
- hasMCU = hasExternalSignalingServer && webSocketClient != null && webSocketClient.hasMCU();
- Log.d(TAG, " hasMCU is " + hasMCU);
- // The signaling session is the same as the Nextcloud session only when the MCU is not used.
- String currentSessionId = callSession;
- if (hasMCU) {
- currentSessionId = webSocketClient.getSessionId();
- }
- Log.d(TAG, " currentSessionId is " + currentSessionId);
- List<Participant> participantsInCall = new ArrayList<>();
- participantsInCall.addAll(joined);
- participantsInCall.addAll(updated);
- participantsInCall.addAll(unchanged);
- boolean isSelfInCall = false;
- Participant selfParticipant = null;
- for (Participant participant : participantsInCall) {
- long inCallFlag = participant.getInCall();
- if (!participant.getSessionId().equals(currentSessionId)) {
- Log.d(TAG, " inCallFlag of participant "
- + participant.getSessionId().substring(0, 4)
- + " : "
- + inCallFlag);
- } else {
- Log.d(TAG, " inCallFlag of currentSessionId: " + inCallFlag);
- isSelfInCall = inCallFlag != 0;
- selfParticipant = participant;
- }
- }
- if (!isSelfInCall && currentCallStatus != CallStatus.LEAVING && ApplicationWideCurrentRoomHolder.getInstance().isInCall()) {
- Log.d(TAG, "Most probably a moderator ended the call for all.");
- hangup(true);
- return;
- }
- if (!isSelfInCall) {
- Log.d(TAG, "Self not in call, disconnecting from all other sessions");
- for (Participant participant : participantsInCall) {
- String sessionId = participant.getSessionId();
- Log.d(TAG, " session that will be removed is: " + sessionId);
- endPeerConnection(sessionId, "video");
- endPeerConnection(sessionId, "screen");
- removeCallParticipant(sessionId);
- }
- return;
- }
- if (currentCallStatus == CallStatus.LEAVING) {
- return;
- }
- if (hasMCU) {
- // Ensure that own publishing peer is set up.
- getOrCreatePeerConnectionWrapperForSessionIdAndType(webSocketClient.getSessionId(), VIDEO_STREAM_TYPE_VIDEO, true);
- }
- boolean selfJoined = false;
- boolean selfParticipantHasAudioOrVideo = participantInCallFlagsHaveAudioOrVideo(selfParticipant);
- for (Participant participant : joined) {
- String sessionId = participant.getSessionId();
- if (sessionId == null) {
- Log.w(TAG, "Null sessionId for call participant, this should not happen: " + participant);
- continue;
- }
- if (sessionId.equals(currentSessionId)) {
- selfJoined = true;
- continue;
- }
- Log.d(TAG, " newSession joined: " + sessionId);
- CallParticipant callParticipant = addCallParticipant(sessionId);
- String userId = participant.getUserId();
- if (userId != null) {
- callParticipants.get(sessionId).setUserId(userId);
- }
- if (participant.getInternal() != null) {
- callParticipants.get(sessionId).setInternal(participant.getInternal());
- }
- String nick;
- if (hasExternalSignalingServer) {
- nick = webSocketClient.getDisplayNameForSession(sessionId);
- } else {
- nick = offerAnswerNickProviders.get(sessionId) != null ? offerAnswerNickProviders.get(sessionId).getNick() : "";
- }
- callParticipants.get(sessionId).setNick(nick);
- boolean participantHasAudioOrVideo = participantInCallFlagsHaveAudioOrVideo(participant);
- // FIXME Without MCU, PeerConnectionWrapper only sends an offer if the local session ID is higher than the
- // remote session ID. However, if the other participant does not have audio nor video that participant
- // will not send an offer, so no connection is actually established when the remote participant has a
- // higher session ID but is not publishing media.
- if ((hasMCU && participantHasAudioOrVideo) ||
- (!hasMCU && selfParticipantHasAudioOrVideo && (!participantHasAudioOrVideo || sessionId.compareTo(currentSessionId) < 0))) {
- getOrCreatePeerConnectionWrapperForSessionIdAndType(sessionId, VIDEO_STREAM_TYPE_VIDEO, false);
- }
- }
- boolean othersInCall = selfJoined ? joined.size() > 1 : joined.size() > 0;
- if (othersInCall && currentCallStatus != CallStatus.IN_CONVERSATION) {
- setCallState(CallStatus.IN_CONVERSATION);
- }
- for (Participant participant : left) {
- String sessionId = participant.getSessionId();
- Log.d(TAG, " oldSession that will be removed is: " + sessionId);
- endPeerConnection(sessionId, "video");
- endPeerConnection(sessionId, "screen");
- removeCallParticipant(sessionId);
- }
- }
- private boolean participantInCallFlagsHaveAudioOrVideo(Participant participant) {
- if (participant == null) {
- return false;
- }
- return (participant.getInCall() & Participant.InCallFlags.WITH_AUDIO) > 0 ||
- (!isVoiceOnlyCall && (participant.getInCall() & Participant.InCallFlags.WITH_VIDEO) > 0);
- }
- private PeerConnectionWrapper getPeerConnectionWrapperForSessionIdAndType(String sessionId, String type) {
- for (PeerConnectionWrapper wrapper : peerConnectionWrapperList) {
- if (wrapper.getSessionId().equals(sessionId)
- && wrapper.getVideoStreamType().equals(type)) {
- return wrapper;
- }
- }
- return null;
- }
- private PeerConnectionWrapper getOrCreatePeerConnectionWrapperForSessionIdAndType(String sessionId,
- String type,
- boolean publisher) {
- PeerConnectionWrapper peerConnectionWrapper;
- if ((peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(sessionId, type)) != null) {
- return peerConnectionWrapper;
- } else {
- if (peerConnectionFactory == null) {
- Log.e(TAG, "peerConnectionFactory was null in getOrCreatePeerConnectionWrapperForSessionIdAndType.");
- Toast.makeText(context, context.getResources().getString(R.string.nc_common_error_sorry),
- Toast.LENGTH_LONG).show();
- hangup(true);
- return null;
- }
- if (hasMCU && publisher) {
- peerConnectionWrapper = new PeerConnectionWrapper(peerConnectionFactory,
- iceServers,
- sdpConstraintsForMCU,
- sessionId,
- callSession,
- localStream,
- true,
- true,
- type,
- signalingMessageReceiver,
- signalingMessageSender);
- } else if (hasMCU) {
- peerConnectionWrapper = new PeerConnectionWrapper(peerConnectionFactory,
- iceServers,
- sdpConstraints,
- sessionId,
- callSession,
- null,
- false,
- true,
- type,
- signalingMessageReceiver,
- signalingMessageSender);
- } else {
- if (!"screen".equals(type)) {
- peerConnectionWrapper = new PeerConnectionWrapper(peerConnectionFactory,
- iceServers,
- sdpConstraints,
- sessionId,
- callSession,
- localStream,
- false,
- false,
- type,
- signalingMessageReceiver,
- signalingMessageSender);
- } else {
- peerConnectionWrapper = new PeerConnectionWrapper(peerConnectionFactory,
- iceServers,
- sdpConstraints,
- sessionId,
- callSession,
- null,
- false,
- false,
- type,
- signalingMessageReceiver,
- signalingMessageSender);
- }
- }
- peerConnectionWrapperList.add(peerConnectionWrapper);
- if (!publisher) {
- CallParticipant callParticipant = callParticipants.get(sessionId);
- if (callParticipant == null) {
- callParticipant = addCallParticipant(sessionId);
- }
- if ("screen".equals(type)) {
- callParticipant.setScreenPeerConnectionWrapper(peerConnectionWrapper);
- } else {
- callParticipant.setPeerConnectionWrapper(peerConnectionWrapper);
- }
- }
- if (publisher) {
- peerConnectionWrapper.addObserver(selfPeerConnectionObserver);
- startSendingNick();
- }
- return peerConnectionWrapper;
- }
- }
- private CallParticipant addCallParticipant(String sessionId) {
- CallParticipant callParticipant = new CallParticipant(sessionId, signalingMessageReceiver);
- callParticipants.put(sessionId, callParticipant);
- SignalingMessageReceiver.CallParticipantMessageListener callParticipantMessageListener =
- new CallActivityCallParticipantMessageListener(sessionId);
- callParticipantMessageListeners.put(sessionId, callParticipantMessageListener);
- signalingMessageReceiver.addListener(callParticipantMessageListener, sessionId);
- if (!hasExternalSignalingServer) {
- OfferAnswerNickProvider offerAnswerNickProvider = new OfferAnswerNickProvider(sessionId);
- offerAnswerNickProviders.put(sessionId, offerAnswerNickProvider);
- signalingMessageReceiver.addListener(offerAnswerNickProvider.getVideoWebRtcMessageListener(), sessionId, "video");
- signalingMessageReceiver.addListener(offerAnswerNickProvider.getScreenWebRtcMessageListener(), sessionId, "screen");
- }
- final CallParticipantModel callParticipantModel = callParticipant.getCallParticipantModel();
- ScreenParticipantDisplayItemManager screenParticipantDisplayItemManager =
- new ScreenParticipantDisplayItemManager(callParticipantModel);
- screenParticipantDisplayItemManagers.put(sessionId, screenParticipantDisplayItemManager);
- callParticipantModel.addObserver(screenParticipantDisplayItemManager, screenParticipantDisplayItemManagersHandler);
- CallParticipantEventDisplayer callParticipantEventDisplayer =
- new CallParticipantEventDisplayer(callParticipantModel);
- callParticipantEventDisplayers.put(sessionId, callParticipantEventDisplayer);
- callParticipantModel.addObserver(callParticipantEventDisplayer, callParticipantEventDisplayersHandler);
- runOnUiThread(() -> {
- addParticipantDisplayItem(callParticipantModel, "video");
- });
- return callParticipant;
- }
- private void endPeerConnection(String sessionId, String type) {
- PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(sessionId, type);
- if (peerConnectionWrapper == null) {
- return;
- }
- if (webSocketClient != null && webSocketClient.getSessionId() != null && webSocketClient.getSessionId().equals(sessionId)) {
- peerConnectionWrapper.removeObserver(selfPeerConnectionObserver);
- }
- CallParticipant callParticipant = callParticipants.get(sessionId);
- if (callParticipant != null) {
- if ("screen".equals(type)) {
- callParticipant.setScreenPeerConnectionWrapper(null);
- } else {
- callParticipant.setPeerConnectionWrapper(null);
- }
- }
- peerConnectionWrapper.removePeerConnection();
- peerConnectionWrapperList.remove(peerConnectionWrapper);
- }
- private void removeCallParticipant(String sessionId) {
- CallParticipant callParticipant = callParticipants.remove(sessionId);
- if (callParticipant == null) {
- return;
- }
- ScreenParticipantDisplayItemManager screenParticipantDisplayItemManager =
- screenParticipantDisplayItemManagers.remove(sessionId);
- callParticipant.getCallParticipantModel().removeObserver(screenParticipantDisplayItemManager);
- CallParticipantEventDisplayer callParticipantEventDisplayer =
- callParticipantEventDisplayers.remove(sessionId);
- callParticipant.getCallParticipantModel().removeObserver(callParticipantEventDisplayer);
- callParticipant.destroy();
- SignalingMessageReceiver.CallParticipantMessageListener listener = callParticipantMessageListeners.remove(sessionId);
- signalingMessageReceiver.removeListener(listener);
- OfferAnswerNickProvider offerAnswerNickProvider = offerAnswerNickProviders.remove(sessionId);
- if (offerAnswerNickProvider != null) {
- signalingMessageReceiver.removeListener(offerAnswerNickProvider.getVideoWebRtcMessageListener());
- signalingMessageReceiver.removeListener(offerAnswerNickProvider.getScreenWebRtcMessageListener());
- }
- runOnUiThread(() -> removeParticipantDisplayItem(sessionId, "video"));
- }
- private void removeParticipantDisplayItem(String sessionId, String videoStreamType) {
- Log.d(TAG, "removeParticipantDisplayItem");
- ParticipantDisplayItem participantDisplayItem = participantDisplayItems.remove(sessionId + "-" + videoStreamType);
- if (participantDisplayItem == null) {
- return;
- }
- participantDisplayItem.destroy();
- if (!isDestroyed()) {
- initGridAdapter();
- }
- }
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onMessageEvent(ConfigurationChangeEvent configurationChangeEvent) {
- powerManagerUtils.setOrientation(Objects.requireNonNull(getResources()).getConfiguration().orientation);
- initGridAdapter();
- updateSelfVideoViewPosition();
- }
- private void updateSelfVideoViewIceConnectionState(PeerConnection.IceConnectionState iceConnectionState) {
- boolean connected = iceConnectionState == PeerConnection.IceConnectionState.CONNECTED ||
- iceConnectionState == PeerConnection.IceConnectionState.COMPLETED;
- // FIXME In voice only calls there is no video view, so the progress bar would appear floating in the middle of
- // nowhere. However, a way to signal that the local participant is not connected to the HPB is still need in
- // that case.
- if (!connected && !isVoiceOnlyCall) {
- binding.selfVideoViewProgressBar.setVisibility(View.VISIBLE);
- } else {
- binding.selfVideoViewProgressBar.setVisibility(View.GONE);
- }
- }
- private void updateSelfVideoViewPosition() {
- Log.d(TAG, "updateSelfVideoViewPosition");
- if (!isInPipMode) {
- FrameLayout.LayoutParams layoutParams =
- (FrameLayout.LayoutParams) binding.selfVideoRenderer.getLayoutParams();
- DisplayMetrics displayMetrics = getApplicationContext().getResources().getDisplayMetrics();
- int screenWidthPx = displayMetrics.widthPixels;
- int screenWidthDp = (int) DisplayUtils.convertPixelToDp(screenWidthPx, getApplicationContext());
- float newXafterRotate = 0;
- float newYafterRotate;
- if (binding.callInfosLinearLayout.getVisibility() == View.VISIBLE) {
- newYafterRotate = 250;
- } else {
- newYafterRotate = 20;
- }
- if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
- layoutParams.height = (int) getResources().getDimension(R.dimen.call_self_video_short_side_length);
- layoutParams.width = (int) getResources().getDimension(R.dimen.call_self_video_long_side_length);
- newXafterRotate = (float) (screenWidthDp - getResources().getDimension(R.dimen.call_self_video_short_side_length) * 0.8);
- } else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
- layoutParams.height = (int) getResources().getDimension(R.dimen.call_self_video_long_side_length);
- layoutParams.width = (int) getResources().getDimension(R.dimen.call_self_video_short_side_length);
- newXafterRotate = (float) (screenWidthDp - getResources().getDimension(R.dimen.call_self_video_short_side_length) * 0.5);
- }
- binding.selfVideoRenderer.setLayoutParams(layoutParams);
- int newXafterRotatePx = (int) DisplayUtils.convertDpToPixel(newXafterRotate, getApplicationContext());
- binding.selfVideoViewWrapper.setY(newYafterRotate);
- binding.selfVideoViewWrapper.setX(newXafterRotatePx);
- }
- }
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onMessageEvent(ProximitySensorEvent proximitySensorEvent) {
- if (!isVoiceOnlyCall) {
- boolean enableVideo = proximitySensorEvent.getProximitySensorEventType() ==
- ProximitySensorEvent.ProximitySensorEventType.SENSOR_FAR && videoOn;
- if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_CAMERA) &&
- (currentCallStatus == CallStatus.CONNECTING || isConnectionEstablished()) && videoOn
- && enableVideo != localVideoTrack.enabled()) {
- toggleMedia(enableVideo, true);
- }
- }
- }
- private void startSendingNick() {
- DataChannelMessage dataChannelMessage = new DataChannelMessage();
- dataChannelMessage.setType("nickChanged");
- Map<String, String> nickChangedPayload = new HashMap<>();
- nickChangedPayload.put("userid", conversationUser.getUserId());
- nickChangedPayload.put("name", conversationUser.getDisplayName());
- dataChannelMessage.setPayloadMap(nickChangedPayload);
- for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
- if (peerConnectionWrapper.isMCUPublisher()) {
- Observable
- .interval(1, TimeUnit.SECONDS)
- .repeatUntil(() -> (!isConnectionEstablished() || isDestroyed()))
- .observeOn(Schedulers.io())
- .subscribe(new Observer<Long>() {
- @Override
- public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
- // unused atm
- }
- @Override
- public void onNext(@io.reactivex.annotations.NonNull Long aLong) {
- peerConnectionWrapper.sendChannelData(dataChannelMessage);
- }
- @Override
- public void onError(@io.reactivex.annotations.NonNull Throwable e) {
- // unused atm
- }
- @Override
- public void onComplete() {
- // unused atm
- }
- });
- break;
- }
- }
- }
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
- @NonNull int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- EffortlessPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults,
- this);
- }
- private void addParticipantDisplayItem(CallParticipantModel callParticipantModel, String videoStreamType) {
- if (callParticipantModel.isInternal() != null && callParticipantModel.isInternal()) {
- return;
- }
- String defaultGuestNick = getResources().getString(R.string.nc_nick_guest);
- ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(baseUrl,
- defaultGuestNick,
- rootEglBase,
- videoStreamType,
- callParticipantModel);
- String sessionId = callParticipantModel.getSessionId();
- participantDisplayItems.put(sessionId + "-" + videoStreamType, participantDisplayItem);
- initGridAdapter();
- }
- private void setCallState(CallStatus callState) {
- if (currentCallStatus == null || currentCallStatus != callState) {
- currentCallStatus = callState;
- if (handler == null) {
- handler = new Handler(Looper.getMainLooper());
- } else {
- handler.removeCallbacksAndMessages(null);
- }
- switch (callState) {
- case CONNECTING:
- handler.post(() -> {
- playCallingSound();
- if (isIncomingCallFromNotification) {
- binding.callStates.callStateTextView.setText(R.string.nc_call_incoming);
- } else {
- binding.callStates.callStateTextView.setText(R.string.nc_call_ringing);
- }
- binding.callConversationNameTextView.setText(conversationName);
- binding.callModeTextView.setText(getDescriptionForCallType());
- if (binding.callStates.callStateRelativeLayout.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateRelativeLayout.setVisibility(View.VISIBLE);
- }
- if (binding.gridview.getVisibility() != View.INVISIBLE) {
- binding.gridview.setVisibility(View.INVISIBLE);
- }
- if (binding.callStates.callStateProgressBar.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateProgressBar.setVisibility(View.VISIBLE);
- }
- if (binding.callStates.errorImageView.getVisibility() != View.GONE) {
- binding.callStates.errorImageView.setVisibility(View.GONE);
- }
- });
- break;
- case CALLING_TIMEOUT:
- handler.post(() -> {
- hangup(false);
- binding.callStates.callStateTextView.setText(R.string.nc_call_timeout);
- binding.callModeTextView.setText(getDescriptionForCallType());
- if (binding.callStates.callStateRelativeLayout.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateRelativeLayout.setVisibility(View.VISIBLE);
- }
- if (binding.callStates.callStateProgressBar.getVisibility() != View.GONE) {
- binding.callStates.callStateProgressBar.setVisibility(View.GONE);
- }
- if (binding.gridview.getVisibility() != View.INVISIBLE) {
- binding.gridview.setVisibility(View.INVISIBLE);
- }
- binding.callStates.errorImageView.setImageResource(R.drawable.ic_av_timer_timer_24dp);
- if (binding.callStates.errorImageView.getVisibility() != View.VISIBLE) {
- binding.callStates.errorImageView.setVisibility(View.VISIBLE);
- }
- });
- break;
- case PUBLISHER_FAILED:
- handler.post(() -> {
- // No calling sound when the publisher failed
- binding.callStates.callStateTextView.setText(R.string.nc_call_reconnecting);
- binding.callModeTextView.setText(getDescriptionForCallType());
- if (binding.callStates.callStateRelativeLayout.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateRelativeLayout.setVisibility(View.VISIBLE);
- }
- if (binding.gridview.getVisibility() != View.INVISIBLE) {
- binding.gridview.setVisibility(View.INVISIBLE);
- }
- if (binding.callStates.callStateProgressBar.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateProgressBar.setVisibility(View.VISIBLE);
- }
- if (binding.callStates.errorImageView.getVisibility() != View.GONE) {
- binding.callStates.errorImageView.setVisibility(View.GONE);
- }
- });
- break;
- case RECONNECTING:
- handler.post(() -> {
- playCallingSound();
- binding.callStates.callStateTextView.setText(R.string.nc_call_reconnecting);
- binding.callModeTextView.setText(getDescriptionForCallType());
- if (binding.callStates.callStateRelativeLayout.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateRelativeLayout.setVisibility(View.VISIBLE);
- }
- if (binding.gridview.getVisibility() != View.INVISIBLE) {
- binding.gridview.setVisibility(View.INVISIBLE);
- }
- if (binding.callStates.callStateProgressBar.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateProgressBar.setVisibility(View.VISIBLE);
- }
- if (binding.callStates.errorImageView.getVisibility() != View.GONE) {
- binding.callStates.errorImageView.setVisibility(View.GONE);
- }
- });
- break;
- case JOINED:
- handler.postDelayed(() -> setCallState(CallStatus.CALLING_TIMEOUT), 45000);
- handler.post(() -> {
- binding.callModeTextView.setText(getDescriptionForCallType());
- if (isIncomingCallFromNotification) {
- binding.callStates.callStateTextView.setText(R.string.nc_call_incoming);
- } else {
- binding.callStates.callStateTextView.setText(R.string.nc_call_ringing);
- }
- if (binding.callStates.callStateRelativeLayout.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateRelativeLayout.setVisibility(View.VISIBLE);
- }
- if (binding.callStates.callStateProgressBar.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateProgressBar.setVisibility(View.VISIBLE);
- }
- if (binding.gridview.getVisibility() != View.INVISIBLE) {
- binding.gridview.setVisibility(View.INVISIBLE);
- }
- if (binding.callStates.errorImageView.getVisibility() != View.GONE) {
- binding.callStates.errorImageView.setVisibility(View.GONE);
- }
- });
- break;
- case IN_CONVERSATION:
- handler.post(() -> {
- stopCallingSound();
- binding.callModeTextView.setText(getDescriptionForCallType());
- if (!isVoiceOnlyCall) {
- binding.callInfosLinearLayout.setVisibility(View.GONE);
- }
- if (!isPushToTalkActive) {
- animateCallControls(false, 5000);
- }
- if (binding.callStates.callStateRelativeLayout.getVisibility() != View.INVISIBLE) {
- binding.callStates.callStateRelativeLayout.setVisibility(View.INVISIBLE);
- }
- if (binding.callStates.callStateProgressBar.getVisibility() != View.GONE) {
- binding.callStates.callStateProgressBar.setVisibility(View.GONE);
- }
- if (binding.gridview.getVisibility() != View.VISIBLE) {
- binding.gridview.setVisibility(View.VISIBLE);
- }
- if (binding.callStates.errorImageView.getVisibility() != View.GONE) {
- binding.callStates.errorImageView.setVisibility(View.GONE);
- }
- });
- break;
- case OFFLINE:
- handler.post(() -> {
- stopCallingSound();
- binding.callStates.callStateTextView.setText(R.string.nc_offline);
- if (binding.callStates.callStateRelativeLayout.getVisibility() != View.VISIBLE) {
- binding.callStates.callStateRelativeLayout.setVisibility(View.VISIBLE);
- }
- if (binding.gridview.getVisibility() != View.INVISIBLE) {
- binding.gridview.setVisibility(View.INVISIBLE);
- }
- if (binding.callStates.callStateProgressBar.getVisibility() != View.GONE) {
- binding.callStates.callStateProgressBar.setVisibility(View.GONE);
- }
- binding.callStates.errorImageView.setImageResource(R.drawable.ic_signal_wifi_off_white_24dp);
- if (binding.callStates.errorImageView.getVisibility() != View.VISIBLE) {
- binding.callStates.errorImageView.setVisibility(View.VISIBLE);
- }
- });
- break;
- case LEAVING:
- handler.post(() -> {
- if (!isDestroyed()) {
- stopCallingSound();
- binding.callModeTextView.setText(getDescriptionForCallType());
- binding.callStates.callStateTextView.setText(R.string.nc_leaving_call);
- binding.callStates.callStateRelativeLayout.setVisibility(View.VISIBLE);
- binding.gridview.setVisibility(View.INVISIBLE);
- binding.callStates.callStateProgressBar.setVisibility(View.VISIBLE);
- binding.callStates.errorImageView.setVisibility(View.GONE);
- }
- });
- break;
- default:
- }
- }
- }
- private String getDescriptionForCallType() {
- String appName = getResources().getString(R.string.nc_app_product_name);
- if (isVoiceOnlyCall) {
- return String.format(getResources().getString(R.string.nc_call_voice), appName);
- } else {
- return String.format(getResources().getString(R.string.nc_call_video), appName);
- }
- }
- private void playCallingSound() {
- stopCallingSound();
- Uri ringtoneUri;
- if (isIncomingCallFromNotification) {
- ringtoneUri = NotificationUtils.INSTANCE.getCallRingtoneUri(getApplicationContext(), appPreferences);
- } else {
- ringtoneUri = Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/raw" +
- "/tr110_1_kap8_3_freiton1");
- }
- if (ringtoneUri != null) {
- mediaPlayer = new MediaPlayer();
- try {
- mediaPlayer.setDataSource(this, ringtoneUri);
- mediaPlayer.setLooping(true);
- AudioAttributes audioAttributes = new AudioAttributes.Builder().setContentType(
- AudioAttributes.CONTENT_TYPE_SONIFICATION)
- .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
- .build();
- mediaPlayer.setAudioAttributes(audioAttributes);
- mediaPlayer.setOnPreparedListener(mp -> mediaPlayer.start());
- mediaPlayer.prepareAsync();
- } catch (IOException e) {
- Log.e(TAG, "Failed to play sound");
- }
- }
- }
- private void stopCallingSound() {
- if (mediaPlayer != null) {
- try {
- if (mediaPlayer.isPlaying()) {
- mediaPlayer.stop();
- }
- } catch (IllegalStateException e) {
- Log.e(TAG, "mediaPlayer was not initialized", e);
- } finally {
- if (mediaPlayer != null) {
- mediaPlayer.release();
- }
- mediaPlayer = null;
- }
- }
- }
- public void addReactionForAnimation(String emoji, String displayName) {
- reactionAnimator.addReaction(emoji, displayName);
- }
- /**
- * Temporary implementation of SignalingMessageReceiver until signaling related code is extracted from
- * CallActivity.
- * <p>
- * All listeners are called in the main thread.
- */
- private static class InternalSignalingMessageReceiver extends SignalingMessageReceiver {
- public void process(List<Map<String, Object>> users) {
- processUsersInRoom(users);
- }
- public void process(NCSignalingMessage message) {
- processSignalingMessage(message);
- }
- }
- private class OfferAnswerNickProvider {
- private final WebRtcMessageListener videoWebRtcMessageListener = new WebRtcMessageListener();
- private final WebRtcMessageListener screenWebRtcMessageListener = new WebRtcMessageListener();
- private final String sessionId;
- private String nick;
- private class WebRtcMessageListener implements SignalingMessageReceiver.WebRtcMessageListener {
- @Override
- public void onOffer(String sdp, String nick) {
- onOfferOrAnswer(nick);
- }
- @Override
- public void onAnswer(String sdp, String nick) {
- onOfferOrAnswer(nick);
- }
- @Override
- public void onCandidate(String sdpMid, int sdpMLineIndex, String sdp) {
- }
- @Override
- public void onEndOfCandidates() {
- }
- }
- private OfferAnswerNickProvider(String sessionId) {
- this.sessionId = sessionId;
- }
- private void onOfferOrAnswer(String nick) {
- this.nick = nick;
- if (callParticipants.get(sessionId) != null) {
- callParticipants.get(sessionId).setNick(nick);
- }
- }
- public WebRtcMessageListener getVideoWebRtcMessageListener() {
- return videoWebRtcMessageListener;
- }
- public WebRtcMessageListener getScreenWebRtcMessageListener() {
- return screenWebRtcMessageListener;
- }
- public String getNick() {
- return nick;
- }
- }
- private class CallActivityCallParticipantMessageListener implements SignalingMessageReceiver.CallParticipantMessageListener {
- private final String sessionId;
- public CallActivityCallParticipantMessageListener(String sessionId) {
- this.sessionId = sessionId;
- }
- @Override
- public void onRaiseHand(boolean state, long timestamp) {
- }
- @Override
- public void onReaction(String reaction) {
- }
- @Override
- public void onUnshareScreen() {
- endPeerConnection(sessionId, "screen");
- }
- }
- private class CallActivitySelfPeerConnectionObserver implements PeerConnectionWrapper.PeerConnectionObserver {
- @Override
- public void onStreamAdded(MediaStream mediaStream) {
- }
- @Override
- public void onStreamRemoved(MediaStream mediaStream) {
- }
- @Override
- public void onIceConnectionStateChanged(PeerConnection.IceConnectionState iceConnectionState) {
- runOnUiThread(() -> {
- updateSelfVideoViewIceConnectionState(iceConnectionState);
- if (iceConnectionState == PeerConnection.IceConnectionState.FAILED) {
- setCallState(CallStatus.PUBLISHER_FAILED);
- webSocketClient.clearResumeId();
- hangup(false);
- }
- });
- }
- }
- private class ScreenParticipantDisplayItemManager implements CallParticipantModel.Observer {
- private final CallParticipantModel callParticipantModel;
- private ScreenParticipantDisplayItemManager(CallParticipantModel callParticipantModel) {
- this.callParticipantModel = callParticipantModel;
- }
- @Override
- public void onChange() {
- String sessionId = callParticipantModel.getSessionId();
- if (callParticipantModel.getScreenIceConnectionState() == null) {
- removeParticipantDisplayItem(sessionId, "screen");
- return;
- }
- boolean hasScreenParticipantDisplayItem = participantDisplayItems.get(sessionId + "-screen") != null;
- if (!hasScreenParticipantDisplayItem) {
- addParticipantDisplayItem(callParticipantModel, "screen");
- }
- }
- @Override
- public void onReaction(String reaction) {
- }
- }
- private class CallParticipantEventDisplayer implements CallParticipantModel.Observer {
- private final CallParticipantModel callParticipantModel;
- private boolean raisedHand;
- private CallParticipantEventDisplayer(CallParticipantModel callParticipantModel) {
- this.callParticipantModel = callParticipantModel;
- this.raisedHand = callParticipantModel.getRaisedHand() != null ?
- callParticipantModel.getRaisedHand().getState() : false;
- }
- @Override
- public void onChange() {
- if (callParticipantModel.getRaisedHand() == null || !callParticipantModel.getRaisedHand().getState()) {
- raisedHand = false;
- return;
- }
- if (raisedHand) {
- return;
- }
- raisedHand = true;
- String nick = callParticipantModel.getNick();
- Toast.makeText(context, String.format(context.getResources().getString(R.string.nc_call_raised_hand), nick), Toast.LENGTH_LONG).show();
- }
- @Override
- public void onReaction(String reaction) {
- addReactionForAnimation(reaction, callParticipantModel.getNick());
- }
- }
- private class InternalSignalingMessageSender implements SignalingMessageSender {
- @Override
- public void send(NCSignalingMessage ncSignalingMessage) {
- addLocalParticipantNickIfNeeded(ncSignalingMessage);
- String serializedNcSignalingMessage;
- try {
- serializedNcSignalingMessage = LoganSquare.serialize(ncSignalingMessage);
- } catch (IOException e) {
- Log.e(TAG, "Failed to serialize signaling message", e);
- return;
- }
- // The message wrapper can not be defined in a JSON model to be directly serialized, as sent messages
- // need to be serialized twice; first the signaling message, and then the wrapper as a whole. Received
- // messages, on the other hand, just need to be deserialized once.
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append('{')
- .append("\"fn\":\"")
- .append(StringEscapeUtils.escapeJson(serializedNcSignalingMessage))
- .append('\"')
- .append(',')
- .append("\"sessionId\":")
- .append('\"').append(StringEscapeUtils.escapeJson(callSession)).append('\"')
- .append(',')
- .append("\"ev\":\"message\"")
- .append('}');
- List<String> strings = new ArrayList<>();
- String stringToSend = stringBuilder.toString();
- strings.add(stringToSend);
- int apiVersion = ApiUtils.getSignalingApiVersion(conversationUser, new int[]{ApiUtils.APIv3, 2, 1});
- ncApi.sendSignalingMessages(credentials, ApiUtils.getUrlForSignaling(apiVersion, baseUrl, roomToken),
- strings.toString())
- .retry(3)
- .subscribeOn(Schedulers.io())
- .subscribe(new Observer<SignalingOverall>() {
- @Override
- public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
- }
- @Override
- public void onNext(@io.reactivex.annotations.NonNull SignalingOverall signalingOverall) {
- // When sending messages to the internal signaling server the response has been empty since
- // Talk v2.9.0, so it is not really needed to process it, but there is no harm either in
- // doing that, as technically messages could be returned.
- receivedSignalingMessages(signalingOverall.getOcs().getSignalings());
- }
- @Override
- public void onError(@io.reactivex.annotations.NonNull Throwable e) {
- Log.e(TAG, "", e);
- }
- @Override
- public void onComplete() {
- }
- });
- }
- /**
- * Adds the local participant nick to offers and answers.
- * <p>
- * For legacy reasons the offers and answers sent when the internal signaling server is used are expected to
- * provide the nick of the local participant.
- *
- * @param ncSignalingMessage the message to add the nick to
- */
- private void addLocalParticipantNickIfNeeded(NCSignalingMessage ncSignalingMessage) {
- String type = ncSignalingMessage.getType();
- if (!"offer".equals(type) && !"answer".equals(type)) {
- return;
- }
- NCMessagePayload payload = ncSignalingMessage.getPayload();
- if (payload == null) {
- // Broken message, this should not happen
- return;
- }
- payload.setNick(conversationUser.getDisplayName());
- }
- }
- private class MicrophoneButtonTouchListener implements View.OnTouchListener {
- @SuppressLint("ClickableViewAccessibility")
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- v.onTouchEvent(event);
- if (event.getAction() == MotionEvent.ACTION_UP && isPushToTalkActive) {
- isPushToTalkActive = false;
- binding.microphoneButton.setImageResource(R.drawable.ic_mic_off_white_24px);
- pulseAnimation.stop();
- toggleMedia(false, false);
- animateCallControls(false, 5000);
- }
- return true;
- }
- }
- @Subscribe(threadMode = ThreadMode.BACKGROUND)
- public void onMessageEvent(NetworkEvent networkEvent) {
- if (networkEvent.getNetworkConnectionEvent() == NetworkEvent.NetworkConnectionEvent.NETWORK_CONNECTED) {
- if (handler != null) {
- handler.removeCallbacksAndMessages(null);
- }
- } else if (networkEvent.getNetworkConnectionEvent() ==
- NetworkEvent.NetworkConnectionEvent.NETWORK_DISCONNECTED) {
- if (handler != null) {
- handler.removeCallbacksAndMessages(null);
- }
- }
- }
- @RequiresApi(api = Build.VERSION_CODES.O)
- @Override
- public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
- super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
- Log.d(TAG, "onPictureInPictureModeChanged");
- Log.d(TAG, "isInPictureInPictureMode= " + isInPictureInPictureMode);
- isInPipMode = isInPictureInPictureMode;
- if (isInPictureInPictureMode) {
- mReceiver =
- new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (intent == null || !MICROPHONE_PIP_INTENT_NAME.equals(intent.getAction())) {
- return;
- }
- final int action = intent.getIntExtra(MICROPHONE_PIP_INTENT_EXTRA_ACTION, 0);
- switch (action) {
- case MICROPHONE_PIP_REQUEST_MUTE:
- case MICROPHONE_PIP_REQUEST_UNMUTE:
- onMicrophoneClick();
- break;
- }
- }
- };
- registerReceiver(mReceiver,
- new IntentFilter(MICROPHONE_PIP_INTENT_NAME),
- permissionUtil.getPrivateBroadcastPermission(),
- null);
- updateUiForPipMode();
- } else {
- unregisterReceiver(mReceiver);
- mReceiver = null;
- updateUiForNormalMode();
- }
- }
- void updatePictureInPictureActions(
- @DrawableRes int iconId,
- String title,
- int requestCode) {
- if (isGreaterEqualOreo() && isPipModePossible()) {
- final ArrayList<RemoteAction> actions = new ArrayList<>();
- final Icon icon = Icon.createWithResource(this, iconId);
- int intentFlag;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
- intentFlag = FLAG_IMMUTABLE;
- } else {
- intentFlag = 0;
- }
- final PendingIntent intent =
- PendingIntent.getBroadcast(
- this,
- requestCode,
- new Intent(MICROPHONE_PIP_INTENT_NAME).putExtra(MICROPHONE_PIP_INTENT_EXTRA_ACTION, requestCode),
- intentFlag);
- actions.add(new RemoteAction(icon, title, title, intent));
- mPictureInPictureParamsBuilder.setActions(actions);
- setPictureInPictureParams(mPictureInPictureParamsBuilder.build());
- }
- }
- public void updateUiForPipMode() {
- Log.d(TAG, "updateUiForPipMode");
- RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
- ViewGroup.LayoutParams.WRAP_CONTENT);
- params.setMargins(0, 0, 0, 0);
- binding.gridview.setLayoutParams(params);
- binding.callControls.setVisibility(View.GONE);
- binding.callInfosLinearLayout.setVisibility(View.GONE);
- binding.selfVideoViewWrapper.setVisibility(View.GONE);
- binding.callStates.callStateRelativeLayout.setVisibility(View.GONE);
- if (participantDisplayItems.size() > 1) {
- binding.pipCallConversationNameTextView.setText(conversationName);
- binding.pipGroupCallOverlay.setVisibility(View.VISIBLE);
- } else {
- binding.pipGroupCallOverlay.setVisibility(View.GONE);
- }
- binding.selfVideoRenderer.release();
- }
- public void updateUiForNormalMode() {
- Log.d(TAG, "updateUiForNormalMode");
- if (isVoiceOnlyCall) {
- binding.callControls.setVisibility(View.VISIBLE);
- } else {
- // animateCallControls needs this to be invisible for a check.
- binding.callControls.setVisibility(View.INVISIBLE);
- }
- initViews();
- binding.callInfosLinearLayout.setVisibility(View.VISIBLE);
- binding.selfVideoViewWrapper.setVisibility(View.VISIBLE);
- binding.pipGroupCallOverlay.setVisibility(View.GONE);
- }
- @Override
- public void suppressFitsSystemWindows() {
- binding.controllerCallLayout.setFitsSystemWindows(false);
- }
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- eventBus.post(new ConfigurationChangeEvent());
- }
- public boolean isAllowedToStartOrStopRecording() {
- return CapabilitiesUtilNew.isCallRecordingAvailable(conversationUser)
- && isModerator;
- }
- public boolean isAllowedToRaiseHand() {
- return CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "raise-hand") ||
- isBreakoutRoom;
- }
- private class SelfVideoTouchListener implements View.OnTouchListener {
- @SuppressLint("ClickableViewAccessibility")
- @Override
- public boolean onTouch(View view, MotionEvent event) {
- long duration = event.getEventTime() - event.getDownTime();
- if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
- float newY = event.getRawY() - binding.selfVideoViewWrapper.getHeight() / (float) 2;
- float newX = event.getRawX() - binding.selfVideoViewWrapper.getWidth() / (float) 2;
- binding.selfVideoViewWrapper.setY(newY);
- binding.selfVideoViewWrapper.setX(newX);
- } else if (event.getActionMasked() == MotionEvent.ACTION_UP && duration < 100) {
- switchCamera();
- }
- return true;
- }
- }
- }
|