ui搭建完成
This commit is contained in:
@@ -16,13 +16,12 @@ namespace Unity.RenderStreaming
|
||||
/// 2. 在Inspector中关联各字段
|
||||
/// 3. participantVideoContainer 需要挂载 GridLayoutGroup 或 VerticalLayoutGroup
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(HostConnection))]
|
||||
public class MultiParticipantHostSample : MonoBehaviour
|
||||
public class MultiParticipantHost : MonoBehaviour
|
||||
{
|
||||
#pragma warning disable 0649
|
||||
|
||||
[Header("核心组件")]
|
||||
[SerializeField] private SignalingManager renderStreaming;
|
||||
[SerializeField] private HostConnection hostConnection;
|
||||
private SignalingManager renderStreaming;
|
||||
private HostConnection hostConnection;
|
||||
|
||||
[Header("Host本地视频")]
|
||||
[SerializeField] private VideoStreamSender videoStreamSender;
|
||||
@@ -40,10 +39,8 @@ namespace Unity.RenderStreaming
|
||||
[SerializeField] private InputField connectionIdInput;
|
||||
[SerializeField] private Dropdown webcamSelectDropdown;
|
||||
[SerializeField] private Dropdown microphoneSelectDropdown;
|
||||
|
||||
|
||||
#pragma warning restore 0649
|
||||
|
||||
private string connectionId;
|
||||
private RenderStreamingSettings settings;
|
||||
|
||||
/// <summary>
|
||||
@@ -60,6 +57,8 @@ namespace Unity.RenderStreaming
|
||||
|
||||
void Awake()
|
||||
{
|
||||
renderStreaming=GameObject.FindObjectOfType<SignalingManager>();
|
||||
hostConnection=GameObject.FindObjectOfType<HostConnection>();
|
||||
startButton.interactable = true;
|
||||
// 初始化UI
|
||||
setUpButton.interactable = true;
|
||||
@@ -76,7 +75,7 @@ namespace Unity.RenderStreaming
|
||||
});
|
||||
setUpButton.onClick.AddListener(SetUp);
|
||||
hangUpButton.onClick.AddListener(HangUp);
|
||||
connectionIdInput.onValueChanged.AddListener(input => connectionId = input);
|
||||
connectionIdInput.onValueChanged.AddListener(input => hostConnection.RoomConnectionId = input);
|
||||
connectionIdInput.text = $"{Random.Range(0, 99999):D5}";
|
||||
|
||||
// 本地视频:Sender启动后显示
|
||||
@@ -130,12 +129,12 @@ namespace Unity.RenderStreaming
|
||||
if (settings != null)
|
||||
videoStreamSender.SetCodec(settings.SenderVideoCodec);
|
||||
|
||||
hostConnection.CreateConnection(connectionId);
|
||||
hostConnection.CreateConnection(hostConnection.RoomConnectionId);
|
||||
}
|
||||
|
||||
private void HangUp()
|
||||
{
|
||||
hostConnection.DeleteConnection(connectionId);
|
||||
hostConnection.DeleteConnection(hostConnection.RoomConnectionId);
|
||||
|
||||
// 清理所有Participant UI
|
||||
foreach (var ui in participantUIs.Values)
|
||||
@@ -11,7 +11,7 @@ namespace Unity.RenderStreaming
|
||||
{
|
||||
public class MessageChannel : DataChannelBase
|
||||
{
|
||||
public event Action<string, UserInfo> OnMessageReceived;
|
||||
public event Action<string, UserInfo> OnUserInfoMessageReceived;
|
||||
public event Action<string, MediaStateChange> OnMediaStateChangeReceived;
|
||||
|
||||
[Header("消息记录")] [SerializeField, TextArea(1, 3)]
|
||||
@@ -41,7 +41,8 @@ namespace Unity.RenderStreaming
|
||||
{
|
||||
record = new MessageRecord { type = "raw", data = message };
|
||||
}
|
||||
|
||||
record.timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
ConnectionId=record.connectionId;
|
||||
JObject json = null;
|
||||
switch (record.type)
|
||||
{
|
||||
@@ -51,7 +52,7 @@ namespace Unity.RenderStreaming
|
||||
case MessageTypes.UserInfo:
|
||||
json = record.data as JObject;
|
||||
var info = json.ToObject<UserInfo>();
|
||||
OnMessageReceived?.Invoke(ConnectionId, info);
|
||||
OnUserInfoMessageReceived?.Invoke(ConnectionId, info);
|
||||
break;
|
||||
case MessageTypes.MediaStateChange:
|
||||
json = record.data as JObject;
|
||||
@@ -112,6 +113,8 @@ namespace Unity.RenderStreaming
|
||||
public object data;
|
||||
public bool isSent;
|
||||
public string timestamp = DateTime.Now.ToString();
|
||||
public string connectionId;
|
||||
public string participantId;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user