26 lines
722 B
C#
26 lines
722 B
C#
// Assets/Script/MessageChannel.cs
|
|
using System;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
|
|
namespace Unity.RenderStreaming
|
|
{
|
|
public class MessageChannel : DataChannelBase
|
|
{
|
|
public event Action<string, string> OnMessageReceived; // connectionId, message
|
|
|
|
protected override void OnMessage(byte[] bytes)
|
|
{
|
|
try
|
|
{
|
|
string json = Encoding.UTF8.GetString(bytes);
|
|
Debug.Log($"[MessageChannel] Received: {json}");
|
|
OnMessageReceived?.Invoke(ConnectionId, json);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError($"[MessageChannel] Parse error: {e.Message}");
|
|
}
|
|
}
|
|
}
|
|
} |