示例#1
0
 protected override void OnRestart()
 {
     try
     {
         base.OnRestart();
         TwilioVideo = TwilioVideoHelper.GetOrCreate(this);
         UpdateState();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
示例#2
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");
                }

                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.SendAnswerCallAsync(CallId, TypeCall.Video);

                        if (apiStatus == 200)
                        {
                            if (respond is AnswerCallObject result)
                            {
                                if (result.Data != null)
                                {
                                    ConnectToRoom();
                                }
                            }
                        }
                        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);
            }
        }