public static TwilioVideoHelper GetOrCreate(Context context) { if (Instance == null) { Instance = new TwilioVideoHelper(); } if (Instance.CurrentVideoTrack == null) { Instance.CreateLocalMedia(context); } return(Instance); }
protected override void OnRestart() { try { base.OnRestart(); TwilioVideo = TwilioVideoHelper.GetOrCreate(this); UpdateState(); } catch (Exception e) { Console.WriteLine(e); } }
public static TwilioVideoHelper GetOrCreate(Context context) { try { if (Instance == null) { Instance = new TwilioVideoHelper(); } if (Instance.CurrentVideoTrack == null || Instance.CurrentAudioTrack == null) { Instance.CreateLocalMedia(context); } return(Instance); } catch (Exception e) { Console.WriteLine(e); return(null); } }
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); } }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.TwilioAudioCallActivityLayout); Window.AddFlags(WindowManagerFlags.KeepScreenOn); // Create your application here Intent intentCloser = new Intent(this, typeof(NotificationManagerClass.NotificationBroadcasterCloser)); intentCloser.PutExtra("action", "answer"); intentCloser.PutExtra("type", Intent.GetStringExtra("type")); SendBroadcast(intentCloser); UserID = Intent.GetStringExtra("UserID"); avatar = Intent.GetStringExtra("avatar"); name = Intent.GetStringExtra("name"); var data_CALL_ID = Intent.GetStringExtra("CallID") ?? "Data not available"; if (data_CALL_ID != "Data not available" && !string.IsNullOrEmpty(data_CALL_ID)) { CALL_ID = data_CALL_ID; TWILIO_ACCESS_TOKEN = Intent.GetStringExtra("access_token"); TWILIO_ACCESS_TOKEN_USER2 = Intent.GetStringExtra("access_token_2"); from_id = Intent.GetStringExtra("from_id"); active = Intent.GetStringExtra("active"); time = Intent.GetStringExtra("time"); status = Intent.GetStringExtra("status"); ROOM_NAME = Intent.GetStringExtra("room_name"); CALL_TYPE = Intent.GetStringExtra("type"); } Speaker_audio_button = FindViewById <CircleButton>(Resource.Id.speaker_audio_button); End_call_button = FindViewById <CircleButton>(Resource.Id.end_audio_call_button); Mute_audio_button = FindViewById <CircleButton>(Resource.Id.mute_audio_call_button); UserImageViewAsync = FindViewById <ImageView>(Resource.Id.audiouserImageViewAsync); UserNameTextView = FindViewById <TextView>(Resource.Id.audiouserNameTextView); DurationTextView = FindViewById <TextView>(Resource.Id.audiodurationTextView); Speaker_audio_button.Click += Speaker_audio_button_Click; End_call_button.Click += End_call_button_Click; Mute_audio_button.Click += Mute_audio_button_Click; Speaker_audio_button.SetImageResource(Resource.Drawable.ic_speaker_close); bool granted = ContextCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.Camera) == Permission.Granted && ContextCompat.CheckSelfPermission(ApplicationContext, Manifest.Permission.RecordAudio) == Permission.Granted; CheckVideoCallPermissions(granted); if (CALL_TYPE == "Twilio_audio_call") { if (!string.IsNullOrEmpty(TWILIO_ACCESS_TOKEN)) { if (!string.IsNullOrEmpty(UserID)) { Load_userWhenCall(UserID); } TwilioVideo = TwilioVideoHelper.GetOrCreate(ApplicationContext); UpdateState(); DurationTextView.Text = this.GetText(Resource.String.Lbl_Waiting_for_answer); var Check_for_ResponseDate = API_Request.Send_Twilio_Audio_Call_Answer_Async("answer", CALL_ID); ConnectToRoom(); var ckd = Last_Calls_Fragment.mAdapter?.mCallUser?.FirstOrDefault(a => a.id == CALL_ID); // id >> Call_Id if (ckd == null) { Classes.Call_User cv = new Classes.Call_User { id = CALL_ID, user_id = UserID, avatar = avatar, name = name, from_id = from_id, active = active, time = "Answered call", status = status, room_name = ROOM_NAME, type = CALL_TYPE, typeIcon = "Accept", typeColor = "#008000" }; Last_Calls_Fragment.mAdapter?.Insert(cv); SqLiteDatabase dbDatabase = new SqLiteDatabase(); dbDatabase.Insert_CallUser(cv); dbDatabase.Dispose(); } } } else if (CALL_TYPE == "Twilio_audio_calling_start") { if (!string.IsNullOrEmpty(UserID)) { LoadProfileFromUserID(UserID); Load_userWhenCall(UserID); } DurationTextView.Text = this.GetText(Resource.String.Lbl_Calling); TwilioVideo = TwilioVideoHelper.GetOrCreate(ApplicationContext); IMethods.AudioRecorderAndPlayer.PlayAudioFromAsset("mystic_call.mp3"); UpdateState(); } } catch (Exception e) { Console.WriteLine(e); } }
protected override void OnRestart() { base.OnRestart(); TwilioVideo = TwilioVideoHelper.GetOrCreate(ApplicationContext); UpdateState(); }