Exemple #1
0
        public static async Task <Classes.Call_User> Create_Agora_Call_Event_Async(string recipient_id, string call_type)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    var formContent = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("user_id", UserDetails.User_id),
                        new KeyValuePair <string, string>("recipient_id", recipient_id),
                        new KeyValuePair <string, string>("call_type", call_type),
                        new KeyValuePair <string, string>("s", UserDetails.access_token),
                    });

                    var response = await client.PostAsync(API_Create_Agora_Call_Event, formContent);

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

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

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

                        vidodata.type = call_type;

                        return(vidodata);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
Exemple #2
0
        public static async Task <Classes.Call_User> Create_Twilio_Video_Call_Answer_Async(string recipient_id)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    var formContent = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair <string, string>("user_id", UserDetails.User_id),
                        new KeyValuePair <string, string>("recipient_id", recipient_id),
                        new KeyValuePair <string, string>("s", UserDetails.access_token),
                    });

                    var response = await client.PostAsync(API_Create_Video_Call_Answer, formContent);

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

                    var    data      = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);
                    string apiStatus = data["status"].ToString();
                    if (apiStatus == "200")
                    {
                        Classes.Call_User videoData = new Classes.Call_User
                        {
                            access_token   = data["access_token"].ToString(),
                            access_token_2 = data["access_token_2"].ToString(),
                            id             = data["id"].ToString(),
                            room_name      = data["room_name"].ToString(),
                            type           = "Twilio_video_call"
                        };

                        return(videoData);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
Exemple #3
0
            public override void OnReceive(Context context, Intent intent)
            {
                try
                {
                    int notificationId = intent.GetIntExtra("NOTIFICATION_ID", 0);

                    NotificationManager notifyMgr =
                        (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);
                    notifyMgr.Cancel(notificationId);

                    var Call_id   = intent.GetStringExtra("CallID");
                    var isDismiss = intent.GetStringExtra("action");
                    if (isDismiss == "dismiss")
                    {
                        if (intent.GetStringExtra("type") == "Twilio_video_call")
                        {
                            API_Request.Send_Twilio_Video_Call_Answer_Async("decline", Call_id).ConfigureAwait(false);
                        }
                        else if (intent.GetStringExtra("type") == "Twilio_audio_call")
                        {
                            API_Request.Send_Twilio_Audio_Call_Answer_Async("decline", Call_id).ConfigureAwait(false);
                        }
                        else if (intent.GetStringExtra("type") == "Agora_audio_call_recieve")
                        {
                            API_Request.Send_Agora_Call_Action_Async("decline", Call_id).ConfigureAwait(false);
                        }
                        else if (intent.GetStringExtra("type") == "Agora_video_call_recieve")
                        {
                            API_Request.Send_Agora_Call_Action_Async("decline", Call_id).ConfigureAwait(false);
                        }

                        var ckd = Last_Calls_Fragment.mAdapter?.mCallUser?.FirstOrDefault(a =>
                                                                                          a.id == CallID); // id >> Call_Id
                        if (ckd == null)
                        {
                            Classes.Call_User cv = new Classes.Call_User();
                            cv.id             = CallID;
                            cv.user_id        = UserID;
                            cv.avatar         = avatar;
                            cv.name           = name;
                            cv.access_token   = access_token;
                            cv.access_token_2 = access_token_2;
                            cv.from_id        = from_id;
                            cv.active         = active;
                            cv.time           = "Missed call";
                            cv.status         = status;
                            cv.room_name      = room_name;
                            cv.type           = type;
                            cv.typeIcon       = "Cancel";
                            cv.typeColor      = "#FF0000";

                            Last_Calls_Fragment.mAdapter?.Insert(cv);

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


                        notifyMgr.CancelAll();
                    }
                    else
                    {
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }