summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/XChatIFlyMgr.cs
blob: 1ee5f80a5bbd475819ac35c76ad9311f9641511c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using KKSG;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient
{
	internal class XChatIFlyMgr : XSingleton<XChatIFlyMgr>
	{
		public bool IsAutoPlayEnable
		{
			get
			{
				return this._enable_auto_play;
			}
		}

		public IXIFlyMgr IFLYMGR
		{
			get
			{
				return this._ifly_mgr;
			}
		}

		public Dictionary<ulong, string> LocalAudio
		{
			get
			{
				return this._local_audio;
			}
		}

		public List<ChatInfo> AutoPlayAudioList
		{
			get
			{
				bool flag = this.m_lAutoPlayAudioList == null;
				if (flag)
				{
					this.m_lAutoPlayAudioList = new List<ChatInfo>();
				}
				return this.m_lAutoPlayAudioList;
			}
			set
			{
				this.m_lAutoPlayAudioList = value;
			}
		}

		private static readonly float MIN_RECORD_LENGTH = 0.3f;

		private static readonly float AUDIO_TIME_OUT = 10f;

		private static int CLEAR_AUDIO_COUNT = 20;

		private IXIFlyMgr _ifly_mgr = null;

		private string audiotxt = "";

		private VoiceUsage _usage = VoiceUsage.CHAT;

		private string _upload_file = "";

		private float _record_start = 0f;

		private float _record_length = 0f;

		private string cachePath = "";

		private ChatChannelType _channel_type = ChatChannelType.DEFAULT;

		private ChatInfo _download_audio = null;

		private uint _auto_play_timer = 0u;

		private uint _record_timer = 0u;

		private uint _translate_timer = 0u;

		private uint _prepare_record_time = 0u;

		private bool _is_recording = false;

		private bool _enable_auto_play = false;

		private EndRecordCallBack _callback = null;

		private float _try_trans_start_time = 0f;

		private uint _txt_length_limit;

		private uint _windows_audio_token;

		private bool[] _auto_play_enable_channel = new bool[XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(ChatChannelType.ChannelNum)];

		private List<ChatInfo> m_lAutoPlayAudioList;

		private Dictionary<ulong, string> _local_audio = new Dictionary<ulong, string>();

		private List<ChatInfo> _auto_play_list = new List<ChatInfo>();

		private int MAX_DELETE_CNT = 100;

		private UpLoadAudioRes lastAudoRes;

		private static ulong lastFileID = 0UL;

		public XChatIFlyMgr()
		{
			for (int i = 0; i < XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(ChatChannelType.ChannelNum); i++)
			{
				bool flag = i == XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(ChatChannelType.Group);
				if (flag)
				{
					this._auto_play_enable_channel[i] = false;
				}
				else
				{
					this._auto_play_enable_channel[i] = true;
				}
			}
		}

		public void InitFlyMgr()
		{
			bool flag = this._ifly_mgr == null;
			if (flag)
			{
				this._ifly_mgr = (XUpdater.XUpdater.XGameRoot.GetComponent("XIFlyMgr") as IXIFlyMgr);
			}
			bool flag2 = this._ifly_mgr != null;
			if (flag2)
			{
				this._ifly_mgr.SetCallback(new Action<string>(this.RecoganizeCallback));
				this._ifly_mgr.SetVoiceCallback(new Action<string>(this.VoiceVolumeCallback));
			}
			XChatDocument specificDocument = XDocuments.GetSpecificDocument<XChatDocument>(XChatDocument.uuID);
			this._txt_length_limit = specificDocument.GetRawData(ChatChannelType.World).length / 3u;
		}

		public bool NeedClear()
		{
			try
			{
				string audioCachePath = this.GetAudioCachePath();
				bool flag = Directory.Exists(audioCachePath);
				if (flag)
				{
					DirectoryInfo directoryInfo = new DirectoryInfo(audioCachePath);
					FileInfo[] files = directoryInfo.GetFiles();
					bool flag2 = files != null;
					if (flag2)
					{
						bool flag3 = files.Length > XChatIFlyMgr.CLEAR_AUDIO_COUNT;
						if (flag3)
						{
							return true;
						}
					}
				}
				string persistentDataPath = Application.persistentDataPath;
				bool flag4 = Directory.Exists(persistentDataPath);
				if (flag4)
				{
					DirectoryInfo directoryInfo2 = new DirectoryInfo(persistentDataPath);
					FileInfo[] files2 = directoryInfo2.GetFiles();
					bool flag5 = files2 != null;
					if (flag5)
					{
						bool flag6 = files2.Length > XChatIFlyMgr.CLEAR_AUDIO_COUNT;
						if (flag6)
						{
							return true;
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}

		public void ClearAudioCache()
		{
			string audioCachePath = this.GetAudioCachePath();
			bool flag = Directory.Exists(audioCachePath);
			if (flag)
			{
				DirectoryInfo directoryInfo = new DirectoryInfo(audioCachePath);
				FileInfo[] files = directoryInfo.GetFiles();
				bool flag2 = files != null;
				if (flag2)
				{
					int num = Mathf.Min(this.MAX_DELETE_CNT, files.Length);
					for (int i = 0; i < num; i++)
					{
						string extension = files[i].Extension;
						bool flag3 = !extension.Equals(".mp3") && !extension.Equals(".sound");
						if (!flag3)
						{
							XSingleton<XDebug>.singleton.AddLog("delete: ", files[i].Name, " ext: ", extension, null, null, XDebugColor.XDebug_None);
							try
							{
								this.RemoveLocalAudio(files[i].Name);
								File.Delete(files[i].FullName);
							}
							catch
							{
								XSingleton<XDebug>.singleton.AddErrorLog("Delete file error, ", files[i].FullName, null, null, null, null);
							}
						}
					}
				}
			}
			string persistentDataPath = Application.persistentDataPath;
			bool flag4 = Directory.Exists(persistentDataPath);
			if (flag4)
			{
				DirectoryInfo directoryInfo2 = new DirectoryInfo(persistentDataPath);
				FileInfo[] files2 = directoryInfo2.GetFiles();
				bool flag5 = files2 != null;
				if (flag5)
				{
					int num2 = Mathf.Min(this.MAX_DELETE_CNT, files2.Length);
					for (int j = 0; j < num2; j++)
					{
						string extension2 = files2[j].Extension;
						bool flag6 = !extension2.Equals(".mp3") && !extension2.Equals(".sound");
						if (!flag6)
						{
							XSingleton<XDebug>.singleton.AddLog("delete: ", files2[j].Name, " ext: ", extension2, null, null, XDebugColor.XDebug_None);
							try
							{
								this.RemoveLocalAudio(files2[j].Name);
								File.Delete(files2[j].FullName);
							}
							catch
							{
								XSingleton<XDebug>.singleton.AddErrorLog("Delete apollo file error, ", files2[j].FullName, null, null, null, null);
							}
						}
					}
				}
			}
		}

		private void RemoveLocalAudio(string name)
		{
			ulong key = 0UL;
			ulong.TryParse(name, out key);
			bool flag = this._local_audio.ContainsKey(key);
			if (flag)
			{
				this._local_audio.Remove(key);
			}
		}

		public void RemoveOldRecordFile()
		{
			string audioCachePath = this.GetAudioCachePath();
			bool flag = Directory.Exists(audioCachePath);
			if (flag)
			{
				DirectoryInfo directoryInfo = new DirectoryInfo(audioCachePath);
				FileInfo[] files = directoryInfo.GetFiles();
				bool flag2 = files != null;
				if (flag2)
				{
					for (int i = 0; i < files.Length; i++)
					{
						string a = files[i].Name.Substring(files[i].Name.LastIndexOf(".") + 1);
						bool flag3 = a != "pcm";
						if (!flag3)
						{
							try
							{
								files[i].Delete();
							}
							catch
							{
								XSingleton<XDebug>.singleton.AddLog("Delete file failed: ", files[i].Name, null, null, null, null, XDebugColor.XDebug_None);
							}
							break;
						}
					}
				}
			}
		}

		public void GenerateAudioFiles(int num)
		{
			string text = this.GetAudioCachePath();
			bool flag = Directory.Exists(text);
			if (flag)
			{
				DirectoryInfo directoryInfo = new DirectoryInfo(text);
				FileInfo[] files = directoryInfo.GetFiles();
				bool flag2 = files != null;
				if (flag2)
				{
					for (int i = 0; i < files.Length; i++)
					{
						string a = files[i].Name.Substring(files[i].Name.LastIndexOf(".") + 1);
						bool flag3 = a == "mp3";
						if (flag3)
						{
							for (int j = 0; j < num; j++)
							{
								string text2 = text + "/" + j.ToString() + ".mp3";
								bool flag4 = !File.Exists(text2);
								if (flag4)
								{
									File.Copy(files[i].FullName, text2);
								}
							}
							break;
						}
					}
				}
			}
			text = Application.persistentDataPath;
			bool flag5 = Directory.Exists(text);
			if (flag5)
			{
				DirectoryInfo directoryInfo2 = new DirectoryInfo(text);
				FileInfo[] files2 = directoryInfo2.GetFiles();
				bool flag6 = files2 != null;
				if (flag6)
				{
					for (int k = 0; k < files2.Length; k++)
					{
						string a2 = files2[k].Name.Substring(files2[k].Name.LastIndexOf(".") + 1);
						bool flag7 = a2 == "sound";
						if (flag7)
						{
							for (int l = 0; l < num; l++)
							{
								string text3 = text + "/" + l.ToString() + ".sound";
								bool flag8 = !File.Exists(text3);
								if (flag8)
								{
									File.Copy(files2[k].FullName, text3);
								}
							}
							break;
						}
					}
				}
			}
		}

		public bool IsIFlyListening()
		{
			bool flag = this._ifly_mgr != null;
			return flag && this._ifly_mgr.IsIFlyListening();
		}

		public bool IsRecording()
		{
			return this._is_recording;
		}

		public void EnableAutoPlay(bool enable)
		{
			XRadioDocument specificDocument = XDocuments.GetSpecificDocument<XRadioDocument>(XRadioDocument.uuID);
			bool flag = specificDocument != null && specificDocument.roomState == XRadioDocument.BigRoomState.InRoom && enable;
			if (!flag)
			{
				XSingleton<XDebug>.singleton.AddLog("Enable auto play: ", enable.ToString(), null, null, null, null, XDebugColor.XDebug_None);
				this._enable_auto_play = enable;
			}
		}

		public void SetBackMusicOn(bool on)
		{
			XAudioOperationArgs @event = XEventPool<XAudioOperationArgs>.GetEvent();
			@event.IsAudioOn = on;
			@event.Firer = XSingleton<XGame>.singleton.Doc;
			XSingleton<XEventMgr>.singleton.FireEvent(@event);
		}

		public void SetChannelAutoPlay(ChatChannelType type, bool auto)
		{
			bool flag = XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(type) >= this._auto_play_enable_channel.Length;
			if (!flag)
			{
				this._auto_play_enable_channel[XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(type)] = auto;
			}
		}

		public bool IsChannelAutoPlayEnable(ChatChannelType type)
		{
			bool flag = XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(type) >= this._auto_play_enable_channel.Length;
			return !flag && this._auto_play_enable_channel[XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(type)];
		}

		private void setRadioOn(bool on)
		{
			XRadioDocument specificDocument = XDocuments.GetSpecificDocument<XRadioDocument>(XRadioDocument.uuID);
			bool flag = specificDocument != null;
			if (flag)
			{
				specificDocument.MuteSounds(!on);
			}
		}

		public void StartRecord(VoiceUsage usage = VoiceUsage.CHAT, EndRecordCallBack callback = null)
		{
			bool flag = this._ifly_mgr == null || !this._ifly_mgr.IsInited();
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(XSingleton<XStringTable>.singleton.GetString("CHAT_INIT_FAILED"), "fece00");
			}
			else
			{
				bool isBroadcast = DlgBase<BroadMiniDlg, BroadcastMiniBehaviour>.singleton.isBroadcast;
				if (isBroadcast)
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FM_VOICE_BROAD"), "fece00");
				}
				else
				{
					XRadioDocument specificDocument = XDocuments.GetSpecificDocument<XRadioDocument>(XRadioDocument.uuID);
					bool flag2 = specificDocument.isHosting();
					if (flag2)
					{
						XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FM_VOICE_RADIO"), "fece00");
					}
					else
					{
						this.StopAutoPlay();
						this._ifly_mgr.Cancel();
						this.SetBackMusicOn(false);
						this.setRadioOn(false);
						this.RemoveOldRecordFile();
						XSingleton<XTimerMgr>.singleton.KillTimer(this._translate_timer);
						this._translate_timer = 0u;
						DlgBase<XChatVoiceStatusView, XChatVoiceStatusBehaviour>.singleton.SetVisible(true, true);
						this._usage = usage;
						this._callback = callback;
						XSingleton<XDebug>.singleton.AddLog("Record StartTime: ", Time.time.ToString(), null, null, null, null, XDebugColor.XDebug_None);
						RuntimePlatform platform = Application.platform;
						if ((int)platform != 8 && (int)platform != 11)
						{
							this.audiotxt = DateTime.Now.ToString();
							this._windows_audio_token = XSingleton<XTimerMgr>.singleton.SetTimer(0.2f, new XTimerMgr.ElapsedEventHandler(this.RefreshWindowsVoice), null);
						}
						else
						{
							this.audiotxt = "";
						}
						bool flag3 = usage == VoiceUsage.CHAT;
						if (flag3)
						{
							this._prepare_record_time = XSingleton<XTimerMgr>.singleton.SetTimer(0.15f, new XTimerMgr.ElapsedEventHandler(this.DoStartRecord), null);
						}
						else
						{
							this.DoStartRecord(null);
						}
					}
				}
			}
		}

		private void DoStartRecord(object obj)
		{
			this._is_recording = true;
			this._record_start = Time.realtimeSinceStartup;
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				try
				{
					this._ifly_mgr.StartRecord();
				}
				catch
				{
					XSingleton<XDebug>.singleton.AddErrorLog("IFly Start record error", null, null, null, null, null);
				}
			}
			this._record_timer = XSingleton<XTimerMgr>.singleton.SetTimer(10.5f, new XTimerMgr.ElapsedEventHandler(this.RecordTimeOut), null);
		}

		private void RefreshWindowsVoice(object obj)
		{
			DlgBase<XChatVoiceStatusView, XChatVoiceStatusBehaviour>.singleton.OnSetVolume((uint)XSingleton<XCommon>.singleton.RandomInt(0, 7));
			this._windows_audio_token = XSingleton<XTimerMgr>.singleton.SetTimer(0.2f, new XTimerMgr.ElapsedEventHandler(this.RefreshWindowsVoice), null);
		}

		public void RecoganizeCallback(string txt)
		{
			bool flag = (long)this.audiotxt.Length <= (long)((ulong)this._txt_length_limit);
			if (flag)
			{
				bool flag2 = (long)(this.audiotxt.Length + txt.Length) <= (long)((ulong)this._txt_length_limit);
				if (flag2)
				{
					this.audiotxt += txt;
				}
				else
				{
					bool flag3 = this._txt_length_limit - (uint)(this.audiotxt.Length + 1) > 0u;
					if (flag3)
					{
						this.audiotxt += txt.Substring(0, (int)(this._txt_length_limit - (uint)(this.audiotxt.Length + 1)));
					}
				}
			}
		}

		public void VoiceVolumeCallback(string volume)
		{
			uint num = 0u;
			uint.TryParse(volume, out num);
			DlgBase<XChatVoiceStatusView, XChatVoiceStatusBehaviour>.singleton.OnSetVolume((num * 7u + 3u) / 25u);
		}

		public void StopRecord(bool cancel)
		{
			bool flag = this._ifly_mgr == null || !this._ifly_mgr.IsInited();
			if (!flag)
			{
				DlgBase<XChatVoiceStatusView, XChatVoiceStatusBehaviour>.singleton.SetVisible(false, true);
				XSingleton<XTimerMgr>.singleton.KillTimer(this._windows_audio_token);
				bool flag2 = this._prepare_record_time > 0u;
				if (flag2)
				{
					XSingleton<XTimerMgr>.singleton.KillTimer(this._prepare_record_time);
					this._prepare_record_time = 0u;
				}
				this.SetBackMusicOn(true);
				this.setRadioOn(true);
				bool flag3 = !this._is_recording;
				if (!flag3)
				{
					bool flag4 = this._record_timer > 0u;
					if (flag4)
					{
						XSingleton<XTimerMgr>.singleton.KillTimer(this._record_timer);
						this._record_timer = 0u;
					}
					bool flag5 = !cancel;
					if (flag5)
					{
						this._ifly_mgr.StopRecord();
						this._record_length = Time.realtimeSinceStartup - this._record_start;
						this._record_length = ((this._record_length > 10f) ? 10f : this._record_length);
						XSingleton<XDebug>.singleton.AddLog("Record StopTime: ", Time.time.ToString(), null, null, null, null, XDebugColor.XDebug_None);
						bool flag6 = this._record_length <= XChatIFlyMgr.MIN_RECORD_LENGTH;
						if (flag6)
						{
							XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("CHAT_RECORD_TOO_SHORT"), "fece00");
						}
						else
						{
							string param = string.Format("{0:D2}{1:D2}{2:D2}", DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
							this._translate_timer = XSingleton<XTimerMgr>.singleton.SetTimer(0.1f, new XTimerMgr.ElapsedEventHandler(this.DelayTransMp3), param);
							this._try_trans_start_time = Time.time;
						}
					}
					this._is_recording = false;
				}
			}
		}

		private void RecordTimeOut(object obj)
		{
			bool flag = !this._is_recording;
			if (!flag)
			{
				this.StopRecord(false);
				bool flag2 = this._callback != null;
				if (flag2)
				{
					this._callback();
				}
			}
		}

		public void DelayTransMp3(object obj)
		{
			string text = obj as string;
			bool flag = Time.time - this._try_trans_start_time >= 0.3f;
			if (flag)
			{
				this.StartTransMp3(text);
			}
			else
			{
				bool flag2 = this._ifly_mgr != null && (this._ifly_mgr.IsIFlyListening() || !this._ifly_mgr.IsRecordFileExist());
				if (flag2)
				{
					this._translate_timer = XSingleton<XTimerMgr>.singleton.SetTimer(0.1f, new XTimerMgr.ElapsedEventHandler(this.DelayTransMp3), text);
				}
				else
				{
					this.StartTransMp3(text);
				}
			}
		}

		public void StartTransMp3(string destFileName)
		{
			string filePath = "";
			RuntimePlatform platform = Application.platform;
			if ((int)platform != 8 && (int)platform != 11)
			{
				filePath = "Assets/Editor/Mp3Sample/sample.mp3";
			}
			else
			{
				bool flag = this._ifly_mgr != null;
				if (flag)
				{
					bool flag2 = !this._ifly_mgr.IsRecordFileExist();
					if (flag2)
					{
						XSingleton<XDebug>.singleton.AddErrorLog("Record busy, can't record", null, null, null, null, null);
						return;
					}
					filePath = this._ifly_mgr.StartTransMp3(destFileName);
				}
			}
			this.StartUpLoadMp3(filePath);
		}

		public void StartUpLoadMp3(string filePath)
		{
			XSingleton<XDebug>.singleton.AddLog("Will start upload mp3, txt:", this.audiotxt, null, null, null, null, XDebugColor.XDebug_None);
			RpcC2T_UpLoadAudioToGate rpcC2T_UpLoadAudioToGate = new RpcC2T_UpLoadAudioToGate();
			rpcC2T_UpLoadAudioToGate.oArg.audio = File.ReadAllBytes(filePath);
			rpcC2T_UpLoadAudioToGate.oArg.text = Encoding.UTF8.GetBytes(this.audiotxt);
			rpcC2T_UpLoadAudioToGate.oArg.srctype = 0u;
			this._upload_file = filePath;
			XSingleton<XDebug>.singleton.AddLog("The audio length: ", rpcC2T_UpLoadAudioToGate.oArg.audio.Length.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			XSingleton<XClientNetwork>.singleton.Send(rpcC2T_UpLoadAudioToGate);
		}

		public void UpLoadMp3Res(UpLoadAudioRes res)
		{
			uint num = (uint)(this._record_length * 1000f) + 1u;
			XSingleton<XDebug>.singleton.AddLog("Will upload res mp3, usage: ", null, null, null, null, null, XDebugColor.XDebug_None);
			bool flag = this._usage == VoiceUsage.CHAT;
			if (flag)
			{
				this._local_audio[res.audiodownuid] = this._upload_file;
				this.lastAudoRes = res;
				bool flag2 = DlgBase<XChatView, XChatBehaviour>.singleton.CheckWorldSendMsg(true, null, ChatChannelType.DEFAULT);
				if (flag2)
				{
					bool flag3 = num >= 9000u && this.audiotxt.Length <= (int)(num / 2000u);
					if (!flag3)
					{
						XSingleton<XDebug>.singleton.AddLog("Will Do send world chat", null, null, null, null, null, XDebugColor.XDebug_None);
						DlgBase<XChatView, XChatBehaviour>.singleton.SendVoiceChat(this.audiotxt, DlgBase<XChatView, XChatBehaviour>.singleton.activeChannelType, res.audiodownuid, num * 1f);
					}
				}
			}
			else
			{
				bool flag4 = this._usage == VoiceUsage.ANSWER;
				if (flag4)
				{
					XVoiceQADocument specificDocument = XDocuments.GetSpecificDocument<XVoiceQADocument>(XVoiceQADocument.uuID);
					XSingleton<XDebug>.singleton.AddLog("Will Do send answer chat", null, null, null, null, null, XDebugColor.XDebug_None);
					specificDocument.SendAnswer(this.audiotxt, res.audiodownuid, num);
				}
				else
				{
					bool flag5 = this._usage == VoiceUsage.FLOWER_REPLY;
					if (flag5)
					{
						this._local_audio[res.audiodownuid] = this._upload_file;
						this.lastAudoRes = res;
						DlgBase<XChatView, XChatBehaviour>.singleton.SendVoiceChat(this.audiotxt, ChatChannelType.Friends, res.audiodownuid, num * 1f);
					}
					else
					{
						bool flag6 = this._usage == VoiceUsage.MENTORHIP;
						if (flag6)
						{
							this._local_audio[res.audiodownuid] = this._upload_file;
							this.lastAudoRes = res;
						}
						else
						{
							bool flag7 = this._usage == VoiceUsage.GUILDCOLLECT;
							if (flag7)
							{
								XExchangeItemDocument specificDocument2 = XDocuments.GetSpecificDocument<XExchangeItemDocument>(XExchangeItemDocument.uuID);
								XSingleton<XDebug>.singleton.AddLog("Will Do send voice chat in guild collect", null, null, null, null, null, XDebugColor.XDebug_None);
								specificDocument2.SendChat(this.audiotxt, res.audiodownuid, num);
							}
						}
					}
				}
			}
		}

		public void ResendLastWorldChat()
		{
			bool useApollo = XChatDocument.UseApollo;
			if (useApollo)
			{
				XSingleton<XChatApolloMgr>.singleton.ResendLastWorldChat();
			}
			else
			{
				uint num = (this._record_length >= 1f) ? ((uint)this._record_length) : 1u;
				bool flag = this.lastAudoRes != null;
				if (flag)
				{
					DlgBase<XChatView, XChatBehaviour>.singleton.SendVoiceChat(this.audiotxt, DlgBase<XChatView, XChatBehaviour>.singleton.activeChannelType, this.lastAudoRes.audiodownuid, num * 1f);
				}
			}
		}

		public void DownloadMp3(ChatInfo info)
		{
			XSingleton<XDebug>.singleton.AddLog("Will Download mp3", null, null, null, null, null, XDebugColor.XDebug_None);
			this._download_audio = info;
			RpcC2A_GetAudioListReq rpcC2A_GetAudioListReq = new RpcC2A_GetAudioListReq();
			rpcC2A_GetAudioListReq.oArg.audioUidList.Add(info.mAudioId);
			XSingleton<XClientNetwork>.singleton.Send(rpcC2A_GetAudioListReq);
		}

		public void DownloadMp3Res(GetAudioListRes res)
		{
			bool flag = res.dataList == null || res.dataList.Count == 0;
			if (flag)
			{
				XSingleton<XDebug>.singleton.AddLog("Download res error", null, null, null, null, null, XDebugColor.XDebug_None);
				this.DoStartAutoPlay(null);
			}
			else
			{
				AudioBrief audioBrief = res.dataList[0];
				string text = this.GetAudioCachePath() + "/" + audioBrief.audioUid.ToString() + ".mp3";
				bool flag2 = this._download_audio.mChannelId != ChatChannelType.DEFAULT;
				if (flag2)
				{
					text = this.GetAudioCachePath() + "/" + audioBrief.audioUid.ToString() + ".sound";
				}
				File.WriteAllBytes(text, audioBrief.audio);
				this._local_audio[this._download_audio.mAudioId] = text;
				XSingleton<XDebug>.singleton.AddLog("Download OK, will start play mp3, audiotime: ", this._download_audio.mAudioTime.ToString(), null, null, null, null, XDebugColor.XDebug_None);
				this.StartPlayMp3(text, this._download_audio.mAudioTime, this._download_audio);
				this.ChatShowInfo(this._download_audio);
			}
		}

		public void DownLoadMp3Error()
		{
			this.DoStartAutoPlay(null);
		}

		public void StartPlayMp3(string filepath, uint audiotime, ChatInfo info)
		{
			IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
			xapolloManager.SetApolloMode(2);
			XOptionsDocument specificDocument = XDocuments.GetSpecificDocument<XOptionsDocument>(XOptionsDocument.uuID);
			int @int = XSingleton<XGlobalConfig>.singleton.GetInt("SetSpeakerVolume");
			xapolloManager.SetMusicVolum((int)((float)@int * specificDocument.voiceVolme));
			RuntimePlatform platform = Application.platform;
			if ((int)platform != 8 && (int)platform != 11)
			{
				XSingleton<XChatApolloMgr>.singleton.StartPlayVoice(filepath);
			}
			else
			{
				bool flag = File.Exists(filepath);
				if (!flag)
				{
					XSingleton<XDebug>.singleton.AddLog("File not found, ", filepath, null, null, null, null, XDebugColor.XDebug_None);
					XSingleton<XTimerMgr>.singleton.KillTimer(this._auto_play_timer);
					this._auto_play_timer = XSingleton<XTimerMgr>.singleton.SetGlobalTimer(0.1f, new XTimerMgr.ElapsedEventHandler(this.DoStartAutoPlay), null);
					return;
				}
				try
				{
					XSingleton<XChatApolloMgr>.singleton.StartPlayVoice(filepath);
				}
				catch (Exception ex)
				{
					XSingleton<XDebug>.singleton.AddLog("StartPlayMp3, Find play exception, ", ex.ToString(), null, null, null, null, XDebugColor.XDebug_None);
				}
			}
			XSingleton<XTimerMgr>.singleton.KillTimer(this._auto_play_timer);
			bool flag2 = audiotime <= 1000u;
			if (flag2)
			{
				audiotime = 1000u;
			}
			this._auto_play_timer = XSingleton<XTimerMgr>.singleton.SetGlobalTimer((audiotime + 10u) * 1f / 1000f, new XTimerMgr.ElapsedEventHandler(this.DoStartAutoPlay), null);
			XSingleton<XDebug>.singleton.AddLog("Will start time autoplay, time: ", audiotime.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			this.DeleteAudio(info.mAudioId);
		}

		public void DoStartPlayChatInfo(ChatInfo info)
		{
			this.StopAutoPlay();
			this.StartPlayInfo(info);
		}

		public void StartPlayInfo(ChatInfo info)
		{
			bool is_recording = this._is_recording;
			if (is_recording)
			{
				XSingleton<XDebug>.singleton.AddLog("StartPlayInfo, isrecord will return", null, null, null, null, null, XDebugColor.XDebug_None);
			}
			else
			{
				bool flag = this._local_audio.ContainsKey(info.mAudioId) && File.Exists(this._local_audio[info.mAudioId]);
				if (flag)
				{
					this.ChatShowInfo(info);
					this.StartPlayMp3(this._local_audio[info.mAudioId], info.mAudioTime, info);
				}
				else
				{
					this.DownloadMp3(info);
				}
			}
		}

		private void DeleteAudio(ulong audioid)
		{
			bool flag = XChatIFlyMgr.lastFileID == 0UL || XChatIFlyMgr.lastFileID == audioid;
			if (flag)
			{
				XChatIFlyMgr.lastFileID = audioid;
			}
			else
			{
				RuntimePlatform platform = Application.platform;
				bool flag2 = (int)platform == 8;
				if (flag2)
				{
					string path = string.Concat(new object[]
					{
						Application.temporaryCachePath,
						"/",
						XChatIFlyMgr.lastFileID,
						".mp3"
					});
					this.DeleteFile(path);
					string path2 = string.Concat(new object[]
					{
						Application.temporaryCachePath,
						"/",
						XChatIFlyMgr.lastFileID,
						".sound"
					});
					this.DeleteFile(path2);
				}
				else
				{
					string path3 = string.Concat(new object[]
					{
						Application.persistentDataPath,
						"/",
						XChatIFlyMgr.lastFileID,
						".sound"
					});
					this.DeleteFile(path3);
					string path4 = string.Concat(new object[]
					{
						Application.persistentDataPath,
						"/",
						XChatIFlyMgr.lastFileID,
						".mp3"
					});
					this.DeleteFile(path4);
				}
				XChatIFlyMgr.lastFileID = audioid;
			}
		}

		private void DeleteFile(string path)
		{
			XSingleton<XDebug>.singleton.AddLog("delete: ", path, null, null, null, null, XDebugColor.XDebug_None);
			try
			{
				bool flag = !string.IsNullOrEmpty(path);
				if (flag)
				{
					bool flag2 = File.Exists(path);
					if (flag2)
					{
						File.Delete(path);
					}
				}
			}
			catch
			{
				XSingleton<XDebug>.singleton.AddWarningLog("delete fail" + path, null, null, null, null, null);
			}
		}

		public void StartPlayAudioId(ulong audioid)
		{
			this.StartPlayInfo(new ChatInfo
			{
				mAudioId = audioid,
				mChannelId = ChatChannelType.DEFAULT
			});
		}

		public void ClearPlayList()
		{
			this._auto_play_list.Clear();
		}

		public void DoStartAutoPlay(object obj)
		{
			bool enable_auto_play = this._enable_auto_play;
			if (enable_auto_play)
			{
				this.StartAutoPlay(true, true);
			}
			else
			{
				IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
				xapolloManager.SetApolloMode(0);
				this.SetBackMusicOn(true);
				this.setRadioOn(true);
				this._auto_play_timer = 0u;
			}
		}

		public void StartAutoPlay(bool rank = true, bool clearTimeout = true)
		{
			if (clearTimeout)
			{
				this.ClearTimeOutInfo();
			}
			if (rank)
			{
				this.RankAutoPlayList();
			}
			XSingleton<XDebug>.singleton.AddLog("StartAutoPlay, num:", this._auto_play_list.Count.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			bool flag = this._auto_play_list.Count == 0;
			if (flag)
			{
				IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
				xapolloManager.SetApolloMode(0);
				this.SetBackMusicOn(true);
				this.setRadioOn(true);
				XSingleton<XDebug>.singleton.AddLog("StartAutoplay setback music on", null, null, null, null, null, XDebugColor.XDebug_None);
				this._auto_play_timer = 0u;
			}
			else
			{
				XSingleton<XDebug>.singleton.AddLog("StartAutoplay setback music off", null, null, null, null, null, XDebugColor.XDebug_None);
				this.SetBackMusicOn(false);
				this.setRadioOn(false);
				bool flag2 = this._auto_play_list.Count > 0;
				if (flag2)
				{
					this.StartPlayInfo(this._auto_play_list[0]);
					this._auto_play_list.RemoveAt(0);
				}
			}
		}

		public void StopAutoPlay()
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this._auto_play_timer);
			this._auto_play_timer = 0u;
			XSingleton<XChatApolloMgr>.singleton.StopPlayVoice();
		}

		public void InsertAutoPlayList(ChatInfo info, bool clearTimeOut = true)
		{
			this._auto_play_list.Insert(0, info);
			this.StopAutoPlay();
			IApolloManager xapolloManager = XSingleton<XUpdater.XUpdater>.singleton.XApolloManager;
			xapolloManager.SetApolloMode(2);
			try
			{
				this.StartAutoPlay(false, clearTimeOut);
			}
			catch (Exception ex)
			{
				XSingleton<XDebug>.singleton.AddLog("InsertAutoPlayList exception, ", ex.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			}
		}

		public bool AddAutoPlayList(ChatInfo info)
		{
			bool flag = !XSingleton<XClientNetwork>.singleton.IsWifiEnable() && this.IsChannelAutoPlayEnable(ChatChannelType.ZeroChannel);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = !this.IsChannelAutoPlayEnable(info.mChannelId);
				if (flag2)
				{
					result = false;
				}
				else
				{
					bool flag3 = this._channel_type != ChatChannelType.DEFAULT && info.mChannelId != this._channel_type;
					if (flag3)
					{
						result = false;
					}
					else
					{
						bool flag4 = XSingleton<XScene>.singleton.SceneID == 100u || (XSingleton<XAttributeMgr>.singleton.XPlayerData.Level < 10u && DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsVisible());
						if (flag4)
						{
							result = false;
						}
						else
						{
							this._auto_play_list.Add(info);
							bool flag5 = this._auto_play_timer == 0u && this._enable_auto_play && !this.IsRecording();
							if (flag5)
							{
								this.StartAutoPlay(true, true);
							}
							result = true;
						}
					}
				}
			}
			return result;
		}

		public void RankAutoPlayList()
		{
		}

		private void ChatShowInfo(ChatInfo info)
		{
			bool isAudioPlayed = info.isAudioPlayed;
			if (!isAudioPlayed)
			{
				bool flag = info.mChannelId == ChatChannelType.DEFAULT;
				if (!flag)
				{
					info.isAudioPlayed = true;
					XChatDocument specificDocument = XDocuments.GetSpecificDocument<XChatDocument>(XChatDocument.uuID);
					specificDocument.ReceiveChatInfo(info);
				}
			}
		}

		public void ClearTimeOutInfo()
		{
			List<ChatInfo> list = new List<ChatInfo>();
			for (int i = 0; i < this._auto_play_list.Count; i++)
			{
				bool flag = (DateTime.Now - this._auto_play_list[i].mTime).TotalSeconds <= (double)XChatIFlyMgr.AUDIO_TIME_OUT;
				if (flag)
				{
					list.Add(this._auto_play_list[i]);
				}
				else
				{
					this.ChatShowInfo(this._auto_play_list[i]);
				}
			}
			this._auto_play_list = list;
		}

		public void SetAutoPlayChannel(ChatChannelType type)
		{
			bool flag = type != ChatChannelType.DEFAULT;
			if (flag)
			{
				List<ChatInfo> list = new List<ChatInfo>();
				for (int i = 0; i < this._auto_play_list.Count; i++)
				{
					bool flag2 = this._auto_play_list[i].mChannelId == type;
					if (flag2)
					{
						list.Add(this._auto_play_list[i]);
					}
					else
					{
						this.ChatShowInfo(this._auto_play_list[i]);
					}
				}
				this._auto_play_list = list;
			}
			this._channel_type = type;
		}

		private string GetString(string path)
		{
			bool flag = string.IsNullOrEmpty(path);
			string result;
			if (flag)
			{
				result = path;
			}
			else
			{
				result = path.Replace('\\', '/');
			}
			return result;
		}

		public string GetAudioCachePath()
		{
			bool flag = string.IsNullOrEmpty(this.cachePath);
			if (flag)
			{
				RuntimePlatform platform = Application.platform;
				if ((int)platform != 8)
				{
					if ((int)platform != 11)
					{
						this.cachePath = Application.persistentDataPath;
					}
					else
					{
						this.cachePath = Application.persistentDataPath;
					}
				}
				else
				{
					this.cachePath = Application.temporaryCachePath;
				}
			}
			return this.cachePath;
		}

		public void OnOpenWebView()
		{
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.OnOpenWebView();
			}
		}

		public void OnCloseWebView()
		{
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.OnCloseWebView();
			}
		}

		public void OnWebViewScreenLock(bool islock)
		{
			XSingleton<XDebug>.singleton.AddLog("Webview islock: ", islock.ToString(), null, null, null, null, XDebugColor.XDebug_None);
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.OnScreenLock(islock);
			}
		}

		public void OnEvalWebViewJs(string script)
		{
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.OnEvalJsScript(script);
			}
		}

		public void OnRefreshWebViewShow(bool show)
		{
			bool flag = this._ifly_mgr != null;
			if (flag)
			{
				this._ifly_mgr.RefershWebViewShow(show);
			}
		}

		public void RefreshWebViewConfig()
		{
			bool flag = XSingleton<XEntityMgr>.singleton.Player == null;
			if (!flag)
			{
				int num = int.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("HideWebView"));
				bool flag2 = num == 1;
				if (!flag2)
				{
					bool flag3 = this._ifly_mgr != null;
					if (flag3)
					{
						int platform = 0;
						XAuthorizationChannel channel = XSingleton<XLoginDocument>.singleton.Channel;
						if (channel != XAuthorizationChannel.XAuthorization_QQ)
						{
							if (channel == XAuthorizationChannel.XAuthorization_WeChat)
							{
								platform = 1;
							}
						}
						else
						{
							platform = 0;
						}
						this._ifly_mgr.OnInitWebViewInfo(platform, XSingleton<XLoginDocument>.singleton.OpenID, XSingleton<XClientNetwork>.singleton.ServerID.ToString(), XSingleton<XEntityMgr>.singleton.Player.PlayerAttributes.RoleID.ToString(), XSingleton<XAttributeMgr>.singleton.XPlayerData.Name);
					}
				}
			}
		}
	}
}