private void RejectCallButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (CallType == "Twilio_video_call")
                {
                    RequestsAsync.Call.DeclineCallAsync(UserDetails.UserId, CallId, TypeCall.Video).ConfigureAwait(false);
                }
                else if (CallType == "Twilio_audio_call")
                {
                    RequestsAsync.Call.DeclineCallAsync(UserDetails.UserId, CallId, TypeCall.Audio).ConfigureAwait(false);
                }
                else if (CallType == "Agora_video_call_recieve" || CallType == "Agora_audio_call_recieve")
                {
                    ApiRequest.Send_Agora_Call_Action_Async("decline", CallId).ConfigureAwait(false);
                }

                if (!string.IsNullOrEmpty(CallId))
                {
                    var ckd = TabbedMainActivity.GetInstance().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,
                            AccessToken  = TwilioAccessToken,
                            AccessToken2 = TwilioAccessTokenUser2,
                            FromId       = FromId,
                            Active       = Active,
                            Time         = "Missed call",
                            Status       = Status,
                            RoomName     = RoomName,
                            Type         = CallType,
                            TypeIcon     = "Cancel",
                            TypeColor    = "#FF0000"
                        };

                        TabbedMainActivity.GetInstance().LastCallsTab.MAdapter?.Insert(cv);

                        SqLiteDatabase dbDatabase = new SqLiteDatabase();
                        dbDatabase.Insert_CallUser(cv);
                        dbDatabase.Dispose();
                    }
                }

                FinishVideoAudio();
            }
            catch (Exception exception)
            {
                FinishVideoAudio();
                Console.WriteLine(exception);
            }
        }
