コード例 #1
0
 protected override void OnRestart()
 {
     try
     {
         base.OnRestart();
         TwilioVideo = TwilioVideoHelper.GetOrCreate(this, TypeCall.Audio);
         UpdateState();
     }
     catch (Exception e)
     {
         Methods.DisplayReportResultTrack(e);
     }
 }
コード例 #2
0
        public static TwilioVideoHelper GetOrCreate(Context context, TypeCall typeCall)
        {
            try
            {
                TypeCall = typeCall;

                if (Instance == null)
                {
                    Instance = new TwilioVideoHelper();
                }

                if (Instance.CurrentVideoTrack == null || Instance.CurrentAudioTrack == null)
                {
                    Instance.CreateLocalMedia(context);
                }

                return(Instance);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(null);
            }
        }
コード例 #3
0
        private async void InitTwilioCall()
        {
            try
            {
                bool granted =
                    ContextCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.Camera) ==
                    Permission.Granted &&
                    ContextCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.RecordAudio) ==
                    Permission.Granted;

                CheckVideoCallPermissions(granted);

                UserId = Intent?.GetStringExtra("UserID");
                Avatar = Intent?.GetStringExtra("avatar");
                Name   = Intent?.GetStringExtra("name");

                var dataCallId = Intent?.GetStringExtra("CallID") ?? "Data not available";
                if (dataCallId != "Data not available" && !string.IsNullOrEmpty(dataCallId))
                {
                    CallId = dataCallId;

                    TwilioAccessToken      = Intent?.GetStringExtra("access_token");
                    TwilioAccessTokenUser2 = Intent?.GetStringExtra("access_token_2");
                    FromId   = Intent?.GetStringExtra("from_id");
                    Active   = Intent?.GetStringExtra("active");
                    Time     = Intent?.GetStringExtra("time");
                    Status   = Intent?.GetStringExtra("status");
                    RoomName = Intent?.GetStringExtra("room_name");
                    CallType = Intent?.GetStringExtra("type");
                }
                Console.WriteLine(Time);

                switch (CallType)
                {
                case "Twilio_audio_call":
                {
                    if (!string.IsNullOrEmpty(TwilioAccessToken))
                    {
                        if (!string.IsNullOrEmpty(UserId))
                        {
                            Load_userWhenCall();
                        }

                        TwilioVideo = TwilioVideoHelper.GetOrCreate(this, TypeCall.Audio);
                        UpdateState();
                        DurationTextView.Text = GetText(Resource.String.Lbl_Waiting_for_answer);

                        var(apiStatus, respond) = await RequestsAsync.Call.AnswerCallAsync(UserDetails.UserId, CallId, TypeCall.Audio);

                        if (apiStatus == 200)
                        {
                            ConnectToRoom();

                            var ckd = GlobalContext?.LastCallsTab?.MAdapter?.MCallUser?.FirstOrDefault(a => a.Id == CallId);         // id >> Call_Id
                            if (ckd == null)
                            {
                                Classes.CallUser cv = new Classes.CallUser
                                {
                                    Id        = CallId,
                                    UserId    = UserId,
                                    Avatar    = Avatar,
                                    Name      = Name,
                                    FromId    = FromId,
                                    Active    = Active,
                                    Time      = "Answered call",
                                    Status    = Status,
                                    RoomName  = RoomName,
                                    Type      = CallType,
                                    TypeIcon  = "Accept",
                                    TypeColor = "#008000"
                                };

                                GlobalContext?.LastCallsTab?.MAdapter?.Insert(cv);

                                SqLiteDatabase dbDatabase = new SqLiteDatabase();
                                dbDatabase.Insert_CallUser(cv);
                            }
                        }
                        //else Methods.DisplayReportResult(this, respond);
                    }

                    break;
                }

                case "Twilio_audio_calling_start":
                    DurationTextView.Text = GetText(Resource.String.Lbl_Calling);
                    TwilioVideo           = TwilioVideoHelper.GetOrCreate(this, TypeCall.Audio);

                    Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("mystic_call.mp3", "left");

                    StartApiService();

                    UpdateState();
                    break;
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }