增加自定义不是房间的消息发送
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEngine;
|
||||
@@ -11,17 +10,14 @@ namespace Unity.RenderStreaming
|
||||
{
|
||||
public class MessageChannel : DataChannelBase
|
||||
{
|
||||
public event Action<string, UserInfo> OnUserInfoMessageReceived;
|
||||
public event Action<string, MediaStateChange> OnMediaStateChangeReceived;
|
||||
private const int MAX_HISTORY = 100;
|
||||
|
||||
[Header("消息记录")] [SerializeField, TextArea(1, 3)]
|
||||
[Header("消息记录")] [SerializeField] [TextArea(1, 3)]
|
||||
private string lastReceivedMessage;
|
||||
|
||||
[SerializeField] private int receivedMessageCount;
|
||||
|
||||
[SerializeField] private List<MessageRecord> messageHistory = new List<MessageRecord>();
|
||||
|
||||
private const int MAX_HISTORY = 100;
|
||||
[SerializeField] private List<MessageRecord> messageHistory = new();
|
||||
|
||||
public IReadOnlyList<MessageRecord> MessageHistory => messageHistory;
|
||||
public int ReceivedMessageCount => receivedMessageCount;
|
||||
@@ -31,18 +27,18 @@ namespace Unity.RenderStreaming
|
||||
label = "on-message";
|
||||
}
|
||||
|
||||
public event Action<string, UserInfo> OnUserInfoMessageReceived;
|
||||
public event Action<string, MediaStateChange> OnMediaStateChangeReceived;
|
||||
|
||||
public override void OnMessage(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.Log($"[MessageChannel] Received: {message}");
|
||||
var record = JsonConvert.DeserializeObject<MessageRecord>(message);
|
||||
if (record == null)
|
||||
{
|
||||
record = new MessageRecord { type = "raw", data = message };
|
||||
}
|
||||
if (record == null) record = new MessageRecord { type = "raw", data = message };
|
||||
record.timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
ConnectionId=record.connectionId;
|
||||
ConnectionId = record.connectionId;
|
||||
JObject json = null;
|
||||
switch (record.type)
|
||||
{
|
||||
@@ -79,9 +75,9 @@ namespace Unity.RenderStreaming
|
||||
var record = new MessageRecord
|
||||
{
|
||||
type = type,
|
||||
data = JsonConvert.SerializeObject(data)
|
||||
data = data
|
||||
};
|
||||
string json = JsonConvert.SerializeObject(record);
|
||||
var json = JsonConvert.SerializeObject(record);
|
||||
Send(json);
|
||||
|
||||
record.isSent = true;
|
||||
@@ -90,14 +86,6 @@ namespace Unity.RenderStreaming
|
||||
messageHistory.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void SendMessage(string message)
|
||||
{
|
||||
Send(message);
|
||||
var record = new MessageRecord { type = "raw", data = message, isSent = true };
|
||||
messageHistory.Add(record);
|
||||
if (messageHistory.Count > MAX_HISTORY)
|
||||
messageHistory.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void ClearHistory()
|
||||
{
|
||||
@@ -110,11 +98,11 @@ namespace Unity.RenderStreaming
|
||||
public class MessageRecord
|
||||
{
|
||||
public string type;
|
||||
public object data;
|
||||
public bool isSent;
|
||||
public string timestamp = DateTime.Now.ToString();
|
||||
public string connectionId;
|
||||
public string participantId;
|
||||
public object data;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user