Exemple #2
0
        private void Initialize(LastCallsAdapterViewHolder holder, Classes.CallUser item)
        {
            try
            {
                GlideImageLoader.LoadImage(ActivityContext, item.Avatar, holder.ImageAvatar, ImageStyle.CircleCrop, ImagePlaceholders.Drawable);

                string name = Methods.FunString.DecodeString(item.Name);
                holder.TxtUsername.Text = name;

                switch (item.TypeIcon)
                {
                case "Accept":
                    Glide.With(ActivityContext).Load(Resource.Drawable.social_ic_phone_calls).Into(holder.IconCall);
                    break;

                case "Cancel":
                    Glide.With(ActivityContext).Load(Resource.Drawable.social_ic_phone_call_arrow).Into(holder.IconCall);
                    break;

                case "Declined":
                    Glide.With(ActivityContext).Load(Resource.Drawable.social_ic_forward_call).Into(holder.IconCall);
                    break;
                }

                switch (item.Time)
                {
                case "Declined call":
                    holder.TxtLastTimecall.Text = ActivityContext.GetText(Resource.String.Lbl_NotAnswered_call);
                    break;

                case "Missed call":
                    holder.TxtLastTimecall.Text = ActivityContext.GetText(Resource.String.Lbl_Missed_call);
                    break;

                case "Answered call":
                    holder.TxtLastTimecall.Text = ActivityContext.GetText(Resource.String.Lbl_Answered_call);
                    break;

                default:
                    holder.TxtLastTimecall.Text = item.Time;
                    break;
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
Exemple #3
0
 // Function Call
 public void Insert(Classes.CallUser call)
 {
     try
     {
         var check = MCallUser.FirstOrDefault(a => a.Id == call.Id);
         if (check == null)
         {
             MCallUser.Insert(0, call);
             NotifyItemInserted(0);
             MsgTabbedMainActivity.GetInstance().LastCallsTab.MRecycler?.ScrollToPosition(0);
         }
     }
     catch (Exception e)
     {
         Methods.DisplayReportResultTrack(e);
     }
 }
 // Function Call
 public void Insert(Classes.CallUser call)
 {
     try
     {
         var check = MCallUser.FirstOrDefault(a => a.Id == call.Id);
         if (check == null)
         {
             MCallUser.Insert(0, call);
             NotifyItemInserted(0);
             TabbedMainActivity.GetInstance().LastCallsTab.MRecycler?.ScrollToPosition(0);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
        public async void OnCallTime_Running_Out()
        {
            try
            {
                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      = "Missed call",
                        Status    = Status,
                        RoomName  = RoomName,
                        Type      = CallType,
                        TypeIcon  = "Cancel",
                        TypeColor = "#FF0000"
                    };

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

                    SqLiteDatabase dbDatabase = new SqLiteDatabase();
                    dbDatabase.Insert_CallUser(cv);
                    dbDatabase.Dispose();
                }
                Methods.AudioRecorderAndPlayer.StopAudioFromAsset();
                Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("Error.mp3");
                DurationTextView.Text = GetText(Resource.String.Lbl_No_respond_from_the_user);
                await Task.Delay(3000);

                AgoraEngine.LeaveChannel();
                AgoraEngine.Dispose();
                AgoraEngine = null;
                Finish();
            }
            catch (Exception e)
            {
                Finish();
                Console.WriteLine(e);
            }
        }
        private void Initialize(LastCallsAdapterViewHolder holder, Classes.CallUser item)
        {
            try
            {
                GlideImageLoader.LoadImage(ActivityContext, item.Avatar, holder.ImageAvatar, ImageStyle.CircleCrop, ImagePlaceholders.Drawable);

                string name = Methods.FunString.DecodeString(item.Name);
                holder.TxtUsername.Text = name;

                if (item.TypeIcon == "Accept")
                {
                    Glide.With(ActivityContext).Load(Resource.Drawable.social_ic_phone_calls).Into(holder.IconCall);
                }
                else if (item.TypeIcon == "Cancel")
                {
                    Glide.With(ActivityContext).Load(Resource.Drawable.social_ic_phone_call_arrow).Into(holder.IconCall);
                }
                else if (item.TypeIcon == "Declined")
                {
                    Glide.With(ActivityContext).Load(Resource.Drawable.social_ic_forward_call).Into(holder.IconCall);
                }

                if (item.Time == "Declined call")
                {
                    holder.TxtLastTimecall.Text = ActivityContext.GetText(Resource.String.Lbl_Declined_call);
                }
                else if (item.Time == "Missed call")
                {
                    holder.TxtLastTimecall.Text = ActivityContext.GetText(Resource.String.Lbl_Missed_call);
                }
                else if (item.Time == "Answered call")
                {
                    holder.TxtLastTimecall.Text = ActivityContext.GetText(Resource.String.Lbl_Answered_call);
                }
                else
                {
                    holder.TxtLastTimecall.Text = item.Time;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemple #7
0
        public static async Task <Classes.CallUser> Create_Agora_Call_Event_Async(string recipientId, string callType)
        {
            try
            {
                var formContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("user_id", UserDetails.UserId),
                    new KeyValuePair <string, string>("recipient_id", recipientId),
                    new KeyValuePair <string, string>("call_type", callType),
                    new KeyValuePair <string, string>("s", UserDetails.AccessToken)
                });

                var response = await RestHttp.Client.PostAsync(ApiCreateAgoraCallEvent, formContent);

                string json = await response.Content.ReadAsStringAsync();

                var    data      = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);
                string apiStatus = data["status"].ToString();
                if (apiStatus == "200")
                {
                    Classes.CallUser vidodata = new Classes.CallUser();

                    if (data.ContainsKey("id"))
                    {
                        vidodata.Id = data["id"]?.ToString();
                    }
                    if (data.ContainsKey("room_name"))
                    {
                        vidodata.RoomName = data["room_name"]?.ToString();
                    }

                    vidodata.Type = callType;

                    return(vidodata);
                }

                return(null);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(null);
            }
        }
        private async void TimerCallRequestAnswer_Waiter_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                var(apiStatus, respond) = await RequestsAsync.Call.CheckForAnswerAsync(UserDetails.UserId, CallId, TypeCall.Video);

                if (apiStatus == 200)
                {
                    Methods.AudioRecorderAndPlayer.StopAudioFromAsset();

                    if (!string.IsNullOrEmpty(TwilioAccessToken))
                    {
                        TimerRequestWaiter.Enabled = false;
                        TimerRequestWaiter.Stop();
                        TimerRequestWaiter.Close();

                        RunOnUiThread(async() =>
                        {
                            await Task.Delay(1000);

                            TwilioVideo?.UpdateToken(TwilioAccessTokenUser2);
                            TwilioVideo?.JoinRoom(ApplicationContext, RoomName);

                            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);
                            dbDatabase.Dispose();
                        });
                    }
                }
                else if (apiStatus == 300)
                {
                    RunOnUiThread(() =>
                    {
                        try
                        {
                            if (CountSecondsOfOutGoingCall < 70)
                            {
                                CountSecondsOfOutGoingCall += 10;
                            }
                            else
                            {
                                //Call Is inactive
                                TimerRequestWaiter.Enabled = false;
                                TimerRequestWaiter.Stop();
                                TimerRequestWaiter.Close();

                                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      = "Missed call",
                                        Status    = Status,
                                        RoomName  = RoomName,
                                        Type      = CallType,
                                        TypeIcon  = "Cancel",
                                        TypeColor = "#FF0000"
                                    };

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

                                    SqLiteDatabase dbDatabase = new SqLiteDatabase();
                                    dbDatabase.Insert_CallUser(cv);
                                    dbDatabase.Dispose();
                                }

                                FinishCall();
                            }
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception);
                        }
                    });
                }
                else
                {
                    RunOnUiThread(() =>
                    {
                        try
                        {
                            //Call Is inactive
                            TimerRequestWaiter.Enabled = false;
                            TimerRequestWaiter.Stop();
                            TimerRequestWaiter.Close();

                            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      = "Declined call",
                                    Status    = Status,
                                    RoomName  = RoomName,
                                    Type      = CallType,
                                    TypeIcon  = "Declined",
                                    TypeColor = "#FF8000"
                                };

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

                                SqLiteDatabase dbDatabase = new SqLiteDatabase();
                                dbDatabase.Insert_CallUser(cv);
                                dbDatabase.Dispose();
                            }

                            FinishCall();

                            //Methods.DisplayReportResult(this, respond);
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine(exception);
                        }
                    });
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
        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");
                }

                if (CallType == "Twilio_video_call")
                {
                    if (!string.IsNullOrEmpty(TwilioAccessToken))
                    {
                        if (!string.IsNullOrEmpty(UserId))
                        {
                            Load_userWhenCall();
                        }

                        TwilioVideo = TwilioVideoHelper.GetOrCreate(this);
                        UpdateState();
                        NoteTextView.Text = GetText(Resource.String.Lbl_Waiting_for_answer);

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

                        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);
                                dbDatabase.Dispose();
                            }
                        }
                        //else Methods.DisplayReportResult(this, respond);
                    }
                }
                else if (CallType == "Twilio_video_calling_start")
                {
                    StartApiService();

                    NoteTextView.Text = GetText(Resource.String.Lbl_Calling_video);
                    TwilioVideo       = TwilioVideoHelper.GetOrCreate(this);

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

                    UpdateState();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        private async void TimerCallRequestAnswer_Waiter_Elapsed(object sender, ElapsedEventArgs e)
        {
            try
            {
                var callResultGeneration = await ApiRequest.Check_Agora_Call_Answer_Async(CallId, "audio");

                if (string.IsNullOrEmpty(callResultGeneration))
                {
                    return;
                }

                if (callResultGeneration == "answered")
                {
                    TimerRequestWaiter.Enabled = false;
                    TimerRequestWaiter.Stop();
                    TimerRequestWaiter.Close();

                    RunOnUiThread(() =>
                    {
                        Methods.AudioRecorderAndPlayer.StopAudioFromAsset();
                        InitAgoraEngineAndJoinChannel(RoomName);
                    });

                    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);
                        dbDatabase.Dispose();
                    }
                }
                else if (callResultGeneration == "calling")
                {
                    if (CountSecoundsOfOutgoingCall < 80)
                    {
                        CountSecoundsOfOutgoingCall += 10;
                    }
                    else
                    {
                        //Call Is inactive
                        TimerRequestWaiter.Enabled = false;
                        TimerRequestWaiter.Stop();
                        TimerRequestWaiter.Close();

                        RunOnUiThread(OnCallTime_Running_Out);
                    }
                }
                else if (callResultGeneration == "declined")
                {
                    TimerRequestWaiter.Enabled = false;
                    TimerRequestWaiter.Stop();
                    TimerRequestWaiter.Close();

                    RunOnUiThread(OnCall_Declined_From_User);

                    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      = "Declined call",
                            Status    = Status,
                            RoomName  = RoomName,
                            Type      = CallType,
                            TypeIcon  = "Declined",
                            TypeColor = "#FF8000"
                        };

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

                        SqLiteDatabase dbDatabase = new SqLiteDatabase();
                        dbDatabase.Insert_CallUser(cv);
                        dbDatabase.Dispose();
                    }
                }
                else if (callResultGeneration == "no_answer")
                {
                    //Call Is inactive
                    TimerRequestWaiter.Enabled = false;
                    TimerRequestWaiter.Stop();
                    TimerRequestWaiter.Close();

                    RunOnUiThread(OnCallTime_Running_Out);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }
        }
        public async void Start_Call_Action(string type)
        {
            try
            {
                if (type == "call")
                {
                    DurationTextView.Text = GetText(Resource.String.Lbl_Calling);
                    var apiStartCall = await ApiRequest.Create_Agora_Call_Event_Async(UserId, "audio");

                    if (apiStartCall != null && !string.IsNullOrEmpty(apiStartCall.RoomName) && !string.IsNullOrEmpty(apiStartCall.Id))
                    {
                        if (!string.IsNullOrEmpty(apiStartCall.RoomName))
                        {
                            RoomName = apiStartCall.RoomName;
                        }
                        if (!string.IsNullOrEmpty(apiStartCall.Id))
                        {
                            CallId = apiStartCall.Id;
                        }
                        Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("mystic_call.mp3", "left");

                        TimerRequestWaiter          = new Timer();
                        TimerRequestWaiter.Interval = 5000;
                        TimerRequestWaiter.Elapsed += TimerCallRequestAnswer_Waiter_Elapsed;
                        TimerRequestWaiter.Start();
                        InitAgoraEngineAndJoinChannel(RoomName); //the caller Is Joining agora Server
                    }
                }
                else
                {
                    RoomName = Intent.GetStringExtra("room_name");
                    CallId   = Intent.GetStringExtra("CallID");
                    DurationTextView.Text = GetText(Resource.String.Lbl_Waiting_to_connect);

                    var apiStartCall = await ApiRequest.Send_Agora_Call_Action_Async("answer", CallId);

                    if (apiStartCall == "200")
                    {
                        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);
                            dbDatabase.Dispose();
                        }
                        InitAgoraEngineAndJoinChannel(RoomName); //the caller Is Joining agora Server
                    }
                    else
                    {
                        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      = "Missed call",
                                Status    = Status,
                                RoomName  = RoomName,
                                Type      = CallType,
                                TypeIcon  = "Cancel",
                                TypeColor = "#FF0000"
                            };

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

                            SqLiteDatabase dbDatabase = new SqLiteDatabase();
                            dbDatabase.Insert_CallUser(cv);
                            dbDatabase.Dispose();
                        }

                        DurationTextView.Text = GetText(Resource.String.Lbl_Faild_to_connect);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
        private void MAdapterOnCallClick(object sender, LastCallsAdapterClickEventArgs adapterClickEvents)
        {
            try
            {
                var position = adapterClickEvents.Position;
                if (position >= 0)
                {
                    var item = MAdapter.GetItem(position);
                    if (item != null)
                    {
                        DataUser = item;

                        string timeNow       = DateTime.Now.ToString("hh:mm");
                        var    unixTimestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
                        string time          = Convert.ToString(unixTimestamp);

                        if (AppSettings.EnableAudioCall && AppSettings.EnableVideoCall)
                        {
                            var arrayAdapter = new List <string>();
                            var dialogList   = new MaterialDialog.Builder(Context).Theme(AppSettings.SetTabDarkTheme ? Theme.Dark : Theme.Light);

                            arrayAdapter.Add(Context.GetText(Resource.String.Lbl_Voice_call));
                            arrayAdapter.Add(Context.GetText(Resource.String.Lbl_Video_call));

                            dialogList.Title(GetText(Resource.String.Lbl_Call));
                            //dialogList.Content(GetText(Resource.String.Lbl_Select_Type_Call));
                            dialogList.Items(arrayAdapter);
                            dialogList.PositiveText(GetText(Resource.String.Lbl_Close)).OnPositive(this);
                            dialogList.AlwaysCallSingleChoiceCallback();
                            dialogList.ItemsCallback(this).Build().Show();
                        }
                        else if (AppSettings.EnableAudioCall == false && AppSettings.EnableVideoCall) // Video Call On
                        {
                            try
                            {
                                Intent intentVideoCall = new Intent(Context, typeof(TwilioVideoCallActivity));
                                if (AppSettings.UseLibrary == SystemCall.Agora)
                                {
                                    intentVideoCall = new Intent(Context, typeof(AgoraVideoCallActivity));
                                    intentVideoCall.PutExtra("type", "Agora_video_calling_start");
                                }
                                else if (AppSettings.UseLibrary == SystemCall.Twilio)
                                {
                                    intentVideoCall = new Intent(Context, typeof(TwilioVideoCallActivity));
                                    intentVideoCall.PutExtra("type", "Twilio_video_calling_start");
                                }

                                intentVideoCall.PutExtra("UserID", item.UserId);
                                intentVideoCall.PutExtra("avatar", item.Avatar);
                                intentVideoCall.PutExtra("name", item.Name);
                                intentVideoCall.PutExtra("time", timeNow);
                                intentVideoCall.PutExtra("CallID", time);
                                intentVideoCall.PutExtra("access_token", "YOUR_TOKEN");
                                intentVideoCall.PutExtra("access_token_2", "YOUR_TOKEN");
                                intentVideoCall.PutExtra("from_id", "0");
                                intentVideoCall.PutExtra("active", "0");
                                intentVideoCall.PutExtra("status", "0");
                                intentVideoCall.PutExtra("room_name", "TestRoom");
                                StartActivity(intentVideoCall);
                            }
                            catch (Exception exception)
                            {
                                Methods.DisplayReportResultTrack(exception);
                            }
                        }
                        else if (AppSettings.EnableAudioCall && AppSettings.EnableVideoCall == false) // Audio Call On
                        {
                            try
                            {
                                Intent intentVideoCall = new Intent(Context, typeof(TwilioVideoCallActivity));
                                if (AppSettings.UseLibrary == SystemCall.Agora)
                                {
                                    intentVideoCall = new Intent(Context, typeof(AgoraAudioCallActivity));
                                    intentVideoCall.PutExtra("type", "Agora_audio_calling_start");
                                }
                                else if (AppSettings.UseLibrary == SystemCall.Twilio)
                                {
                                    intentVideoCall = new Intent(Context, typeof(TwilioAudioCallActivity));
                                    intentVideoCall.PutExtra("type", "Twilio_audio_calling_start");
                                }

                                intentVideoCall.PutExtra("UserID", item.UserId);
                                intentVideoCall.PutExtra("avatar", item.Avatar);
                                intentVideoCall.PutExtra("name", item.Name);
                                intentVideoCall.PutExtra("time", timeNow);
                                intentVideoCall.PutExtra("CallID", time);
                                intentVideoCall.PutExtra("access_token", "YOUR_TOKEN");
                                intentVideoCall.PutExtra("access_token_2", "YOUR_TOKEN");
                                intentVideoCall.PutExtra("from_id", "0");
                                intentVideoCall.PutExtra("active", "0");
                                intentVideoCall.PutExtra("status", "0");
                                intentVideoCall.PutExtra("room_name", "TestRoom");
                                StartActivity(intentVideoCall);
                            }
                            catch (Exception exception)
                            {
                                Methods.DisplayReportResultTrack(exception);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
Exemple #13
0
        private async void SendMess(string text)
        {
            try
            {
                if (!Methods.CheckConnectivity())
                {
                    Toast.MakeText(this, GetString(Resource.String.Lbl_CheckYourInternetConnection), ToastLength.Short)?.Show();
                }
                else
                {
                    var unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
                    var time2         = unixTimestamp.ToString();

                    //Here on This function will send Selected audio file to the user
                    var(apiStatus, respond) = await RequestsAsync.Message.Send_Message(UserId, time2, text);

                    if (apiStatus == 200)
                    {
                        if (respond is SendMessageObject result)
                        {
                            Console.WriteLine(result.MessageData);
                            if (!string.IsNullOrEmpty(CallId))
                            {
                                var ckd = MsgTabbedMainActivity.GetInstance().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,
                                        AccessToken  = TwilioAccessToken,
                                        AccessToken2 = TwilioAccessTokenUser2,
                                        FromId       = FromId,
                                        Active       = Active,
                                        Time         = "Missed call",
                                        Status       = Status,
                                        RoomName     = RoomName,
                                        Type         = CallType,
                                        TypeIcon     = "Cancel",
                                        TypeColor    = "#FF0000"
                                    };

                                    MsgTabbedMainActivity.GetInstance().LastCallsTab.MAdapter?.Insert(cv);

                                    SqLiteDatabase dbDatabase = new SqLiteDatabase();
                                    dbDatabase.Insert_CallUser(cv);
                                }
                            }

                            switch (CallType)
                            {
                            case "Twilio_video_call":
                                PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                                    () => RequestsAsync.Call.DeclineCallAsync(UserDetails.UserId, CallId, TypeCall.Video)
                                });
                                break;

                            case "Twilio_audio_call":
                                PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                                    () => RequestsAsync.Call.DeclineCallAsync(UserDetails.UserId, CallId, TypeCall.Audio)
                                });
                                break;

                            case "Agora_video_call_recieve":
                            case "Agora_audio_call_recieve":
                                PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                                    () => ApiRequest.Send_Agora_Call_Action_Async("decline", CallId)
                                });
                                break;
                            }

                            FinishVideoAudio();
                        }
                    }
                    else
                    {
                        Methods.DisplayReportResult(this, respond);
                    }
                }
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
            }
        }
