开始开发
This commit is contained in:
26
Assets/Script/WebRtc/MessageChannel.cs
Normal file
26
Assets/Script/WebRtc/MessageChannel.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
// 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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Script/WebRtc/MessageChannel.cs.meta
Normal file
11
Assets/Script/WebRtc/MessageChannel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6d9a920c56cc474db27ac4ed56a219a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user