145 lines
5.5 KiB
C#
145 lines
5.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Newtonsoft.Json;
|
|
using RenderStreaming;
|
|
using Stary.Evo;
|
|
using Unity.RenderStreaming;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Script
|
|
{
|
|
public class MeetingContacts : IController
|
|
{
|
|
/// <summary>
|
|
/// 联系人列表项字典
|
|
/// Key: 参与者ID
|
|
/// Value: 联系人列表项实例
|
|
/// </summary>
|
|
private readonly List<ContactEntryController> _contactEntries = new();
|
|
|
|
private Image _avatarImage;
|
|
private Button _cancelButton;
|
|
private Button _confirmButton;
|
|
|
|
private GameObject _confirmingPop;
|
|
|
|
/// <summary>
|
|
/// 联系人列表项预制体
|
|
/// </summary>
|
|
private GameObject _contactEntryPrefab;
|
|
|
|
/// <summary>
|
|
/// 全部联系人列表容器
|
|
/// </summary>
|
|
private Transform _content;
|
|
|
|
private Text _idText;
|
|
private InputField _leaveMessage;
|
|
private Text _messageText;
|
|
private Text _nameText;
|
|
|
|
public GameObject PanelGo;
|
|
|
|
public ContactEntryController CurrentEntry { get; set; }
|
|
|
|
private GameObjectPool _objectPool;
|
|
|
|
public IArchitecture GetArchitecture()
|
|
{
|
|
return MainArchitecture.Interface;
|
|
}
|
|
|
|
public void Initialize(GameObject panelGo)
|
|
{
|
|
PanelGo = panelGo;
|
|
_contactEntryPrefab = Resources.Load<GameObject>("ContactEntry");
|
|
_content = PanelGo.transform.Find("MeetingGrid/Viewport/Content");
|
|
|
|
//邀请界面
|
|
_confirmingPop = PanelGo.transform.Find("MeetingGrid/ConfirmingPop").gameObject;
|
|
_confirmingPop.SetActive(false);
|
|
//确认邀请
|
|
_idText = _confirmingPop.transform.Find("bg/id").GetComponent<Text>();
|
|
_leaveMessage = _confirmingPop.transform.Find("bg/leaveMessage").GetComponent<InputField>();
|
|
_confirmButton = _confirmingPop.transform.Find("bg/invite").GetComponent<Button>();
|
|
_cancelButton = _confirmingPop.transform.Find("bg/cancel").GetComponent<Button>();
|
|
|
|
_avatarImage = _confirmingPop.transform.Find("ParticipantEntry/head/image").GetComponent<Image>();
|
|
_nameText = _confirmingPop.transform.Find("ParticipantEntry/Name").GetComponent<Text>();
|
|
_messageText = _confirmingPop.transform.Find("ParticipantEntry/Message").GetComponent<Text>();
|
|
|
|
_objectPool = PanelGo.transform.Find("MeetingGrid/Pool").GetComponent<GameObjectPool>();
|
|
}
|
|
|
|
public async void OnEnter()
|
|
{
|
|
foreach (var entry in _contactEntries)
|
|
_objectPool.Release(entry.gameObject);
|
|
_contactEntries.Clear();
|
|
var response =
|
|
await WebRequestSystem.Get<MainPanel.ResponseUsers>(this.GetSystem<IGlobalConfigSystem>().IP,
|
|
"/signaling/users");
|
|
if (response != null && response.totalCount > 0)
|
|
for (var i = 0; i < response.totalCount; i++)
|
|
{
|
|
var item = response.users[i];
|
|
if (string.IsNullOrEmpty(item.name) ||
|
|
string.IsNullOrEmpty(item.userId)) continue;
|
|
var entry = _objectPool.Get();
|
|
var contactEntryController = entry.GetOrAddComponent<ContactEntryController>();
|
|
contactEntryController.SetData(item, this);
|
|
_contactEntries.Add(contactEntryController);
|
|
}
|
|
}
|
|
|
|
|
|
public void OnDestroy()
|
|
{
|
|
_objectPool.AllRelease();
|
|
}
|
|
|
|
public void ClickContactEntry(Sprite avatarImage, string name, MainPanel.UsersItem item)
|
|
{
|
|
_confirmingPop.SetActive(true);
|
|
|
|
|
|
_idText.text = this.GetSystem<IGlobalConfigSystem>().GetConnectionId();
|
|
|
|
_avatarImage.sprite = avatarImage;
|
|
var avatarName = _confirmingPop.transform.Find("ParticipantEntry/head/Name").GetComponent<Text>();
|
|
avatarName.text = name;
|
|
_nameText.text = item.name;
|
|
_messageText.text = item.userId;
|
|
|
|
_confirmButton.onClick.AddListener(() =>
|
|
{
|
|
_confirmingPop.SetActive(false);
|
|
CurrentEntry.StartCountdown();
|
|
// var avatar = _profileImage.sprite.name.Replace("(Clone)", "");
|
|
var userInfo = new
|
|
{
|
|
type = "invite-call",
|
|
data = new
|
|
{
|
|
connectionId = this.GetSystem<IGlobalConfigSystem>().GetConnectionId(),
|
|
targetSocketId = item.socketId,
|
|
targetUserId = item.userId,
|
|
inviterUserId = this.GetSystem<IGlobalConfigSystem>().GetUserId(),
|
|
inviterName = this.GetSystem<IGlobalConfigSystem>().GetConnectionName(),
|
|
inviterAvatar =
|
|
$"{this.GetSystem<IGlobalConfigSystem>().IP}/images/head/" +
|
|
$"{this.GetSystem<IGlobalConfigSystem>().GetConnectionTexture()}.png",
|
|
applyReason = _leaveMessage.text
|
|
}
|
|
};
|
|
SignalingMessageHelper.SendMessage(JsonConvert.SerializeObject(userInfo));
|
|
});
|
|
_cancelButton.onClick.AddListener(() =>
|
|
{
|
|
_confirmingPop.SetActive(false);
|
|
CurrentEntry = null;
|
|
});
|
|
}
|
|
}
|
|
} |