188 lines
6.3 KiB
C#
188 lines
6.3 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 Dictionary<GameObject, 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;
|
|
|
|
private GameObject _panelGo;
|
|
|
|
public ContactEntryController CurrentEntry { get; set; }
|
|
|
|
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").GetComponent<Image>();
|
|
_nameText = _confirmingPop.transform.Find("ParticipantEntry/Name").GetComponent<Text>();
|
|
_messageText = _confirmingPop.transform.Find("ParticipantEntry/Message").GetComponent<Text>();
|
|
}
|
|
|
|
public async void OnEnter()
|
|
{
|
|
var response =
|
|
await WebRequestSystem.Get<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 = GameObject.Instantiate(_contactEntryPrefab, _content);
|
|
var contactEntryController = entry.GetOrAddComponent<ContactEntryController>();
|
|
contactEntryController.SetData(item, this);
|
|
}
|
|
}
|
|
|
|
|
|
public void OnExit()
|
|
{
|
|
}
|
|
|
|
public void ClickContactEntry(Sprite avatarImage, string name, UsersItem item)
|
|
{
|
|
_confirmingPop.SetActive(true);
|
|
|
|
|
|
_idText.text = this.GetSystem<IGlobalConfigSystem>().GetConnectionId();
|
|
|
|
_avatarImage.sprite = avatarImage;
|
|
var avatarName = _avatarImage.transform.Find("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().name}.png"
|
|
}
|
|
};
|
|
SignalingMessageHelper.SendMessage(JsonConvert.SerializeObject(userInfo));
|
|
});
|
|
_cancelButton.onClick.AddListener(() =>
|
|
{
|
|
_confirmingPop.SetActive(false);
|
|
CurrentEntry = null;
|
|
});
|
|
}
|
|
|
|
public class ContactEntryData
|
|
{
|
|
public string avatar;
|
|
public GameObject entry;
|
|
public Toggle invitationTog;
|
|
public string name;
|
|
public string participantId;
|
|
public string role;
|
|
}
|
|
|
|
[Serializable]
|
|
public class ResponseUsers
|
|
{
|
|
/// <summary>
|
|
/// </summary>
|
|
public List<UsersItem> users { get; set; }
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
public int totalCount { get; set; }
|
|
}
|
|
|
|
[Serializable]
|
|
public class UsersItem
|
|
{
|
|
/// <summary>
|
|
/// </summary>
|
|
public string socketId { get; set; }
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
public string connectionId { get; set; }
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
public string participantId { get; set; }
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
public string role { get; set; }
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
public string userId { get; set; }
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
public string name { get; set; }
|
|
|
|
/// <summary>
|
|
/// </summary>
|
|
public string avatar { get; set; }
|
|
}
|
|
}
|
|
} |