Exemple #14
0
        private void RejectCallButton_Click(object sender, EventArgs e)
        {
            try
            {
                switch (CallType)
                {
                case "Twilio_video_call":
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => RequestsAsync.Call.DeclineCallAsync(UserDetails.UserId, CallId, TypeCall.Video)
                    });
                    break;

                case "Twilio_audio_call":
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => RequestsAsync.Call.DeclineCallAsync(UserDetails.UserId, CallId, TypeCall.Audio)
                    });
                    break;

                case "Agora_video_call_recieve":
                case "Agora_audio_call_recieve":
                    PollyController.RunRetryPolicyFunction(new List <Func <Task> > {
                        () => ApiRequest.Send_Agora_Call_Action_Async("decline", CallId)
                    });
                    break;
                }

                if (!string.IsNullOrEmpty(CallId))
                {
                    var ckd = MsgTabbedMainActivity.GetInstance().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,
                            AccessToken  = TwilioAccessToken,
                            AccessToken2 = TwilioAccessTokenUser2,
                            FromId       = FromId,
                            Active       = Active,
                            Time         = "Missed call",
                            Status       = Status,
                            RoomName     = RoomName,
                            Type         = CallType,
                            TypeIcon     = "Cancel",
                            TypeColor    = "#FF0000"
                        };

                        MsgTabbedMainActivity.GetInstance().LastCallsTab.MAdapter?.Insert(cv);

                        SqLiteDatabase dbDatabase = new SqLiteDatabase();
                        dbDatabase.Insert_CallUser(cv);
                    }
                }

                FinishVideoAudio();
            }
            catch (Exception exception)
            {
                FinishVideoAudio();
                Methods.DisplayReportResultTrack(exception);
            }
        }