This commit is contained in:
2025-11-11 17:13:17 +09:00
parent c8a86e9081
commit dbd841c3a0
9 changed files with 71 additions and 682 deletions

View File

@@ -12,6 +12,7 @@ using UVC.Data.Core;
using UVC.Data.Http;
using UVC.Log;
using UVC.network;
using Simulator.Config;
namespace UVC.Data.Mqtt
{
@@ -256,21 +257,9 @@ namespace UVC.Data.Mqtt
private void OnWebGlRawTopicMessage(string topic, string message)
{
// WebGL: 스레드풀 없음 → 메인 스레드에서 부하 분산을 위해 한 프레임 양보
RunBackground(() => OnTopicMessageLogic(topic, message));
}
/// <summary>
/// 플랫폼별 백그라운드 실행 셔임
/// </summary>
private void RunBackground(Action action)
{
if (useWebSocket)
{
UniTask.Void(async () =>
{
await UniTask.NextFrame();
action();
});
OnTopicMessageLogic(topic, message);
}
}
@@ -330,7 +319,7 @@ namespace UVC.Data.Mqtt
string? dataMessage = defaultDataPicker.PickData(message);
if(dataMessage != null) message = dataMessage;
}
//Debug.Log($"t:{topic}/m:{message}");
bool isFirstMessage = false;
// 첫 번째 메시지 수신 여부를 확인하고, 아직 수신하지 않았다면 처리합니다.
if (!firstMessageReceived.ContainsKey(topic) || !firstMessageReceived[topic])

View File

@@ -4,6 +4,7 @@ using Best.HTTP.Shared.PlatformSupport.Memory;
using Cysharp.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Simulator.Config;
using System;
using System.Collections.Generic;
using System.IO;
@@ -234,7 +235,8 @@ namespace UVC.Network
request.DownloadSettings = new Best.HTTP.Request.Settings.DownloadSettings() { ContentStreamMaxBuffered = 1024 * 1024 * 200 };
request.MethodType = method;
request.SetHeader("Content-Type", "application/json; charset=utf-8");
//if (useAuth) request.SetHeader("access-token", AuthService.Instance.Entiti.accessToken);
if (useAuth) request.SetHeader("Authorization", "Bearer " + Constants.ACESS_TOKEN);
//request.SetHeader("access-token", Constants.ACESS_TOKEN);
JObject headerObject = new JObject();
headerObject.Add("Content-Type", "application/json; charset=utf-8");

View File

@@ -338,9 +338,30 @@ namespace UVC.network
/// <remarks>
/// 이 메서드는 메시지를 로깅하고 해당 토픽에 등록된 모든 핸들러를 호출합니다.
/// </remarks>
private void OnTopic(MQTTClient client, SubscriptionTopic topic, string topicName, ApplicationMessage message)
private void OnTopic(MQTTClient client, SubscriptionTopic topic, string topicName, ApplicationMessage message)
{
DispatchTopic(() => OnTopicLogic(client, topic, topicName, message));
string payload = Encoding.UTF8.GetString(message.Payload.Data, message.Payload.Offset, message.Payload.Count);
//Debug.Log($"{payload}");
//DispatchTopic(() => OnTopicLogic(client, topic, topicName, message));
if (useWebSocket)
{
// WebGL: 스레드풀 없음 → 다음 프레임에 메인 스레드로 실행
OnTopicLogic(client, topic, topicName, message);
}
else
{
if (onBackgroundThread)
{
UniTask.RunOnThreadPool(() => OnTopicLogic(client, topic, topicName, message)).Forget();
}
else
{
if (PlayerLoopHelper.IsMainThread)
OnTopicLogic(client, topic, topicName, message);
else
UniTask.Post(() => OnTopicLogic(client, topic, topicName, message));
}
}
}
// 웹GL 대응: 스레드풀 미지원 시 메인 스레드로 포스트
@@ -372,6 +393,7 @@ namespace UVC.network
{
//Debug.Log($"MQTT OnTopicLogic isMainThread={PlayerLoopHelper.IsMainThread}");
string payload = Encoding.UTF8.GetString(message.Payload.Data, message.Payload.Offset, message.Payload.Count);
//Debug.Log($"{payload}");
//ULog.Debug($"MQTT OnTopic {topic.Filter.OriginalFilter} => {payload}");
#if !UNITY_WEBGL || UNITY_EDITOR
ServerLog.LogMqtt(MQTTDomain, MQTTPort.ToString(), topic.Filter.OriginalFilter, payload, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"));